10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-11-18 12:03:57 +01:00

module_handler is now a module object not a class

This commit is contained in:
Thomas Applencourt 2015-06-09 16:06:01 +02:00
parent 4e707c1362
commit af34292086
3 changed files with 38 additions and 31 deletions

View File

@ -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_handler = namedtuple('EZ_handler', ['ez_module', 'ez_cfg', 'ez_interface',
'ez_config']) 'ez_config'])
Sym_link = namedtuple('Sym_link', ['source', 'destination']) 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": if mode == "production":
dict_root = ModuleHandler.dict_root dict_root = module_instance.dict_root
dict_root_path = dict_module_genelogy_path(dict_root) dict_root_path = dict_module_genelogy_path(dict_root)
d_binaries_condensed = defaultdict(list) 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 # # 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_genealogy_path = dict_module_genelogy_path(d_genealogy)
d_irp = get_file_dependency(d_genealogy_path) d_irp = get_file_dependency(d_genealogy_path)

View File

@ -29,12 +29,13 @@ except ImportError:
# Canot cache for namedtuple are not hashable # 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 """Loop over MODULE in QP_ROOT/src, open all the NEEDED_CHILDREN_MODULES
and create a dict[MODULE] = [sub module needed, ...] and create a dict[MODULE] = [sub module needed, ...]
""" """
d_ref = dict() d_ref = dict()
if not dir_:
qp_root = os.environ['QP_ROOT'] qp_root = os.environ['QP_ROOT']
dir_ = os.path.join(qp_root, 'src') dir_ = os.path.join(qp_root, 'src')
@ -47,12 +48,17 @@ def get_dict_child():
except IOError: except IOError:
pass pass
else: else:
if o not in d_ref:
d_ref[o] = l_children d_ref[o] = l_children
else:
print "Module {0} alredy defined"
print "Abort"
sys.exit(1)
return d_ref 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 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: if module not in l:
l.append(module) l.append(module)
try: try:
l.extend(l_module_generalogy_rec(d_child, d_child[module])) l.extend(l_module_descendant(d_child, d_child[module]))
except KeyError: except KeyError:
print >> sys.stderr, "`{0}` not submodule".format(module) print >> sys.stderr, "`{0}` not submodule".format(module)
print >> sys.stderr, "Check the corresponding NEEDED_CHILDREN_MODULES" 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)) 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): def l_module(self):
return self.dict_child.keys() return self.dict_child.keys()
@classproperty @property
def dict_parent(self): def dict_parent(self):
""" """
Get a dic of the first parent Get a dic of the first parent
@ -93,7 +100,7 @@ class ModuleHandler:
return d return d
@classproperty @property
def dict_descendant(self): def dict_descendant(self):
""" """
Get a dic of all the genealogy desc (children and all_children) Get a dic of all the genealogy desc (children and all_children)
@ -103,12 +110,12 @@ class ModuleHandler:
d_child = self.dict_child d_child = self.dict_child
for module_name in d_child: for module_name in d_child:
d[module_name] = l_module_generalogy_rec(d_child, d[module_name] = l_module_descendant(d_child,
d_child[module_name]) d_child[module_name])
return d return d
@classproperty @property
def dict_root(self): def dict_root(self):
""" """
Return a dict(module_name) = module_boss Return a dict(module_name) = module_boss
@ -126,9 +133,8 @@ class ModuleHandler:
return dict_root return dict_root
@classmethod def l_descendant_unique(self, l_module):
def l_descendant_unique(cls, l_module): d_desc = self.dict_descendant
d_desc = cls.dict_descendant
d = {} d = {}
for module in l_module: for module in l_module:
@ -137,10 +143,9 @@ class ModuleHandler:
return d.keys() return d.keys()
@classmethod def l_reduce_tree(self, l_module):
def l_reduce_tree(cls, l_module):
"""For a list of module in input return only the root""" """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 = [] l_module_reduce = []
for module in l_module: for module in l_module:
if module not in l_d_u: if module not in l_d_u:
@ -148,8 +153,7 @@ class ModuleHandler:
return l_module_reduce return l_module_reduce
@classmethod def create_png(self, l_module):
def create_png(cls, l_module):
"""Create the png of the dependency tree for a l_module""" """Create the png of the dependency tree for a l_module"""
# Init # Init
@ -170,7 +174,7 @@ class ModuleHandler:
# Init # Init
graph = pydot.Dot(graph_type='digraph') graph = pydot.Dot(graph_type='digraph')
d_ref = cls.dict_child d_ref = self.dict_child
# Create all the edge # Create all the edge
for module in l_module: for module in l_module:
@ -196,9 +200,10 @@ if __name__ == '__main__':
dir_ = os.path.dirname(path_file) dir_ = os.path.dirname(path_file)
path_file = os.path.basename(dir_) path_file = os.path.basename(dir_)
m = ModuleHandler()
if arguments['print_descendant']: if arguments['print_descendant']:
print " ".join(sorted(ModuleHandler.l_module)) print " ".join(sorted(m.l_module))
if arguments["create_png"]: if arguments["create_png"]:
ModuleHandler.create_png([path_file]) m.create_png([path_file])

View File

@ -53,9 +53,10 @@ def save_new_module(path, l_child):
if __name__ == '__main__': if __name__ == '__main__':
arguments = docopt(__doc__) arguments = docopt(__doc__)
m_instance = ModuleHandler()
if arguments["list"]: if arguments["list"]:
for module in ModuleHandler.l_module: for module in m_instance.l_module:
print module print module
elif arguments["create"]: elif arguments["create"]:
@ -68,7 +69,7 @@ if __name__ == '__main__':
print path print path
for children in l_children: 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 "This module ({0}) is not a valide module.".format(children)
print "Run `list` flag for the list of module avalaible" print "Run `list` flag for the list of module avalaible"
print "Aborting..." print "Aborting..."
@ -78,9 +79,9 @@ if __name__ == '__main__':
print l_children print l_children
print "You can use all the routine in this module" 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:" 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 print l_child_reduce
save_new_module(path, l_child_reduce) save_new_module(path, l_child_reduce)