Skip to content

Commit

Permalink
Add type hints to new code
Browse files Browse the repository at this point in the history
  • Loading branch information
xylix committed Mar 3, 2020
1 parent 9dfea4b commit 94dc1df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
5 changes: 3 additions & 2 deletions aw_qt/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from configparser import ConfigParser
from typing import ClassVar, List

from aw_core.config import load_config
import json
Expand All @@ -25,5 +26,5 @@ class AwQtSettings:
def __init__(self, testing: bool):
config_section = qt_config["aw-qt" if not testing else "aw-qt-testing"]

self.possible_modules = json.loads(config_section["possible_modules"])
self.autostart_modules = json.loads(config_section["autostart_modules"])
self.possible_modules: List[str] = json.loads(config_section["possible_modules"])
self.autostart_modules: List[str] = json.loads(config_section["autostart_modules"])
21 changes: 12 additions & 9 deletions aw_qt/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from time import sleep
import logging
import subprocess
from typing import Optional, List
from typing import Optional, List, Dict, Set

import aw_core

Expand Down Expand Up @@ -129,27 +129,30 @@ def read_log(self) -> str:

class Manager:
def __init__(self, testing: bool = False) -> None:
self.settings = AwQtSettings(testing)
self.modules = {}
self.settings: AwQtSettings = AwQtSettings(testing)
self.modules: Dict[str, Module] = {}
self.autostart_modules: Set[str] = set(self.settings.autostart_modules)

for name in self.settings.possible_modules:
if _locate_executable(name):
self.modules[name] = Module(name, testing=testing)
else:
logger.warning("Module '{}' not found".format(name))
logger.warning("Module '{}' not found but was in possible modules".format(name))

def get_unexpected_stops(self):
return list(filter(lambda x: x.started and not x.is_alive(), self.modules))
return list(filter(lambda x: x.started and not x.is_alive(), self.modules.values()))

def start(self, module_name):
if module_name in self.modules:
if module_name in self.modules.keys():
self.modules[module_name].start()

def autostart(self, autostart_modules):

if autostart_modules is None:
# Modules to start are not specified. Fallback on configuration.
logger.info("Modules to start weren't specified in CLI arguments. Falling back to configuration.")
autostart_modules = self.settings.autostart_modules

# We only want to autostart modules that are both in found modules and are asked to autostart.
autostart_modules = autostart_modules.intersection(set(self.modules.keys()))
# Always start aw-server first
if "aw-server" in autostart_modules:
self.start("aw-server")
Expand All @@ -161,7 +164,7 @@ def autostart(self, autostart_modules):
self.start(module_name)

def stop_all(self):
for module in filter(lambda m: m.is_alive(), self.modules):
for module in filter(lambda m: m.is_alive(), self.modules.values()):
module.stop()


Expand Down

0 comments on commit 94dc1df

Please sign in to comment.