mirror of
https://github.com/LCPQ/quantum_package
synced 2025-01-03 10:05:57 +01:00
No we can set the root for the dict of dependancy
This commit is contained in:
parent
af34292086
commit
8c5c1069e0
@ -19,41 +19,44 @@ Options:
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import os.path
|
import os.path
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
from decorator import classproperty
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "source .quantum_package.rc"
|
print "source .quantum_package.rc"
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
# Canot cache for namedtuple are not hashable
|
# 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
|
"""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_:
|
if not l_root_abs:
|
||||||
qp_root = os.environ['QP_ROOT']
|
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:
|
module_abs = os.path.join(root_abs, module_rel)
|
||||||
path_file = os.path.join(dir_, o, "NEEDED_CHILDREN_MODULES")
|
try:
|
||||||
with open(path_file, "r") as f:
|
path_file = os.path.join(module_abs, "NEEDED_CHILDREN_MODULES")
|
||||||
l_children = f.read().split()
|
|
||||||
except IOError:
|
with open(path_file, "r") as f:
|
||||||
pass
|
l_children = f.read().split()
|
||||||
else:
|
except IOError:
|
||||||
if o not in d_ref:
|
pass
|
||||||
d_ref[o] = l_children
|
|
||||||
else:
|
else:
|
||||||
print "Module {0} alredy defined"
|
if module_rel not in d_ref:
|
||||||
print "Abort"
|
d_ref[module_rel] = l_children
|
||||||
sys.exit(1)
|
else:
|
||||||
|
print "Module {0} alredy defined"
|
||||||
|
print "Abort"
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
return d_ref
|
return d_ref
|
||||||
|
|
||||||
@ -79,8 +82,8 @@ def l_module_descendant(d_child, l_module):
|
|||||||
|
|
||||||
class ModuleHandler():
|
class ModuleHandler():
|
||||||
|
|
||||||
def __init__(self, dict_child=get_dict_child()):
|
def __init__(self, l_root_abs=None):
|
||||||
self.dict_child = dict_child
|
self.dict_child = get_dict_child(l_root_abs)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def l_module(self):
|
def l_module(self):
|
||||||
|
@ -14,7 +14,7 @@ import os
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from docopt import docopt
|
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
|
from update_README import Doc_key, Needed_key
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print "source .quantum_package.rc"
|
print "source .quantum_package.rc"
|
||||||
@ -53,8 +53,8 @@ def save_new_module(path, l_child):
|
|||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
arguments = docopt(__doc__)
|
arguments = docopt(__doc__)
|
||||||
m_instance = ModuleHandler()
|
|
||||||
|
|
||||||
|
m_instance = ModuleHandler()
|
||||||
if arguments["list"]:
|
if arguments["list"]:
|
||||||
for module in m_instance.l_module:
|
for module in m_instance.l_module:
|
||||||
print module
|
print module
|
||||||
|
@ -15,12 +15,3 @@ def cache(func):
|
|||||||
saved[args] = result
|
saved[args] = result
|
||||||
return result
|
return result
|
||||||
return newfunc
|
return newfunc
|
||||||
|
|
||||||
|
|
||||||
class classproperty(object):
|
|
||||||
|
|
||||||
def __init__(self, fget):
|
|
||||||
self.fget = fget
|
|
||||||
|
|
||||||
def __get__(self, owner_self, owner_cls):
|
|
||||||
return self.fget(owner_cls)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user