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():
|
2016-07-31 17:18:17 +02:00
|
|
|
modules = boxes.generators.getAllGeneratorModules()
|
|
|
|
del modules['_template']
|
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()
|
2017-02-23 17:34:57 +01:00
|
|
|
elif (sys.argv[1] in modules or
|
|
|
|
(sys.argv[1].startswith("--generator=") and
|
|
|
|
sys.argv[1][12:] in modules)):
|
|
|
|
if sys.argv[1].startswith("--generator="):
|
|
|
|
sys.argv[1] = sys.argv[1][12:]
|
2016-03-23 22:15:34 +01:00
|
|
|
name = sys.argv[1]
|
|
|
|
sys.argv[0] = "%s %s" % (sys.argv[0], sys.argv[1])
|
2017-02-23 17:34:57 +01:00
|
|
|
sys.argv[1] = '--tab="0"'
|
|
|
|
del sys.argv[0]
|
2016-03-23 22:15:34 +01:00
|
|
|
del sys.argv[1]
|
|
|
|
modules[name].main()
|
|
|
|
elif sys.argv[1] == '--list':
|
|
|
|
print("Available generators:")
|
|
|
|
for name in sorted(modules):
|
2016-07-31 17:18:17 +02:00
|
|
|
if not hasattr(modules[name], "main"):
|
|
|
|
continue
|
2016-03-23 22:15:34 +01:00
|
|
|
print(" * ", name)
|
2016-03-25 17:49:33 +01:00
|
|
|
else:
|
2017-02-26 18:54:34 +01:00
|
|
|
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()
|