From 8ac7a65685ffe58529087bbe5a0063d1e0168f5c Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Sun, 13 Jan 2013 15:23:46 +0000 Subject: New framework to allow combining items. --- weatbag/items/__init__.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 weatbag/items/__init__.py (limited to 'weatbag/items/__init__.py') diff --git a/weatbag/items/__init__.py b/weatbag/items/__init__.py new file mode 100644 index 0000000..3d0922f --- /dev/null +++ b/weatbag/items/__init__.py @@ -0,0 +1,26 @@ +from importlib import import_module +from types import ModuleType + +def get_item_module(name): + """Returns the module for that item, or a blank module if no module exists. + """ + name = name.replace(' ','_') + try: + return import_module('weatbag.items.' + name) + except ImportError: + return ModuleType(name, "Dummy Module") + + +def _combine(item1, item2): + "Try combining items one way" + try: + return get_item_module(item1).combine(item2) + except AttributeError: + pass + +def combine(item1, item2): + "Try combining items either way round." + results = _combine(item1, item2) + if results is None: + results = _combine(item2, item1) + return results -- cgit v1.3