Linting cleanup

master
Tom Wilson 5 years ago
parent 62b8794936
commit 517483a5cb

@ -26,7 +26,8 @@ setup(
'pytest-cov', 'pytest-cov',
'pytest-sugar', 'pytest-sugar',
'tox', 'tox',
'responses' 'responses',
'debugpy'
], ],
'test': [ 'test': [
'pytest', 'pytest',

@ -1,16 +1,18 @@
import logging import logging
import os # import os
import sys import sys
from pathlib import Path from pathlib import Path
import glob import glob
from types import SimpleNamespace from types import SimpleNamespace
from datetime import datetime from datetime import datetime
from pprint import pprint import inspect
# from pprint import pprint
import pkg_resources import pkg_resources
import chromalog
# import chromalog
import click import click
import toml import toml
@ -165,7 +167,7 @@ def test(ctx, plugin_name, interface_function):
if not interface_function: if not interface_function:
echo_section(F"Interface functions [{plugin_name}]:", on_nl=False) echo_section(F"Interface functions [{plugin_name}]:", on_nl=False)
for name, func in interface._functions.items(): for name in interface._functions:
click.echo(F" {name}") click.echo(F" {name}")
return return

@ -49,7 +49,8 @@ class CoreUpdateState():
def __init__(self, cmd_reader, cmd_result_writer): def __init__(self, cmd_reader, cmd_result_writer):
""" """
Control update handler for the `/update` core endpoint. Needs a reference to the CommandRunner Control update handler for the `/update` core endpoint. Needs a reference to the
CommandRunner
""" """
self.topic_bundle = statesman.TopicBundle({ self.topic_bundle = statesman.TopicBundle({
'status': statesman.StateWriter(), 'status': statesman.StateWriter(),

@ -120,7 +120,7 @@ def plugin_class(cls):
interface.register_plugin_class(MyPluginClass) interface.register_plugin_class(MyPluginClass)
""" """
if not inspect.isclass(cls): if not inspect.isclass(cls):
raise PluginLoadError(F"@plugin_class can only be used to decorate a class") raise PluginLoadError("@plugin_class can only be used to decorate a class")
cls._shepherd_load_marker = ClassMarker() cls._shepherd_load_marker = ClassMarker()
return cls return cls
@ -482,7 +482,7 @@ class PluginInterface():
""" """
self._load_guard() self._load_guard()
if not isinstance(name, str): if not isinstance(name, str):
raise PluginLoadError(F"Hook name must be a string") raise PluginLoadError("Hook name must be a string")
if name in self._hooks: if name in self._hooks:
raise PluginLoadError(F"Hook with name '{name}' already exists") raise PluginLoadError(F"Hook with name '{name}' already exists")

@ -18,7 +18,7 @@ from apscheduler.triggers.cron import CronTrigger as APCronTrigger
from configspec import * from configspec import *
import preserve import preserve
from .util import HoldLock # from .util import HoldLock
log = logging.getLogger("shepherd.agent.tasks") log = logging.getLogger("shepherd.agent.tasks")
@ -98,8 +98,8 @@ class CronTrigger(TaskTrigger):
return fire_time.astimezone(pytz.utc).astimezone(tz.tzutc()) return fire_time.astimezone(pytz.utc).astimezone(tz.tzutc())
TriggerSpec = ConfigSpecification() CronTriggerSpec = ConfigSpecification()
TriggerSpec.add_specs({ CronTriggerSpec.add_specs({
'month': StringSpec(helptext="Month in year, 1-12"), 'month': StringSpec(helptext="Month in year, 1-12"),
'day': StringSpec(helptext="Day of month, 1-32"), 'day': StringSpec(helptext="Day of month, 1-32"),
'day_of_week': StringSpec(helptext="Day of week, 0-6 or mon,tue,wed,thu,fri,sat,sun"), 'day_of_week': StringSpec(helptext="Day of week, 0-6 or mon,tue,wed,thu,fri,sat,sun"),
@ -326,27 +326,7 @@ def _tasks_update_loop(config, suspend_hook, session):
_update_thread_init_done.clear() _update_thread_init_done.clear()
# Right, so we have our task list, and calls have been resolved. Assume that any waiting period # TODO Handle case when tasks return None as next trigger time, and when no triggers are left
# for control has already been handled. # TODO Add maximum suspend period
# TODO Add "snooze" task checking even on new session, to catch tasks we miss if we restart
# Eventually also need a system to wait for time to stabilise (hook?) # due to new config
# What do we do when task list is empty? Return directly?
# That list then gets sorted by that time, and the main loop simply waits for the next scheduled
# time to pass before calling the task (on a different thread). The scheduled_for time gets updated,
# the scheduled_tasks list gets sorted again. The loop then looks at the next task, probably with
# some log if "scheduled_for" is too far in the past, but run the task anyway.
# Lowpower handling can then be in the section of the cycle where we'd otherwise be doing a delay.
# Have a minimum sleep delay (10ms or something), so we can have a task only run if it's past
# the scheduled_for, and then we can happily use that time to get the _next_ trigger time.
# Start our scheduler thread to fire off tasks, including the initial grace period checks
# Due to our task constraints, our scheduler can be somewhat simplified. We know that task
# triggers won't change after init, and they will be infrequent enough that we can just
# make a new thread for each task.
# Maybe have "cycles", where we determine what task is going to occur next, and when.
# A main dispatch loop then pretty much delays until that point, or triggers the low power
# stuff somehow.

Loading…
Cancel
Save