From 1bceb5b150074825ce4a03f57901651ca3a47326 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 6 Dec 2015 16:15:04 +0000 Subject: [PATCH] Added update command for cloning --- project/sync/cli.py | 8 ++++---- project/utils/repos.py | 20 ++++++++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/project/sync/cli.py b/project/sync/cli.py index b5dab73..fd97c65 100644 --- a/project/sync/cli.py +++ b/project/sync/cli.py @@ -8,9 +8,9 @@ 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: + exit_code = repos.clone_public_data() + if private and exit_code == 0: if not config.get('private_repo'): print("private repo not set") - return 0 - repos.clone_public_data() + exit_code = repos.clone_public_data() + return exit_code diff --git a/project/utils/repos.py b/project/utils/repos.py index 42d40d1..d7523d1 100644 --- a/project/utils/repos.py +++ b/project/utils/repos.py @@ -3,6 +3,13 @@ from . import config, constants def clone_public_data(): + if os.path.isdir(constants.PUBLIC_DATA_DIR): + initial = os.getcwd() + go_to_data() + exit_code = os.system("git pull") + os.chdir(initial) + return exit_code + exit_code = os.system("git clone -b master --single-branch {} {}" .format(config.get('public_repo'), constants.PUBLIC_DATA_DIR)) @@ -10,8 +17,15 @@ def clone_public_data(): def clone_private_data(): - exit_code = os.system("git clone -b master --single-branch {} {}" - .format(config.get('private_repo'), constants.PRIVATE_DATA_DIR)) + exit_code = 0 + if os.path.isdir(constants.PRIVATE_DATA_DIR): + initial = os.getcwd() + os.chdir(constants.PRIVATE_DATA_DIR) + exit_code = os.system("git pull") + os.chdir(initial) + else: + exit_code = os.system("git clone -b master --single-branch {} {}" + .format(config.get('private_repo'), constants.PRIVATE_DATA_DIR)) if exit_code != 0: return exit_code @@ -19,6 +33,8 @@ def clone_private_data(): constants.PRIVATE_DATA_DIR, constants.PUBLIC_DATA_DIR ) + return exit_code + def has_data(data):