fixed CLI options,

implemented better config attr search member,
fixed imports
This commit is contained in:
Arthur Lu 2022-03-29 04:28:09 +00:00
parent 0212e6b2ca
commit 5553e3dddf
2 changed files with 20 additions and 34 deletions

View File

@ -185,32 +185,23 @@ class Configuration:
if not isValidated: if not isValidated:
raise ConfigurationError("config validation error: " + v.errors) raise ConfigurationError("config validation error: " + v.errors)
def __getattr__(self, name): # simple linear lookup method for common multikey-value paths, TYPE UNSAFE def __getattr__(self, name): # better hashed lookup method for common multikey-value paths, TYPE UNSAFE
if name == "persistent": attr_lookup = {
return self.config["persistent"] "persistent": self.config["persistent"],
elif name == "key": "key": self.config["persistent"]["key"],
return self.config["persistent"]["key"] "database": self.config["persistent"]["key"]["database"],
elif name == "database": "tba": self.config["persistent"]["key"]["tba"],
# soon to be deprecated "tra": self.config["persistent"]["key"]["tra"],
return self.config["persistent"]["key"]["database"] "priority": self.config["persistent"]["config-preference"],
elif name == "tba": "sync": self.config["persistent"]["synchronize-config"],
return self.config["persistent"]["key"]["tba"] "variable": self.config["variable"],
elif name == "tra": "event_delay": self.config["variable"]["event-delay"],
return self.config["persistent"]["key"]["tra"] "loop_delay": self.config["variable"]["loop-delay"],
elif name == "priority": "competition": self.config["variable"]["competition"],
return self.config["persistent"]["config-preference"] "modules": self.config["variable"]["modules"]
elif name == "sync": }
return self.config["persistent"]["synchronize-config"] if name in attr_lookup.keys():
elif name == "variable": return attr_lookup[name]
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"]
else: else:
return None return None

View File

@ -149,18 +149,14 @@ __author__ = (
# imports: # imports:
from distutils.command.config import config
import os, sys, time import os, sys, time
import pymongo # soon to be deprecated import pymongo # soon to be deprecated
import traceback import traceback
import warnings import warnings
from config import Configuration, ConfigurationError 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 interface import Logger
from module import Match, Metric, Pit from module import Match, Metric, Pit
import zmq
#def main(logger, verbose, profile, debug, socket_send = None): #def main(logger, verbose, profile, debug, socket_send = None):
def main(logger, verbose, profile, debug, config_path): 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.resolve_config_conflicts(logger, client)
config_modules, competition = config.modules, config.competition config_modules, competition = config.modules, config.competition
clear_metrics(client, config.competition)
for m in config_modules: for m in config_modules:
if m in modules: if m in modules:
start = time.time() start = time.time()
@ -338,9 +333,9 @@ if __name__ == "__main__":
if 'verbose' == sys.argv[1]: if 'verbose' == sys.argv[1]:
start(None, True, False, False, config_path = config_path) start(None, True, False, False, config_path = config_path)
elif 'profile' == sys.argv[1]: 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]: elif 'debug' == sys.argv[1]:
start(None, True, False, False, config_path = config_path) start(None, False, False, True, config_path = config_path)
else: else:
print("usage: %s verbose|profile|debug" % sys.argv[0]) print("usage: %s verbose|profile|debug" % sys.argv[0])
sys.exit(2) sys.exit(2)