From 6ffd153c9e1577661025060f49bee9b4566086a5 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 4 Dec 2015 08:48:36 +0000 Subject: [PATCH] Added repo functions and constants file --- project/utils/config.py | 16 +++++++++------- project/utils/constants.py | 11 +++++++++++ project/utils/repos.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 project/utils/constants.py create mode 100644 project/utils/repos.py diff --git a/project/utils/config.py b/project/utils/config.py index 88cc8f2..d4936eb 100644 --- a/project/utils/config.py +++ b/project/utils/config.py @@ -1,5 +1,6 @@ import os from yaml import load, dump +from .constants import DEFAULT_CONFIG_DIR, USER_CONFIG_DIR, REQUIRED_KEYS try: from yaml import CLoader as Loader, CDumper as Dumper @@ -7,11 +8,6 @@ except ImportError: from yaml import Loader, Dumper -BASE_DIR = os.path.dirname(os.path.abspath(__file__)) -USER_CONFIG_DIR = os.path.expanduser("~/.dfa.yml") -DEFAULT_CONFIG_DIR = os.path.join(BASE_DIR, 'defaults.yml') - - def get_config_data(filename): try: with open(filename) as config_file: @@ -31,9 +27,8 @@ def write_user_config(refresh_after=False): except Exception as e: return e + DEFAULT_CONFIG = get_config_data(DEFAULT_CONFIG_DIR) - - USER_CONFIG = get_config_data(os.path.expanduser(USER_CONFIG_DIR)) @@ -50,3 +45,10 @@ def set(key, value, refresh_after=False): return "NO_KEY" USER_CONFIG[key] = value return write_user_config(refresh_after) + + +def has_basics(): + for key in REQUIRED_KEYS: + if not get(key): + return False + return True diff --git a/project/utils/constants.py b/project/utils/constants.py new file mode 100644 index 0000000..0f3e2eb --- /dev/null +++ b/project/utils/constants.py @@ -0,0 +1,11 @@ +import os + + +BASE_DIR = os.path.dirname(os.path.abspath(__file__)) + + +USER_CONFIG_DIR = os.path.expanduser("~/.dfa.yml") +DEFAULT_CONFIG_DIR = os.path.join(BASE_DIR, 'defaults.yml') + + +REQUIRED_KEYS = ['public_data'] diff --git a/project/utils/repos.py b/project/utils/repos.py new file mode 100644 index 0000000..04263b8 --- /dev/null +++ b/project/utils/repos.py @@ -0,0 +1,28 @@ +import os +from . import config + + +def has_repo_cloned(): + return os.path.isdir('./data') + + +def has_required_config_set(): + REQUIRED_KEYS = ['public_repo'] + for key in REQUIRED_KEYS: + if not config.get(key): + return False + return True + + +def clone_public_data(): + exit_code = 0 + exit_code = os.system("git clone -b master --single-branch {} data" + .format(config.get('public_repo'))) + return exit_code + + +def clone_private_data(): + exit_code = 0 + exit_code = os.system("git clone -b master --single-branch {} private_data" + .format(config.get('private_repo'))) + return exit_code