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

modify hub config

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