1
Fork 0

Added export commands

This commit is contained in:
Jake Howard 2015-12-05 23:25:26 +00:00
parent b490f8f568
commit a3afd13f4f
4 changed files with 44 additions and 10 deletions

View File

@ -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.')

View File

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

14
project/export/exports.py Normal file
View File

@ -0,0 +1,14 @@
def atom():
print("atom")
def thing():
print("thing")
def stuff():
print("stuff")
def foo():
print("foo")

View File

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