From 2fb77fcb390adee87ad038c9335d920eb8d9f55f Mon Sep 17 00:00:00 2001 From: shreyamalviya Date: Thu, 20 May 2021 16:27:11 +0530 Subject: [PATCH] Get default directory depending on OS --- .../cc/environment/server_config_generator.py | 3 ++- monkey/monkey_island/cc/server_utils/consts.py | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/monkey/monkey_island/cc/environment/server_config_generator.py b/monkey/monkey_island/cc/environment/server_config_generator.py index fd47889ea..17ee4a50c 100644 --- a/monkey/monkey_island/cc/environment/server_config_generator.py +++ b/monkey/monkey_island/cc/environment/server_config_generator.py @@ -3,6 +3,7 @@ from pathlib import Path from monkey_island.cc.environment.data_dir_generator import create_data_dir from monkey_island.cc.server_utils.consts import ( + DEFAULT_DATA_DIR, DEFAULT_DEVELOP_SERVER_CONFIG_PATH, DEFAULT_SERVER_CONFIG_PATH, ) @@ -10,7 +11,7 @@ from monkey_island.cc.server_utils.consts import ( def create_default_server_config_file() -> str: if not os.path.isfile(DEFAULT_SERVER_CONFIG_PATH): - create_data_dir(DEFAULT_SERVER_CONFIG_PATH, False) + create_data_dir(DEFAULT_DATA_DIR, False) write_default_server_config_to_file(DEFAULT_SERVER_CONFIG_PATH) return DEFAULT_SERVER_CONFIG_PATH diff --git a/monkey/monkey_island/cc/server_utils/consts.py b/monkey/monkey_island/cc/server_utils/consts.py index eaf7ec416..a3005ad31 100644 --- a/monkey/monkey_island/cc/server_utils/consts.py +++ b/monkey/monkey_island/cc/server_utils/consts.py @@ -1,17 +1,28 @@ import os +import sys __author__ = "itay.mizeretz" +def get_default_data_dir() -> str: + is_windows_os = sys.platform.startswith("win") + if is_windows_os: + return r"%AppData%\monkey_island" + else: + return r"$HOME/.monkey_island" + + SERVER_CONFIG_FILENAME = "server_config.json" MONKEY_ISLAND_ABS_PATH = os.path.join(os.getcwd(), "monkey_island") -DEFAULT_DATA_DIR = os.path.join(MONKEY_ISLAND_ABS_PATH, "cc") +DEFAULT_DATA_DIR = os.path.expandvars(get_default_data_dir()) DEFAULT_MONKEY_TTL_EXPIRY_DURATION_IN_SECONDS = 60 * 5 -DEFAULT_SERVER_CONFIG_PATH = os.path.join(DEFAULT_DATA_DIR, SERVER_CONFIG_FILENAME) +DEFAULT_SERVER_CONFIG_PATH = os.path.expandvars( + os.path.join(DEFAULT_DATA_DIR, SERVER_CONFIG_FILENAME) +) DEFAULT_DEVELOP_SERVER_CONFIG_PATH = os.path.join( MONKEY_ISLAND_ABS_PATH, "cc", f"{SERVER_CONFIG_FILENAME}.develop"