From 8282b3211aacd53775dc7c79e94bae3b10da5d3c Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sun, 6 Dec 2015 22:29:53 +0000 Subject: [PATCH] Fixed atom exporting, and a few other things --- project/export/cli.py | 2 ++ project/export/exports.py | 29 ++++++++++++++++++++++++++++- project/sync/cli.py | 6 +++--- project/utils/constants.py | 2 ++ project/utils/repos.py | 33 ++++++++++++++++++--------------- 5 files changed, 53 insertions(+), 19 deletions(-) diff --git a/project/export/cli.py b/project/export/cli.py index 186957f..a5fbf9a 100644 --- a/project/export/cli.py +++ b/project/export/cli.py @@ -1,5 +1,6 @@ import click from project.export import exports +from project.utils import repos @click.command('export') @@ -13,6 +14,7 @@ def cli(sections): if func.__name__ in sections: functions.append(func) for func in functions: + repos.go_to_data() # Reset data directory func() return 0 diff --git a/project/export/exports.py b/project/export/exports.py index 7e10fee..9e13968 100644 --- a/project/export/exports.py +++ b/project/export/exports.py @@ -1,5 +1,32 @@ +import os, shutil +from yaml import load, dump +from project.utils import shell, constants + +try: + from yaml import CLoader as Loader, CDumper as Dumper +except ImportError: + from yaml import Loader, Dumper + + def atom(): - print("atom") + out, error = shell.call('which apm') + if not out or error: + print("You don't seem to have atom installed.") + return True + os.chdir('atom') + packages_themes = [] + with open('packages.yml') as pt_file: + packages_themes = load(pt_file, Loader=Loader) or {} + for package in packages_themes: + exit_code = os.system('apm install {}'.format(package)) + if exit_code != 0: + print("Error installing {}".format(package), exit_code) + return True + + shutil.copy2( + os.path.join(constants.PUBLIC_DATA_DIR, 'atom', 'keymap.cson'), + os.path.expanduser("~/.atom/keymap.cson") + ) def thing(): diff --git a/project/sync/cli.py b/project/sync/cli.py index 7d3aee3..89f2b2a 100644 --- a/project/sync/cli.py +++ b/project/sync/cli.py @@ -3,8 +3,8 @@ from project.utils import config, repos @click.command('sync') -@click.option('--private', default=False) -@click.option('--clean', default=False) +@click.option('--private/--no-private', default=False, required=False) +@click.option('--clean/--no-clean', default=False, required=False) def cli(private, clean): if clean: print("Cleaning") @@ -20,4 +20,4 @@ def cli(private, clean): print("private repo not set") return 1 error = repos.clone_private_data() - return int(error) + return 1 if error else 0 diff --git a/project/utils/constants.py b/project/utils/constants.py index 655f895..8cfa0ce 100644 --- a/project/utils/constants.py +++ b/project/utils/constants.py @@ -12,3 +12,5 @@ REQUIRED_KEYS = ['public_repo'] # Data Directories PRIVATE_DATA_DIR = os.path.join(DATA_DIR, 'private_data') PUBLIC_DATA_DIR = os.path.join(DATA_DIR, 'public_data') + +ALL_DATA_DIR = os.path.join(DATA_DIR, 'all_data') diff --git a/project/utils/repos.py b/project/utils/repos.py index a8cdc09..00c711d 100644 --- a/project/utils/repos.py +++ b/project/utils/repos.py @@ -5,47 +5,50 @@ from . import config, constants, shell def clone_public_data(): if os.path.isdir(constants.PUBLIC_DATA_DIR): + print("Updating public...") initial = os.getcwd() go_to_data() out, error = shell.call("git pull") os.chdir(initial) - if error: - print("Error:", out) - return error - - out, error = shell.call( - "git clone -b master --single-branch {} {}".format( - config.get('public_repo'), - constants.PUBLIC_DATA_DIR + print(out) + else: + print("Downloading public data...") + out, error = shell.call( + "git clone -b master --single-branch {} {}".format( + config.get('public_repo'), + constants.PUBLIC_DATA_DIR + ) ) + print(out) + copy_tree( + constants.PUBLIC_DATA_DIR, + constants.ALL_DATA_DIR ) - return error def clone_private_data(): if os.path.isdir(constants.PRIVATE_DATA_DIR): + print("Updating private data...") initial = os.getcwd() os.chdir(constants.PRIVATE_DATA_DIR) out, error = shell.call("git pull") os.chdir(initial) - if error: - print("Error:", out) + print(out) return error else: + print("Downloading private data...") out, error = shell.call( "git clone -b master --single-branch {} {}".format( config.get('private_repo'), constants.PRIVATE_DATA_DIR ) ) - if error: - return error + print(out) copy_tree( constants.PRIVATE_DATA_DIR, - constants.PUBLIC_DATA_DIR + constants.ALL_DATA_DIR ) - return error def has_data(data):