Skip to content

Commit

Permalink
rename QTSettings to AwQtSettings and add aw-server-rust
Browse files Browse the repository at this point in the history
  • Loading branch information
xylix committed Mar 3, 2020
1 parent a974e2c commit 9dfea4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
19 changes: 6 additions & 13 deletions aw_qt/config.py
Expand Up @@ -5,32 +5,25 @@

default_settings = {
"possible_modules": json.dumps(["aw-server",
"aw-server-rust",
"aw-watcher-afk",
"aw-watcher-window", ]),
"autostart_modules": json.dumps(["aw-server",
"aw-watcher-afk",
"aw-watcher-window", ]),
}
default_testing_settings = {
"possible_modules": json.dumps(["aw-server",
"aw-watcher-afk",
"aw-watcher-window", ]),
"autostart_modules": json.dumps(["aw-server",
"autostart_modules": json.dumps(["aw-server-rust",
"aw-server",
"aw-watcher-afk",
"aw-watcher-window", ]),
}

default_config = ConfigParser()
default_config['aw-qt'] = default_settings
default_config['aw-qt-testing'] = default_testing_settings
# Currently there's no reason to make them differ
default_config['aw-qt-testing'] = default_settings
qt_config = load_config("aw-qt", default_config)


class QTSettings:
class AwQtSettings:
def __init__(self, testing: bool):
config_section = qt_config["aw-qt" if not testing else "aw-qt-testing"]

# TODO: Resolved available modules automatically.
# TODO: Filter away all modules not available on system
self.possible_modules = json.loads(config_section["possible_modules"])
self.autostart_modules = json.loads(config_section["autostart_modules"])
14 changes: 6 additions & 8 deletions aw_qt/manager.py
Expand Up @@ -7,7 +7,7 @@

import aw_core

from .config import QTSettings
from .config import AwQtSettings

logger = logging.getLogger(__name__)

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

class Manager:
def __init__(self, testing: bool = False) -> None:
self.settings = QTSettings(testing)
self.settings = AwQtSettings(testing)
self.modules = {}
for name in self.settings.possible_modules:
if _locate_executable(name):
self.modules[name] = Module(name, testing=testing)
else:
print("Module '{}' not found".format(name))
logger.warning("Module '{}' not found".format(name))

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

def start(self, module_name):
if module_name in self.modules.keys():
if module_name in self.modules:
self.modules[module_name].start()
else:
logger.error("Unable to start module '{}': No such module".format(module_name))

def autostart(self, autostart_modules):

Expand All @@ -163,7 +161,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.values()):
for module in filter(lambda m: m.is_alive(), self.modules):
module.stop()


Expand Down

0 comments on commit 9dfea4b

Please sign in to comment.