1
Fork 0
This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
dotfile-automator/project/export/cli.py

51 lines
1.4 KiB
Python
Raw Normal View History

2015-12-05 22:35:18 +00:00
import click
2015-12-05 23:25:26 +00:00
from project.export import exports
2016-01-05 18:32:51 +00:00
from project.utils import repos, shell
DEFAULT = 'all'
2015-12-05 23:25:26 +00:00
2015-12-05 22:35:18 +00:00
@click.command('export')
2016-01-05 18:32:51 +00:00
@click.argument('sections', nargs=-1, default=DEFAULT)
2015-12-05 22:35:18 +00:00
def cli(sections):
2015-12-05 23:25:26 +00:00
functions = [f for k, f in exports.__dict__.items() if is_function(f)]
2016-01-05 18:32:51 +00:00
if sections != DEFAULT: # If they don't want to export everything
2015-12-06 11:00:43 +00:00
temp_functions = functions
functions = []
for func in temp_functions:
if func.__name__ in sections:
functions.append(func)
2015-12-07 18:22:15 +00:00
errors = []
2015-12-05 23:25:26 +00:00
for func in functions:
2015-12-07 18:22:15 +00:00
try:
repos.go_to_data() # Reset data directory
func()
2016-01-05 18:32:51 +00:00
if func.__name__ in sections:
sections.remove(func)
2015-12-07 18:22:15 +00:00
except Exception as e:
errors.append(e)
2016-01-05 18:32:51 +00:00
if sections:
if DEFAULT in sections:
repos.go_to_data()
out, error = shell.call("make export")
if error:
errors.append(error)
else:
for item in sections:
repos.go_to_data()
out, error = shell.call("make " + item)
if error:
errors.append(error)
break
2015-12-07 18:22:15 +00:00
if errors:
print("Errors:")
for error in errors:
print(error)
2016-01-05 18:32:51 +00:00
return 1
2015-12-05 23:25:26 +00:00
return 0
def is_function(item):
return type(item).__name__ == 'function'