提交 66aa8c45 编写于 作者: S shenyuhan

modify hub config

上级 0886e702
......@@ -67,25 +67,14 @@ class ConfigCommand(BaseCommand):
print("Set success! The current configuration is shown below.")
print(json.dumps(config, indent=4))
@staticmethod
def show_server_url():
with open(os.path.join(CONF_HOME, "config.json"), "r") as fp:
config = json.load(fp)
print(config["server_url"])
@staticmethod
def show_log_level():
with open(os.path.join(CONF_HOME, "config.json"), "r") as fp:
print(json.load(fp)["log_level"])
@staticmethod
def set_log_level(level):
level = str(level).upper()
if level not in [
"CRITICAL", "FATAL", "ERROR", "WARN", "WARNING", "INFO",
"DEBUG", "NOTSET"
"NOLOG", "DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"
]:
print("Allowed values include: "
"CRITICAL, FATAL, ERROR, WARN, WARNING, INFO, DEBUG, NOTSET")
"NOLOG, DEBUG, INFO, WARNING, ERROR, CRITICAL")
return
with open(os.path.join(CONF_HOME, "config.json"), "r") as fp:
current_config = json.load(fp)
......@@ -97,19 +86,15 @@ class ConfigCommand(BaseCommand):
@staticmethod
def show_help():
str = "config <option> <value>\n"
str = "config <option>\n"
str += "\tShow hub server config without any option.\n"
str += "option:\n"
str += "reset\n"
str += "\tReset config as default.\n"
str += "server\n"
str += "\tShow server url.\n"
str += "server [URL]\n"
str += "server==[URL]\n"
str += "\tSet hub server url as [URL].\n"
str += "log\n"
str += "\tShow log level.\n"
str += "log [LEVEL]\n"
str += "\tSet log level as [LEVEL:CRITICAL, FATAL, ERROR, WARN, WARNING, INFO, DEBUG, NOTSET].\n"
str += "log==[LEVEL]\n"
str += "\tSet log level as [LEVEL:NOLOG, DEBUG, INFO, WARNING, ERROR, CRITICAL].\n"
print(str)
def execute(self, argv):
......@@ -118,16 +103,10 @@ class ConfigCommand(BaseCommand):
ConfigCommand.show_config()
elif args.option == "reset":
ConfigCommand.set_config(default_server_config)
elif args.option == "server":
if args.value is not None:
ConfigCommand.set_server_url(args.value)
else:
ConfigCommand.show_server_url()
elif args.option == "log":
if args.value is not None:
ConfigCommand.set_log_level(args.value)
else:
ConfigCommand.show_log_level()
elif args.option.startswith("server=="):
ConfigCommand.set_server_url(args.option.split("==")[1])
elif args.option.startswith("log=="):
ConfigCommand.set_log_level(args.option.split("==")[1])
else:
ConfigCommand.show_help()
return True
......
......@@ -39,12 +39,13 @@ class Logger(object):
self.handler.setFormatter(self.format)
self.logger.addHandler(self.handler)
if not os.path.exists(os.path.join(CONF_HOME, "config.json")):
self.logLevel = "DEBUG"
else:
with open(os.path.join(CONF_HOME, "config.json"), "r") as fp:
self.logLevel = json.load(fp).get("log_level", "DEBUG")
self.logLevel = "DEBUG"
self.logger.setLevel(self._get_logging_level())
if os.path.exists(os.path.join(CONF_HOME, "config.json")):
with open(os.path.join(CONF_HOME, "config.json"), "r") as fp:
level = json.load(fp).get("log_level")
self.logLevel = level
self.setLevel(level)
def _is_no_log(self):
return self.getLevel() == Logger.NOLOG
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册