forked from p15670423/monkey
island: Move load_server_config() to config_loader.py
Because `monkey_island.py` has the same name as the `monkey_island` module, pytest can't import monkey_island.py and run any tests against its code.
This commit is contained in:
parent
83a235bb5d
commit
f7bef76f39
|
@ -7,26 +7,9 @@ gevent_monkey.patch_all()
|
||||||
import json # noqa: E402
|
import json # noqa: E402
|
||||||
import os # noqa: E402
|
import os # noqa: E402
|
||||||
|
|
||||||
from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR # noqa: E402
|
from monkey_island import config_loader # noqa: E402
|
||||||
from monkey_island.cc.server_utils.island_logger import setup_logging # noqa: E402
|
from monkey_island.cc.server_utils.island_logger import setup_logging # noqa: E402
|
||||||
|
|
||||||
DEFAULT_LOG_LEVEL = "INFO"
|
|
||||||
|
|
||||||
|
|
||||||
def load_server_config(path):
|
|
||||||
with open(server_config_path, "r") as f:
|
|
||||||
config_content = f.read()
|
|
||||||
data = json.loads(config_content)
|
|
||||||
data_dir = os.path.abspath(
|
|
||||||
os.path.expanduser(
|
|
||||||
os.path.expandvars(data["data_dir"] if "data_dir" in data else DEFAULT_DATA_DIR)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
log_level = data["log_level"] if "log_level" in data else DEFAULT_LOG_LEVEL
|
|
||||||
|
|
||||||
return data_dir, log_level
|
|
||||||
|
|
||||||
|
|
||||||
if "__main__" == __name__:
|
if "__main__" == __name__:
|
||||||
island_args = parse_cli_args()
|
island_args = parse_cli_args()
|
||||||
|
|
||||||
|
@ -35,7 +18,7 @@ if "__main__" == __name__:
|
||||||
try:
|
try:
|
||||||
server_config_path = os.path.expanduser(island_args.server_config)
|
server_config_path = os.path.expanduser(island_args.server_config)
|
||||||
|
|
||||||
data_dir, log_level = load_server_config(server_config_path)
|
data_dir, log_level = config_loader.load_server_config(server_config_path)
|
||||||
|
|
||||||
setup_logging(data_dir, log_level)
|
setup_logging(data_dir, log_level)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR
|
||||||
|
|
||||||
|
DEFAULT_LOG_LEVEL = "INFO"
|
||||||
|
|
||||||
|
|
||||||
|
def load_server_config(server_config_path):
|
||||||
|
with open(server_config_path, "r") as f:
|
||||||
|
config_content = f.read()
|
||||||
|
data = json.loads(config_content)
|
||||||
|
data_dir = os.path.abspath(
|
||||||
|
os.path.expanduser(
|
||||||
|
os.path.expandvars(data["data_dir"] if "data_dir" in data else DEFAULT_DATA_DIR)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
log_level = data["log_level"] if "log_level" in data else DEFAULT_LOG_LEVEL
|
||||||
|
|
||||||
|
return data_dir, log_level
|
Loading…
Reference in New Issue