mirror of
https://github.com/LCPQ/quantum_package
synced 2024-12-23 04:43:50 +01:00
Cleaning only_children_to_all_genealogy.py
This commit is contained in:
parent
ae4bc3d71b
commit
6316d5a1fd
@ -3,13 +3,32 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
from functools import wraps
|
||||||
|
|
||||||
def get_dict_genealogy(all_children=False):
|
|
||||||
|
def cache(func):
|
||||||
|
saved = {}
|
||||||
|
|
||||||
|
@wraps(func)
|
||||||
|
def newfunc(*args):
|
||||||
|
if args in saved:
|
||||||
|
return saved[args]
|
||||||
|
|
||||||
|
result = func(*args)
|
||||||
|
saved[args] = result
|
||||||
|
return result
|
||||||
|
return newfunc
|
||||||
|
|
||||||
|
|
||||||
|
@cache
|
||||||
|
def get_dict_genealogy():
|
||||||
|
"""Loop over MODULE in QPACKAGE_ROOT/src, open all the NEEDED_CHILDREN_MODULES
|
||||||
|
and create a dict[MODULE] = [sub module needed, ...]
|
||||||
|
"""
|
||||||
|
d_ref = dict()
|
||||||
|
|
||||||
qpackage_root = os.environ['QPACKAGE_ROOT']
|
qpackage_root = os.environ['QPACKAGE_ROOT']
|
||||||
dir_ = os.path.join(qpackage_root,'src')
|
dir_ = os.path.join(qpackage_root, 'src')
|
||||||
|
|
||||||
d_ref = dict()
|
|
||||||
|
|
||||||
for o in os.listdir(dir_):
|
for o in os.listdir(dir_):
|
||||||
|
|
||||||
@ -21,15 +40,14 @@ def get_dict_genealogy(all_children=False):
|
|||||||
else:
|
else:
|
||||||
d_ref[o] = l_children
|
d_ref[o] = l_children
|
||||||
|
|
||||||
if all_children:
|
|
||||||
for module in d_ref:
|
|
||||||
d_ref[module] = get_all_children(d_ref, d_ref[module], [])
|
|
||||||
|
|
||||||
return d_ref
|
return d_ref
|
||||||
|
|
||||||
|
|
||||||
def module_children_to_all(d_ref,path):
|
def module_genealogy(path):
|
||||||
|
"""
|
||||||
|
Take a name of a NEEDED_CHILDREN_MODULES
|
||||||
|
and return a list of all the {sub, subsub, ...}children
|
||||||
|
"""
|
||||||
if not path:
|
if not path:
|
||||||
dir_ = os.getcwd()
|
dir_ = os.getcwd()
|
||||||
path = os.path.join(dir_, "NEEDED_CHILDREN_MODULES")
|
path = os.path.join(dir_, "NEEDED_CHILDREN_MODULES")
|
||||||
@ -40,51 +58,54 @@ def module_children_to_all(d_ref,path):
|
|||||||
except IOError:
|
except IOError:
|
||||||
return []
|
return []
|
||||||
else:
|
else:
|
||||||
needed_module = l_children
|
|
||||||
for module in l_children:
|
|
||||||
|
|
||||||
for children in get_all_children(d_ref, d_ref[module], []):
|
needed_module = get_it_and_children(l_children)
|
||||||
if children not in needed_module:
|
|
||||||
needed_module.append(children)
|
|
||||||
|
|
||||||
return needed_module
|
return needed_module
|
||||||
|
|
||||||
|
|
||||||
def get_all_children(d_ref, l_module, l=[]):
|
def get_it_and_children(l_module):
|
||||||
"""
|
"""
|
||||||
From a d_ref (who containt all the data --flatter or not-- create
|
From a list of module return the module and all of the genealogy
|
||||||
an flatten list who contain all the children
|
|
||||||
"""
|
"""
|
||||||
|
d_ref = get_dict_genealogy()
|
||||||
|
|
||||||
|
l = []
|
||||||
for module in l_module:
|
for module in l_module:
|
||||||
if module not in l:
|
if module not in l:
|
||||||
l.append(module)
|
l.append(module)
|
||||||
get_all_children(d_ref, d_ref[module], l)
|
l.extend(get_it_and_children(d_ref[module]))
|
||||||
|
|
||||||
return list(set(l))
|
return list(set(l))
|
||||||
|
|
||||||
|
|
||||||
def reduce_(d_ref, name):
|
def get_all_children(l_module):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Take a big list and try to find the lower parent
|
From a list of module return all the genealogy
|
||||||
available
|
"""
|
||||||
|
|
||||||
|
it_and_all = get_it_and_children(l_module)
|
||||||
|
return [children for children in it_and_all if children not in l_module]
|
||||||
|
|
||||||
|
|
||||||
|
def reduce_(l_module):
|
||||||
|
"""
|
||||||
|
Take a l_module and try to find the lower combinaitions
|
||||||
|
of module with the same genealogy
|
||||||
"""
|
"""
|
||||||
import itertools
|
import itertools
|
||||||
|
d_ref = get_dict_genealogy()
|
||||||
|
|
||||||
a = sorted(get_all_children(d_ref[name]))
|
target_genealogy = sorted(get_all_children(l_module))
|
||||||
|
|
||||||
for i in xrange(len(d_ref)):
|
for i in xrange(len(d_ref)):
|
||||||
for c in itertools.combinations(d_ref, i):
|
for c in itertools.combinations(d_ref, i):
|
||||||
|
|
||||||
l = []
|
guess_genealogy = sorted(get_it_and_children(d_ref, c))
|
||||||
b = sorted(get_all_children(c, l))
|
|
||||||
|
|
||||||
if a == b:
|
if target_genealogy == guess_genealogy:
|
||||||
return c
|
return c
|
||||||
|
|
||||||
#for i in sorted(d_ref):
|
|
||||||
# print i, reduce_(i)
|
|
||||||
#
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import sys
|
import sys
|
||||||
@ -94,15 +115,5 @@ if __name__ == '__main__':
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
path = None
|
path = None
|
||||||
|
|
||||||
d_ref = get_dict_genealogy()
|
l_all_needed_molule = module_genealogy(path)
|
||||||
|
|
||||||
l_all_needed_molule = module_children_to_all(d_ref, path)
|
|
||||||
print " ".join(sorted(l_all_needed_molule))
|
print " ".join(sorted(l_all_needed_molule))
|
||||||
|
|
||||||
# print d_ref
|
|
||||||
#
|
|
||||||
# d_ref = get_dict_genealogy(True)
|
|
||||||
#
|
|
||||||
# print d_ref
|
|
||||||
#
|
|
||||||
# module_hl_to_ll(d_ref)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user