From e11998adcf39294d1f37f2125dad6ff889cf5cbe Mon Sep 17 00:00:00 2001 From: Thomas Applencourt Date: Tue, 9 Jun 2015 19:20:18 +0200 Subject: [PATCH] It will be not that hard to implement module repositories --- scripts/module/module_handler.py | 8 ++--- scripts/module/qp_install_module.py | 55 ++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/scripts/module/module_handler.py b/scripts/module/module_handler.py index 0a6ef2e2..5bd8310e 100755 --- a/scripts/module/module_handler.py +++ b/scripts/module/module_handler.py @@ -61,7 +61,7 @@ def get_dict_child(l_root_abs=None): return d_ref -def l_module_descendant(d_child, l_module): +def get_l_module_descendant(d_child, l_module): """ From a list of module return the module and descendant """ @@ -71,7 +71,7 @@ def l_module_descendant(d_child, l_module): if module not in l: l.append(module) try: - l.extend(l_module_descendant(d_child, d_child[module])) + l.extend(get_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" @@ -113,8 +113,8 @@ class ModuleHandler(): d_child = self.dict_child for module_name in d_child: - d[module_name] = l_module_descendant(d_child, - d_child[module_name]) + d[module_name] = get_l_module_descendant(d_child, + d_child[module_name]) return d diff --git a/scripts/module/qp_install_module.py b/scripts/module/qp_install_module.py index 31262e48..03dbd350 100755 --- a/scripts/module/qp_install_module.py +++ b/scripts/module/qp_install_module.py @@ -1,12 +1,15 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- """ -Usage: qp_install_module.py list +Usage: qp_install_module.py list [--installed|--avalaible-local|--avalaible-remote] + qp_install_module.py install -n qp_install_module.py create -n [...] + qp_install_module.py download -n [...] + Options: list: List all the module avalaible - create: Create a new module + create: Create a new module """ import sys @@ -15,6 +18,7 @@ import os try: from docopt import docopt from module_handler import ModuleHandler, get_dict_child + from module_handler import get_l_module_descendant from update_README import Doc_key, Needed_key except ImportError: print "source .quantum_package.rc" @@ -53,17 +57,26 @@ def save_new_module(path, l_child): if __name__ == '__main__': arguments = docopt(__doc__) + qp_root_src = os.path.join(os.environ['QP_ROOT'], "src") + qp_root_plugin = os.path.join(os.environ['QP_ROOT'], "plugins") - m_instance = ModuleHandler() if arguments["list"]: + + if arguments["--installed"]: + l_repository = [qp_root_src] + + m_instance = ModuleHandler(l_repository) + for module in m_instance.l_module: print module elif arguments["create"]: + m_instance = ModuleHandler(l_repository) + l_children = arguments[""] - qpackage_root = os.environ['QP_ROOT'] - path = os.path.join(qpackage_root, "src", arguments[""]) + qp_root = os.environ['QP_ROOT'] + path = os.path.join(qp_root_src, arguments[""]) print "You will create the module:" print path @@ -85,3 +98,35 @@ if __name__ == '__main__': l_child_reduce = m_instance.l_reduce_tree(l_children) print l_child_reduce save_new_module(path, l_child_reduce) + + elif arguments["download"]: + + d_local = get_dict_child([qp_root_src]) + d_remote = get_dict_child(arguments[""]) + + d_child = d_local.copy() + d_child.update(d_remote) + + name = arguments[""] + l_module_descendant = get_l_module_descendant(d_child, [name]) + + for module in l_module_descendant: + if module not in d_local: + print "you need to install", module + + elif arguments["install"]: + + d_local = get_dict_child([qp_root_src]) + + d_plugin = get_dict_child([qp_root_plugin]) + + d_child = d_local.copy() + d_child.update(d_plugin) + + name = arguments[""] + l_module_descendant = get_l_module_descendant(d_child, [name]) + + module_to_cp = [module for module in l_module_descendant if module not in d_local] + + print "For ln -s by hand the module" + print module_to_cp