Skip to content

Commit

Permalink
Improve autostart() input typing
Browse files Browse the repository at this point in the history
  • Loading branch information
xylix committed Mar 4, 2020
1 parent a7c098c commit 8808f7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions aw_qt/main.py
@@ -1,7 +1,7 @@
import sys
import logging
import argparse
from typing import Set
from typing import List
from typing_extensions import TypedDict

from aw_core.log import setup_logging
Expand All @@ -25,7 +25,7 @@ def main() -> None:
sys.exit(error_code)


CommandLineArgs = TypedDict('CommandLineArgs', {'testing': bool, 'autostart_modules': Set[str]}, total=False)
CommandLineArgs = TypedDict('CommandLineArgs', {'testing': bool, 'autostart_modules': List[str]}, total=False)


def parse_args() -> CommandLineArgs:
Expand Down
22 changes: 11 additions & 11 deletions aw_qt/manager.py
Expand Up @@ -209,23 +209,23 @@ def start(self, module_name: str) -> None:
else:
logger.debug("Manager tried to start nonexistent module {}".format(module_name))

def autostart(self, autostart_modules: Optional[Set[str]]) -> None:
def autostart(self, autostart_modules: Optional[List[str]]) -> None:
if autostart_modules is None:
autostart_modules = set()
autostart_modules = []
if len(autostart_modules) > 0:
logger.info("Modules to start weren't specified in CLI arguments. Falling back to configuration.")
autostart_modules = set(self.settings.autostart_modules)

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")
elif "aw-server-rust" in autostart_modules:
modules_to_start = set(autostart_modules).intersection(set(self.modules.keys()))

# Start aw-server-rust first
if "aw-server-rust" in modules_to_start:
self.start("aw-server-rust")
elif "aw-server" in modules_to_start:
self.start("aw-server")

autostart_modules = set(autostart_modules) - {"aw-server", "aw-server-rust"}
for module_name in autostart_modules:
modules_to_start = set(autostart_modules) - {"aw-server", "aw-server-rust"}
for module_name in modules_to_start:
self.start(module_name)

def stop_all(self) -> None:
Expand Down

0 comments on commit 8808f7c

Please sign in to comment.