From a3afd13f4f234af8ff3174c4e817a48d714e491b Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 5 Dec 2015 23:25:26 +0000 Subject: [PATCH] Added export commands --- project/cli.py | 13 +++++-------- project/export/cli.py | 21 +++++++++++++++++++-- project/export/exports.py | 14 ++++++++++++++ project/utils/repos.py | 6 ++++++ 4 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 project/export/exports.py diff --git a/project/cli.py b/project/cli.py index 13fa7f5..d1dec2e 100644 --- a/project/cli.py +++ b/project/cli.py @@ -17,14 +17,11 @@ class DotFileCLI(click.MultiCommand): ns = {} if name not in self.list_commands(ctx): return - try: - fn = os.path.join(os.path.dirname(__file__), name + '/cli.py') - with open(fn) as f: - code = compile(f.read(), fn, 'exec') - eval(code, ns, ns) - return ns['cli'] - except: - return + fn = os.path.join(os.path.dirname(__file__), name + '/cli.py') + with open(fn) as f: + code = compile(f.read(), fn, 'exec') + eval(code, ns, ns) + return ns['cli'] cli = DotFileCLI(help='This tool\'s subcommands are loaded from a plugin folder dynamically.') diff --git a/project/export/cli.py b/project/export/cli.py index 3899ad5..a50d018 100644 --- a/project/export/cli.py +++ b/project/export/cli.py @@ -1,7 +1,24 @@ import click -from project.utils import config +from project.export import exports + @click.command('export') @click.argument('sections', nargs=-1) def cli(sections): - pass + functions = [f for k, f in exports.__dict__.items() if is_function(f)] + print("got all functions", functions) + if sections: # If they don't want to export everything + print("YOu specified sections") + for func in functions: + if func.__name__ not in sections: + print("{} not in {}".format(func.__name__, sections)) + functions.remove(func) + print("Calling functions", functions) + for func in functions: + print("Calling", func.__name__) + func() + return 0 + + +def is_function(item): + return type(item).__name__ == 'function' diff --git a/project/export/exports.py b/project/export/exports.py new file mode 100644 index 0000000..7e10fee --- /dev/null +++ b/project/export/exports.py @@ -0,0 +1,14 @@ +def atom(): + print("atom") + + +def thing(): + print("thing") + + +def stuff(): + print("stuff") + + +def foo(): + print("foo") diff --git a/project/utils/repos.py b/project/utils/repos.py index 8f53b43..82884a6 100644 --- a/project/utils/repos.py +++ b/project/utils/repos.py @@ -13,3 +13,9 @@ def clone_private_data(): exit_code = os.system("git clone -b master --single-branch {} {}" .format(config.get('private_repo'), constants.PRIVATE_DATA_DIR)) return exit_code + + +def has_data(data): + public_path = os.path.join(constants.PUBLIC_DATA_DIR, data) + private_path = os.path.join(constants.PRIVATE_DATA_DIR, data) + return os.path.isdir(public_path) or os.path.isdir(private_path)