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:
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

View File

@ -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)