From 5553e3dddfb01cd679b55d836f1b98141414e692 Mon Sep 17 00:00:00 2001 From: Arthur Lu Date: Tue, 29 Mar 2022 04:28:09 +0000 Subject: [PATCH] fixed CLI options, implemented better config attr search member, fixed imports --- src/config.py | 43 +++++++++++++++++-------------------------- src/superscript.py | 11 +++-------- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/config.py b/src/config.py index 006039c..754b6dd 100644 --- a/src/config.py +++ b/src/config.py @@ -185,32 +185,23 @@ class Configuration: if not isValidated: raise ConfigurationError("config validation error: " + v.errors) - def __getattr__(self, name): # simple linear lookup method for common multikey-value paths, TYPE UNSAFE - if name == "persistent": - return self.config["persistent"] - elif name == "key": - return self.config["persistent"]["key"] - elif name == "database": - # soon to be deprecated - return self.config["persistent"]["key"]["database"] - elif name == "tba": - return self.config["persistent"]["key"]["tba"] - elif name == "tra": - return self.config["persistent"]["key"]["tra"] - elif name == "priority": - return self.config["persistent"]["config-preference"] - elif name == "sync": - return self.config["persistent"]["synchronize-config"] - elif name == "variable": - return self.config["variable"] - elif name == "event_delay": - return self.config["variable"]["event-delay"] - elif name == "loop_delay": - return self.config["variable"]["loop-delay"] - elif name == "competition": - return self.config["variable"]["competition"] - elif name == "modules": - return self.config["variable"]["modules"] + def __getattr__(self, name): # better hashed lookup method for common multikey-value paths, TYPE UNSAFE + attr_lookup = { + "persistent": self.config["persistent"], + "key": self.config["persistent"]["key"], + "database": self.config["persistent"]["key"]["database"], + "tba": self.config["persistent"]["key"]["tba"], + "tra": self.config["persistent"]["key"]["tra"], + "priority": self.config["persistent"]["config-preference"], + "sync": self.config["persistent"]["synchronize-config"], + "variable": self.config["variable"], + "event_delay": self.config["variable"]["event-delay"], + "loop_delay": self.config["variable"]["loop-delay"], + "competition": self.config["variable"]["competition"], + "modules": self.config["variable"]["modules"] + } + if name in attr_lookup.keys(): + return attr_lookup[name] else: return None diff --git a/src/superscript.py b/src/superscript.py index ee16e65..a304835 100644 --- a/src/superscript.py +++ b/src/superscript.py @@ -149,18 +149,14 @@ __author__ = ( # imports: -from distutils.command.config import config import os, sys, time import pymongo # soon to be deprecated import traceback import warnings from config import Configuration, ConfigurationError -from data import get_previous_time, set_current_time, check_new_database_matches, clear_metrics +from data import get_previous_time, set_current_time, check_new_database_matches from interface import Logger from module import Match, Metric, Pit -import zmq - - #def main(logger, verbose, profile, debug, socket_send = None): def main(logger, verbose, profile, debug, config_path): @@ -207,7 +203,6 @@ def main(logger, verbose, profile, debug, config_path): config.resolve_config_conflicts(logger, client) config_modules, competition = config.modules, config.competition - clear_metrics(client, config.competition) for m in config_modules: if m in modules: start = time.time() @@ -338,9 +333,9 @@ if __name__ == "__main__": if 'verbose' == sys.argv[1]: start(None, True, False, False, config_path = config_path) elif 'profile' == sys.argv[1]: - start(None, True, False, False, config_path = config_path) + start(None, False, True, False, config_path = config_path) elif 'debug' == sys.argv[1]: - start(None, True, False, False, config_path = config_path) + start(None, False, False, True, config_path = config_path) else: print("usage: %s verbose|profile|debug" % sys.argv[0]) sys.exit(2)