diff --git a/scripts/module/module_handler.py b/scripts/module/module_handler.py index 25a7d10e..0a6ef2e2 100755 --- a/scripts/module/module_handler.py +++ b/scripts/module/module_handler.py @@ -19,41 +19,44 @@ Options: import os import sys import os.path +from collections import namedtuple try: from docopt import docopt - from decorator import classproperty except ImportError: print "source .quantum_package.rc" raise # Canot cache for namedtuple are not hashable -def get_dict_child(dir_=None): +def get_dict_child(l_root_abs=None): """Loop over MODULE in QP_ROOT/src, open all the NEEDED_CHILDREN_MODULES and create a dict[MODULE] = [sub module needed, ...] """ d_ref = dict() - if not dir_: + if not l_root_abs: qp_root = os.environ['QP_ROOT'] - dir_ = os.path.join(qp_root, 'src') + l_root_abs = [os.path.join(qp_root, 'src')] - for o in os.listdir(dir_): + for root_abs in l_root_abs: + for module_rel in os.listdir(root_abs): - try: - path_file = os.path.join(dir_, o, "NEEDED_CHILDREN_MODULES") - with open(path_file, "r") as f: - l_children = f.read().split() - except IOError: - pass - else: - if o not in d_ref: - d_ref[o] = l_children + module_abs = os.path.join(root_abs, module_rel) + try: + path_file = os.path.join(module_abs, "NEEDED_CHILDREN_MODULES") + + with open(path_file, "r") as f: + l_children = f.read().split() + except IOError: + pass else: - print "Module {0} alredy defined" - print "Abort" - sys.exit(1) + if module_rel not in d_ref: + d_ref[module_rel] = l_children + else: + print "Module {0} alredy defined" + print "Abort" + sys.exit(1) return d_ref @@ -79,8 +82,8 @@ def l_module_descendant(d_child, l_module): class ModuleHandler(): - def __init__(self, dict_child=get_dict_child()): - self.dict_child = dict_child + def __init__(self, l_root_abs=None): + self.dict_child = get_dict_child(l_root_abs) @property def l_module(self): diff --git a/scripts/module/qp_install_module.py b/scripts/module/qp_install_module.py index 8c7af219..31262e48 100755 --- a/scripts/module/qp_install_module.py +++ b/scripts/module/qp_install_module.py @@ -14,7 +14,7 @@ import os try: from docopt import docopt - from module_handler import ModuleHandler + from module_handler import ModuleHandler, get_dict_child from update_README import Doc_key, Needed_key except ImportError: print "source .quantum_package.rc" @@ -53,8 +53,8 @@ def save_new_module(path, l_child): if __name__ == '__main__': arguments = docopt(__doc__) - m_instance = ModuleHandler() + m_instance = ModuleHandler() if arguments["list"]: for module in m_instance.l_module: print module diff --git a/scripts/utility/decorator.py b/scripts/utility/decorator.py index 66b9e064..9be4ea2c 100644 --- a/scripts/utility/decorator.py +++ b/scripts/utility/decorator.py @@ -15,12 +15,3 @@ def cache(func): saved[args] = result return result return newfunc - - -class classproperty(object): - - def __init__(self, fget): - self.fget = fget - - def __get__(self, owner_self, owner_cls): - return self.fget(owner_cls)