From af342920867f33008e8f0e478e560b276c1ee7b7 Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Tue, 9 Jun 2015 16:06:01 +0200 Subject: [PATCH] module_handler is now a module object not a class --- scripts/compilation/qp_create_ninja.py | 5 ++- scripts/module/module_handler.py | 55 ++++++++++++++------------ scripts/module/qp_install_module.py | 9 +++-- 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/scripts/compilation/qp_create_ninja.py b/scripts/compilation/qp_create_ninja.py index 620c5f1b..47eb11bc 100755 --- a/scripts/compilation/qp_create_ninja.py +++ b/scripts/compilation/qp_create_ninja.py @@ -39,6 +39,7 @@ EZ_config_path = namedtuple('EZ_config', ['path_in_module', 'path_in_ezfio']) EZ_handler = namedtuple('EZ_handler', ['ez_module', 'ez_cfg', 'ez_interface', 'ez_config']) Sym_link = namedtuple('Sym_link', ['source', 'destination']) +module_instance = ModuleHandler() # _ @@ -511,7 +512,7 @@ def get_dict_binaries(l_module, mode="production"): if mode == "production": - dict_root = ModuleHandler.dict_root + dict_root = module_instance.dict_root dict_root_path = dict_module_genelogy_path(dict_root) d_binaries_condensed = defaultdict(list) @@ -656,7 +657,7 @@ if __name__ == "__main__": # G e n e a l o g y _ d i c t # # ~#~#~#~#~#~#~#~#~#~#~#~#~#~ # - d_genealogy = ModuleHandler.dict_descendant + d_genealogy = module_instance.dict_descendant d_genealogy_path = dict_module_genelogy_path(d_genealogy) d_irp = get_file_dependency(d_genealogy_path) diff --git a/scripts/module/module_handler.py b/scripts/module/module_handler.py index 7ae8e07f..25a7d10e 100755 --- a/scripts/module/module_handler.py +++ b/scripts/module/module_handler.py @@ -29,14 +29,15 @@ except ImportError: # Canot cache for namedtuple are not hashable -def get_dict_child(): +def get_dict_child(dir_=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() - qp_root = os.environ['QP_ROOT'] - dir_ = os.path.join(qp_root, 'src') + if not dir_: + qp_root = os.environ['QP_ROOT'] + dir_ = os.path.join(qp_root, 'src') for o in os.listdir(dir_): @@ -47,12 +48,17 @@ def get_dict_child(): except IOError: pass else: - d_ref[o] = l_children + if o not in d_ref: + d_ref[o] = l_children + else: + print "Module {0} alredy defined" + print "Abort" + sys.exit(1) return d_ref -def l_module_generalogy_rec(d_child, l_module): +def l_module_descendant(d_child, l_module): """ From a list of module return the module and descendant """ @@ -62,7 +68,7 @@ def l_module_generalogy_rec(d_child, l_module): if module not in l: l.append(module) try: - l.extend(l_module_generalogy_rec(d_child, d_child[module])) + l.extend(l_module_descendant(d_child, d_child[module])) except KeyError: print >> sys.stderr, "`{0}` not submodule".format(module) print >> sys.stderr, "Check the corresponding NEEDED_CHILDREN_MODULES" @@ -71,15 +77,16 @@ def l_module_generalogy_rec(d_child, l_module): return list(set(l)) -class ModuleHandler: +class ModuleHandler(): - dict_child = get_dict_child() + def __init__(self, dict_child=get_dict_child()): + self.dict_child = dict_child - @classproperty + @property def l_module(self): return self.dict_child.keys() - @classproperty + @property def dict_parent(self): """ Get a dic of the first parent @@ -93,7 +100,7 @@ class ModuleHandler: return d - @classproperty + @property def dict_descendant(self): """ Get a dic of all the genealogy desc (children and all_children) @@ -103,12 +110,12 @@ class ModuleHandler: d_child = self.dict_child for module_name in d_child: - d[module_name] = l_module_generalogy_rec(d_child, - d_child[module_name]) + d[module_name] = l_module_descendant(d_child, + d_child[module_name]) return d - @classproperty + @property def dict_root(self): """ Return a dict(module_name) = module_boss @@ -126,9 +133,8 @@ class ModuleHandler: return dict_root - @classmethod - def l_descendant_unique(cls, l_module): - d_desc = cls.dict_descendant + def l_descendant_unique(self, l_module): + d_desc = self.dict_descendant d = {} for module in l_module: @@ -137,10 +143,9 @@ class ModuleHandler: return d.keys() - @classmethod - def l_reduce_tree(cls, l_module): + def l_reduce_tree(self, l_module): """For a list of module in input return only the root""" - l_d_u = cls.l_descendant_unique(l_module) + l_d_u = self.l_descendant_unique(l_module) l_module_reduce = [] for module in l_module: if module not in l_d_u: @@ -148,8 +153,7 @@ class ModuleHandler: return l_module_reduce - @classmethod - def create_png(cls, l_module): + def create_png(self, l_module): """Create the png of the dependency tree for a l_module""" # Init @@ -170,7 +174,7 @@ class ModuleHandler: # Init graph = pydot.Dot(graph_type='digraph') - d_ref = cls.dict_child + d_ref = self.dict_child # Create all the edge for module in l_module: @@ -196,9 +200,10 @@ if __name__ == '__main__': dir_ = os.path.dirname(path_file) path_file = os.path.basename(dir_) + m = ModuleHandler() if arguments['print_descendant']: - print " ".join(sorted(ModuleHandler.l_module)) + print " ".join(sorted(m.l_module)) if arguments["create_png"]: - ModuleHandler.create_png([path_file]) + m.create_png([path_file]) diff --git a/scripts/module/qp_install_module.py b/scripts/module/qp_install_module.py index 2c5dd4fe..8c7af219 100755 --- a/scripts/module/qp_install_module.py +++ b/scripts/module/qp_install_module.py @@ -53,9 +53,10 @@ def save_new_module(path, l_child): if __name__ == '__main__': arguments = docopt(__doc__) + m_instance = ModuleHandler() if arguments["list"]: - for module in ModuleHandler.l_module: + for module in m_instance.l_module: print module elif arguments["create"]: @@ -68,7 +69,7 @@ if __name__ == '__main__': print path for children in l_children: - if children not in ModuleHandler.dict_descendant: + if children not in m_instance.dict_descendant: print "This module ({0}) is not a valide module.".format(children) print "Run `list` flag for the list of module avalaible" print "Aborting..." @@ -78,9 +79,9 @@ if __name__ == '__main__': print l_children print "You can use all the routine in this module" - print l_children + ModuleHandler.l_descendant_unique(l_children) + print l_children + m_instance.l_descendant_unique(l_children) print "This can be reduce to:" - l_child_reduce = ModuleHandler.l_reduce_tree(l_children) + l_child_reduce = m_instance.l_reduce_tree(l_children) print l_child_reduce save_new_module(path, l_child_reduce)