1
Fork 0

Added repo functions and constants file

This commit is contained in:
Jake Howard 2015-12-04 08:48:36 +00:00
parent 14920e7ec3
commit 6ffd153c9e
3 changed files with 48 additions and 7 deletions

View file

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

View file

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

28
project/utils/repos.py Normal file
View file

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