From 70bb1bf5afb441748e3efa1717e36988daacfbaf Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Fri, 25 Mar 2016 17:49:33 +0100 Subject: [PATCH] Move box generators into boxes.generators sub module --- boxes/generators/__init__.py | 24 +++++++++++++++++++ box.py => boxes/generators/box.py | 0 box2.py => boxes/generators/box2.py | 0 box3.py => boxes/generators/box3.py | 0 castle.py => boxes/generators/castle.py | 0 drillbox.py => boxes/generators/drillbox.py | 0 flexbox.py => boxes/generators/flexbox.py | 0 flexbox2.py => boxes/generators/flexbox2.py | 0 flexbox3.py => boxes/generators/flexbox3.py | 0 flextest.py => boxes/generators/flextest.py | 0 folder.py => boxes/generators/folder.py | 0 lamp.py => boxes/generators/lamp.py | 0 .../generators/magazinefile.py | 0 printer.py => boxes/generators/printer.py | 0 .../generators/silverwarebox.py | 0 .../generators/trayinsert.py | 0 .../generators/traylayout.py | 0 typetray.py => boxes/generators/typetray.py | 0 {bin => scripts}/boxes | 21 ++++++++-------- bserver.py => scripts/boxesserver | 13 +++++++--- 20 files changed, 45 insertions(+), 13 deletions(-) create mode 100644 boxes/generators/__init__.py rename box.py => boxes/generators/box.py (100%) rename box2.py => boxes/generators/box2.py (100%) rename box3.py => boxes/generators/box3.py (100%) rename castle.py => boxes/generators/castle.py (100%) rename drillbox.py => boxes/generators/drillbox.py (100%) rename flexbox.py => boxes/generators/flexbox.py (100%) rename flexbox2.py => boxes/generators/flexbox2.py (100%) rename flexbox3.py => boxes/generators/flexbox3.py (100%) rename flextest.py => boxes/generators/flextest.py (100%) rename folder.py => boxes/generators/folder.py (100%) rename lamp.py => boxes/generators/lamp.py (100%) rename magazinefile.py => boxes/generators/magazinefile.py (100%) rename printer.py => boxes/generators/printer.py (100%) rename silverwarebox.py => boxes/generators/silverwarebox.py (100%) rename trayinsert.py => boxes/generators/trayinsert.py (100%) rename traylayout.py => boxes/generators/traylayout.py (100%) rename typetray.py => boxes/generators/typetray.py (100%) rename {bin => scripts}/boxes (64%) rename bserver.py => scripts/boxesserver (94%) diff --git a/boxes/generators/__init__.py b/boxes/generators/__init__.py new file mode 100644 index 0000000..8a9adee --- /dev/null +++ b/boxes/generators/__init__.py @@ -0,0 +1,24 @@ + +__all__ = [ + "box", + "box2", + "box3", + "castle", + "drillbox", + "flexbox", + "flexbox2", + "flexbox3", + "flextest", + "folder", + "lamp", + "magazinefile", + "silverwarebox", + "trayinsert", + "traylayout", + "typetray", +] + +def getAllBoxGenerators(): + import importlib + return {name: importlib.import_module("boxes.generators." + name) + for name in __all__} diff --git a/box.py b/boxes/generators/box.py similarity index 100% rename from box.py rename to boxes/generators/box.py diff --git a/box2.py b/boxes/generators/box2.py similarity index 100% rename from box2.py rename to boxes/generators/box2.py diff --git a/box3.py b/boxes/generators/box3.py similarity index 100% rename from box3.py rename to boxes/generators/box3.py diff --git a/castle.py b/boxes/generators/castle.py similarity index 100% rename from castle.py rename to boxes/generators/castle.py diff --git a/drillbox.py b/boxes/generators/drillbox.py similarity index 100% rename from drillbox.py rename to boxes/generators/drillbox.py diff --git a/flexbox.py b/boxes/generators/flexbox.py similarity index 100% rename from flexbox.py rename to boxes/generators/flexbox.py diff --git a/flexbox2.py b/boxes/generators/flexbox2.py similarity index 100% rename from flexbox2.py rename to boxes/generators/flexbox2.py diff --git a/flexbox3.py b/boxes/generators/flexbox3.py similarity index 100% rename from flexbox3.py rename to boxes/generators/flexbox3.py diff --git a/flextest.py b/boxes/generators/flextest.py similarity index 100% rename from flextest.py rename to boxes/generators/flextest.py diff --git a/folder.py b/boxes/generators/folder.py similarity index 100% rename from folder.py rename to boxes/generators/folder.py diff --git a/lamp.py b/boxes/generators/lamp.py similarity index 100% rename from lamp.py rename to boxes/generators/lamp.py diff --git a/magazinefile.py b/boxes/generators/magazinefile.py similarity index 100% rename from magazinefile.py rename to boxes/generators/magazinefile.py diff --git a/printer.py b/boxes/generators/printer.py similarity index 100% rename from printer.py rename to boxes/generators/printer.py diff --git a/silverwarebox.py b/boxes/generators/silverwarebox.py similarity index 100% rename from silverwarebox.py rename to boxes/generators/silverwarebox.py diff --git a/trayinsert.py b/boxes/generators/trayinsert.py similarity index 100% rename from trayinsert.py rename to boxes/generators/trayinsert.py diff --git a/traylayout.py b/boxes/generators/traylayout.py similarity index 100% rename from traylayout.py rename to boxes/generators/traylayout.py diff --git a/typetray.py b/boxes/generators/typetray.py similarity index 100% rename from typetray.py rename to boxes/generators/typetray.py diff --git a/bin/boxes b/scripts/boxes similarity index 64% rename from bin/boxes rename to scripts/boxes index c51c1d9..1f40f8b 100755 --- a/bin/boxes +++ b/scripts/boxes @@ -5,7 +5,13 @@ import os import sys from pprint import pprint -import boxes +try: + import boxes +except ImportError: + sys.path.append(os.path.dirname(__file__) + "/..") + import boxes + +import boxes.generators def printusage(): print("""Usage: @@ -15,15 +21,8 @@ boxes [NAME] [options] """) def main(): - modules = {} - for module in os.listdir(os.path.dirname(__file__)): - if module in ('__init__.py', 'boxes.py', 'bserver.py') or module[-3:] != '.py': - continue - name = module[:-3] - module = __import__(name, locals(), globals()) - modules[name] = module - #pprint(modules) - + modules = boxes.generators.getAllBoxGenerators() + if len(sys.argv) == 1: printusage() elif sys.argv[1] in modules: @@ -35,5 +34,7 @@ def main(): print("Available generators:") for name in sorted(modules): print(" * ", name) + else: + print("unknown sub command") main() diff --git a/bserver.py b/scripts/boxesserver similarity index 94% rename from bserver.py rename to scripts/boxesserver index 2feb341..5bbcffb 100755 --- a/bserver.py +++ b/scripts/boxesserver @@ -1,6 +1,5 @@ #!/usr/bin/python3 -import boxes import sys import argparse import cgi @@ -12,8 +11,16 @@ from wsgiref.util import setup_testing_defaults from wsgiref.simple_server import make_server import wsgiref.util -import box, box2, box3, drillbox, flexbox, flexbox2, flexbox3, flextest, folder -import magazinefile, trayinsert, traylayout, typetray, silverwarebox +try: + import boxes.generators +except ImportError: + sys.path.append(os.path.dirname(__file__) + "/..") + import boxes.generators + + +from boxes.generators import box, box2, box3, drillbox +from boxes.generators import flexbox, flexbox2, flexbox3, flextest, folder +from boxes.generators import magazinefile, trayinsert, traylayout, typetray, silverwarebox class ArgumentParserError(Exception): pass