Get default directory depending on OS

This commit is contained in:
shreyamalviya 2021-05-20 16:27:11 +05:30 committed by Shreya
parent 409a3c5234
commit 2fb77fcb39
2 changed files with 15 additions and 3 deletions

View File

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

View File

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