From 37b7815e00173ab6698dc74ff86d3d13367dc8d9 Mon Sep 17 00:00:00 2001 From: shreyamalviya Date: Thu, 20 May 2021 16:35:19 +0530 Subject: [PATCH] Move `is_windows_os()` to separate file --- monkey/monkey_island/cc/environment/data_dir_generator.py | 6 ++---- monkey/monkey_island/cc/environment/utils.py | 5 +++++ monkey/monkey_island/cc/server_utils/consts.py | 6 +++--- 3 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 monkey/monkey_island/cc/environment/utils.py diff --git a/monkey/monkey_island/cc/environment/data_dir_generator.py b/monkey/monkey_island/cc/environment/data_dir_generator.py index 399ade277..98907d639 100644 --- a/monkey/monkey_island/cc/environment/data_dir_generator.py +++ b/monkey/monkey_island/cc/environment/data_dir_generator.py @@ -1,10 +1,8 @@ import os -import sys +from monkey_island.cc.environment.utils import is_windows_os from monkey_island.cc.environment.windows_permissions import set_full_folder_access -is_windows_os = sys.platform.startswith("win") - def create_data_dir(data_dir: str, create_parent_dirs: bool) -> None: if not os.path.isdir(data_dir): @@ -12,5 +10,5 @@ def create_data_dir(data_dir: str, create_parent_dirs: bool) -> None: os.makedirs(data_dir, mode=0o700) else: os.mkdir(data_dir, mode=0o700) - if is_windows_os: # `mode=0o700` doesn't work on Windows + if is_windows_os(): # `mode=0o700` doesn't work on Windows set_full_folder_access(folder_path=data_dir) diff --git a/monkey/monkey_island/cc/environment/utils.py b/monkey/monkey_island/cc/environment/utils.py new file mode 100644 index 000000000..cbb8a1d6f --- /dev/null +++ b/monkey/monkey_island/cc/environment/utils.py @@ -0,0 +1,5 @@ +import sys + + +def is_windows_os() -> bool: + return sys.platform.startswith("win") diff --git a/monkey/monkey_island/cc/server_utils/consts.py b/monkey/monkey_island/cc/server_utils/consts.py index a3005ad31..8b88b000b 100644 --- a/monkey/monkey_island/cc/server_utils/consts.py +++ b/monkey/monkey_island/cc/server_utils/consts.py @@ -1,12 +1,12 @@ import os -import sys + +from monkey_island.cc.environment.utils import is_windows_os __author__ = "itay.mizeretz" def get_default_data_dir() -> str: - is_windows_os = sys.platform.startswith("win") - if is_windows_os: + if is_windows_os(): return r"%AppData%\monkey_island" else: return r"$HOME/.monkey_island"