diff --git a/project/sync/cli.py b/project/sync/cli.py index 810f6ba..ee42314 100644 --- a/project/sync/cli.py +++ b/project/sync/cli.py @@ -1,9 +1,13 @@ import click -from project.utils import config +from project.utils import config, repos @click.command('sync') -def cli(): +@click.option('--private/--no-private', default=False) +def cli(private): if not config.has_basics(): print("You do not have all the basic requirements set.") return 1 + repos.clone_public_data() + if private: + repos.clone_public_data() diff --git a/project/utils/config.py b/project/utils/config.py index d4936eb..7cadc94 100644 --- a/project/utils/config.py +++ b/project/utils/config.py @@ -1,6 +1,6 @@ import os from yaml import load, dump -from .constants import DEFAULT_CONFIG_DIR, USER_CONFIG_DIR, REQUIRED_KEYS +from . import constants try: from yaml import CLoader as Loader, CDumper as Dumper @@ -21,15 +21,15 @@ def get_config_data(filename): def write_user_config(refresh_after=False): try: - with open(USER_CONFIG_DIR, 'w') as config_file: + with open(constants.USER_CONFIG_DIR, 'w') as config_file: dump(USER_CONFIG, config_file, indent=4, default_flow_style=False, Dumper=Dumper) return "SUCCESS" 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)) +DEFAULT_CONFIG = get_config_data(constants.DEFAULT_CONFIG_DIR) +USER_CONFIG = get_config_data(os.path.expanduser(constants.USER_CONFIG_DIR)) def get(key): @@ -48,7 +48,7 @@ def set(key, value, refresh_after=False): def has_basics(): - for key in REQUIRED_KEYS: + for key in constants.REQUIRED_KEYS: if not get(key): return False return True diff --git a/project/utils/constants.py b/project/utils/constants.py index 0f3e2eb..d626f13 100644 --- a/project/utils/constants.py +++ b/project/utils/constants.py @@ -1,11 +1,14 @@ import os - +# Core Directories BASE_DIR = os.path.dirname(os.path.abspath(__file__)) +DATA_DIR = os.path.expanduser("~/dfa/") - -USER_CONFIG_DIR = os.path.expanduser("~/.dfa.yml") +# Config +USER_CONFIG_DIR = os.path.join(DATA_DIR, ".dfa.yml") DEFAULT_CONFIG_DIR = os.path.join(BASE_DIR, 'defaults.yml') - - REQUIRED_KEYS = ['public_data'] + +# Data Directories +PRIVATE_DATA_DIR = os.path.join(DATA_DIR, 'private_data') +PUBLIC_DATA_DIR = os.path.join(DATA_DIR, 'public_data') diff --git a/project/utils/repos.py b/project/utils/repos.py index 9bddc7d..8f53b43 100644 --- a/project/utils/repos.py +++ b/project/utils/repos.py @@ -1,20 +1,15 @@ import os -from . import config - - -def has_repo_cloned(): - return os.path.isdir('./data') +from . import config, constants def clone_public_data(): - exit_code = 0 - exit_code = os.system("git clone -b master --single-branch {} data" - .format(config.get('public_repo'))) + exit_code = os.system("git clone -b master --single-branch {} {}" + .format(config.get('public_repo'), + constants.PUBLIC_DATA_DIR)) 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'))) + exit_code = os.system("git clone -b master --single-branch {} {}" + .format(config.get('private_repo'), constants.PRIVATE_DATA_DIR)) return exit_code