Added repo functions and constants file
This commit is contained in:
parent
14920e7ec3
commit
6ffd153c9e
3 changed files with 48 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
||||||
import os
|
import os
|
||||||
from yaml import load, dump
|
from yaml import load, dump
|
||||||
|
from .constants import DEFAULT_CONFIG_DIR, USER_CONFIG_DIR, REQUIRED_KEYS
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from yaml import CLoader as Loader, CDumper as Dumper
|
from yaml import CLoader as Loader, CDumper as Dumper
|
||||||
|
@ -7,11 +8,6 @@ except ImportError:
|
||||||
from yaml import Loader, Dumper
|
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):
|
def get_config_data(filename):
|
||||||
try:
|
try:
|
||||||
with open(filename) as config_file:
|
with open(filename) as config_file:
|
||||||
|
@ -31,9 +27,8 @@ def write_user_config(refresh_after=False):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return e
|
return e
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_CONFIG = get_config_data(DEFAULT_CONFIG_DIR)
|
DEFAULT_CONFIG = get_config_data(DEFAULT_CONFIG_DIR)
|
||||||
|
|
||||||
|
|
||||||
USER_CONFIG = get_config_data(os.path.expanduser(USER_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"
|
return "NO_KEY"
|
||||||
USER_CONFIG[key] = value
|
USER_CONFIG[key] = value
|
||||||
return write_user_config(refresh_after)
|
return write_user_config(refresh_after)
|
||||||
|
|
||||||
|
|
||||||
|
def has_basics():
|
||||||
|
for key in REQUIRED_KEYS:
|
||||||
|
if not get(key):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
11
project/utils/constants.py
Normal file
11
project/utils/constants.py
Normal 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
28
project/utils/repos.py
Normal 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
|
Reference in a new issue