Updated config
This commit is contained in:
parent
17fc302be4
commit
b7797157cc
4 changed files with 25 additions and 23 deletions
|
@ -1,9 +1,13 @@
|
||||||
import click
|
import click
|
||||||
from project.utils import config
|
from project.utils import config, repos
|
||||||
|
|
||||||
|
|
||||||
@click.command('sync')
|
@click.command('sync')
|
||||||
def cli():
|
@click.option('--private/--no-private', default=False)
|
||||||
|
def cli(private):
|
||||||
if not config.has_basics():
|
if not config.has_basics():
|
||||||
print("You do not have all the basic requirements set.")
|
print("You do not have all the basic requirements set.")
|
||||||
return 1
|
return 1
|
||||||
|
repos.clone_public_data()
|
||||||
|
if private:
|
||||||
|
repos.clone_public_data()
|
||||||
|
|
|
@ -1,6 +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
|
from . import constants
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from yaml import CLoader as Loader, CDumper as Dumper
|
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):
|
def write_user_config(refresh_after=False):
|
||||||
try:
|
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)
|
dump(USER_CONFIG, config_file, indent=4, default_flow_style=False, Dumper=Dumper)
|
||||||
return "SUCCESS"
|
return "SUCCESS"
|
||||||
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(constants.DEFAULT_CONFIG_DIR)
|
||||||
USER_CONFIG = get_config_data(os.path.expanduser(USER_CONFIG_DIR))
|
USER_CONFIG = get_config_data(os.path.expanduser(constants.USER_CONFIG_DIR))
|
||||||
|
|
||||||
|
|
||||||
def get(key):
|
def get(key):
|
||||||
|
@ -48,7 +48,7 @@ def set(key, value, refresh_after=False):
|
||||||
|
|
||||||
|
|
||||||
def has_basics():
|
def has_basics():
|
||||||
for key in REQUIRED_KEYS:
|
for key in constants.REQUIRED_KEYS:
|
||||||
if not get(key):
|
if not get(key):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
# Core Directories
|
||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
DATA_DIR = os.path.expanduser("~/dfa/")
|
||||||
|
|
||||||
|
# Config
|
||||||
USER_CONFIG_DIR = os.path.expanduser("~/.dfa.yml")
|
USER_CONFIG_DIR = os.path.join(DATA_DIR, ".dfa.yml")
|
||||||
DEFAULT_CONFIG_DIR = os.path.join(BASE_DIR, 'defaults.yml')
|
DEFAULT_CONFIG_DIR = os.path.join(BASE_DIR, 'defaults.yml')
|
||||||
|
|
||||||
|
|
||||||
REQUIRED_KEYS = ['public_data']
|
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')
|
||||||
|
|
|
@ -1,20 +1,15 @@
|
||||||
import os
|
import os
|
||||||
from . import config
|
from . import config, constants
|
||||||
|
|
||||||
|
|
||||||
def has_repo_cloned():
|
|
||||||
return os.path.isdir('./data')
|
|
||||||
|
|
||||||
|
|
||||||
def clone_public_data():
|
def clone_public_data():
|
||||||
exit_code = 0
|
exit_code = os.system("git clone -b master --single-branch {} {}"
|
||||||
exit_code = os.system("git clone -b master --single-branch {} data"
|
.format(config.get('public_repo'),
|
||||||
.format(config.get('public_repo')))
|
constants.PUBLIC_DATA_DIR))
|
||||||
return exit_code
|
return exit_code
|
||||||
|
|
||||||
|
|
||||||
def clone_private_data():
|
def clone_private_data():
|
||||||
exit_code = 0
|
exit_code = os.system("git clone -b master --single-branch {} {}"
|
||||||
exit_code = os.system("git clone -b master --single-branch {} private_data"
|
.format(config.get('private_repo'), constants.PRIVATE_DATA_DIR))
|
||||||
.format(config.get('private_repo')))
|
|
||||||
return exit_code
|
return exit_code
|
||||||
|
|
Reference in a new issue