2016-07-11 23:01:57 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-03-23 22:15:34 +01:00
|
|
|
|
2017-02-23 17:34:57 +01:00
|
|
|
from __future__ import print_function
|
2016-03-23 22:15:34 +01:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from pprint import pprint
|
|
|
|
|
2017-02-23 17:20:50 +01:00
|
|
|
|
2016-03-25 17:49:33 +01:00
|
|
|
try:
|
|
|
|
import boxes
|
|
|
|
except ImportError:
|
2017-02-23 17:20:50 +01:00
|
|
|
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/..")
|
2016-03-25 17:49:33 +01:00
|
|
|
import boxes
|
|
|
|
|
|
|
|
import boxes.generators
|
2016-03-23 22:15:34 +01:00
|
|
|
|
|
|
|
def printusage():
|
|
|
|
print("""Usage:
|
|
|
|
boxes [NAME] [options]
|
|
|
|
--list list possible names
|
|
|
|
--help show help for given NAME
|
|
|
|
""")
|
|
|
|
|
|
|
|
def main():
|
2017-03-17 16:23:25 +01:00
|
|
|
generators = {name.split('.')[-1].lower() : box for name, box in
|
|
|
|
boxes.generators.getAllBoxGenerators().items()}
|
|
|
|
groups = boxes.generators.ui_groups
|
|
|
|
groups_by_name = boxes.generators.ui_groups_by_name
|
|
|
|
for name, box in generators.items():
|
|
|
|
groups_by_name.get(box.ui_group,
|
|
|
|
groups_by_name["Misc"]).add(box)
|
2017-03-09 17:42:37 +01:00
|
|
|
if len(sys.argv) > 1 and sys.argv[1].startswith("--id="):
|
2017-02-26 18:54:34 +01:00
|
|
|
del sys.argv[1]
|
2016-03-23 22:15:34 +01:00
|
|
|
if len(sys.argv) == 1:
|
|
|
|
printusage()
|
|
|
|
elif sys.argv[1] == '--list':
|
|
|
|
print("Available generators:")
|
2017-03-17 16:23:25 +01:00
|
|
|
for group in groups:
|
|
|
|
print('\n' + group.title)
|
|
|
|
if group.description:
|
|
|
|
print('\n%s\n' % group.description)
|
|
|
|
else:
|
|
|
|
print()
|
|
|
|
for box in group.generators:
|
|
|
|
print(" * ", box.__name__, ' - ', box.__doc__ or '')
|
2016-03-25 17:49:33 +01:00
|
|
|
else:
|
2017-03-17 16:23:25 +01:00
|
|
|
name = sys.argv[1].lower()
|
|
|
|
if name.startswith("--generator="):
|
|
|
|
name = name[12:]
|
|
|
|
if (name in generators):
|
|
|
|
box = generators[name]()
|
|
|
|
box.parseArgs(sys.argv[2:])
|
|
|
|
box.render()
|
|
|
|
else:
|
|
|
|
sys.stderr.write(str(sys.argv))
|
|
|
|
sys.stderr.write("Unknown generator name. Use boxes --list to get a list of available commands.")
|
2016-03-23 22:15:34 +01:00
|
|
|
|
|
|
|
main()
|