2015-06-04 16:40:00 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2015-06-09 19:20:18 +02:00
|
|
|
Usage: qp_install_module.py list [--installed|--avalaible-local|--avalaible-remote]
|
|
|
|
qp_install_module.py install -n <name>
|
2015-06-05 09:50:24 +02:00
|
|
|
qp_install_module.py create -n <name> [<children_module>...]
|
2015-06-09 19:20:18 +02:00
|
|
|
qp_install_module.py download -n <name> [<path_folder>...]
|
|
|
|
|
2015-06-05 09:50:24 +02:00
|
|
|
|
|
|
|
Options:
|
|
|
|
list: List all the module avalaible
|
2015-06-09 19:20:18 +02:00
|
|
|
create: Create a new module
|
2015-06-04 16:40:00 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
|
|
|
|
try:
|
|
|
|
from docopt import docopt
|
2015-06-09 16:34:52 +02:00
|
|
|
from module_handler import ModuleHandler, get_dict_child
|
2015-06-09 19:20:18 +02:00
|
|
|
from module_handler import get_l_module_descendant
|
2015-06-04 16:40:00 +02:00
|
|
|
from update_README import Doc_key, Needed_key
|
|
|
|
except ImportError:
|
|
|
|
print "source .quantum_package.rc"
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
|
|
def save_new_module(path, l_child):
|
|
|
|
|
|
|
|
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
|
|
|
# N E E D E D _ C H I L D R E N _ M O D U L E S #
|
|
|
|
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~#~ #
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except OSError:
|
|
|
|
print "The module ({0}) already exist...".format(path)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
with open(os.path.join(path, "NEEDED_CHILDREN_MODULES"), "w") as f:
|
|
|
|
f.write(" ".join(l_child))
|
|
|
|
f.write("\n")
|
|
|
|
|
|
|
|
# ~#~#~#~#~#~#~ #
|
|
|
|
# R E A D _ M E #
|
|
|
|
# ~#~#~#~#~#~#~ #
|
|
|
|
|
|
|
|
module_name = os.path.basename(path)
|
|
|
|
|
|
|
|
header = "{0}\n{1}\n{0}\n".format("=" * len(module_name), module_name)
|
|
|
|
|
|
|
|
with open(os.path.join(path, "README.rst"), "w") as f:
|
|
|
|
f.write(header + "\n")
|
|
|
|
f.write(Doc_key + "\n")
|
|
|
|
f.write(Needed_key + "\n")
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
arguments = docopt(__doc__)
|
2015-06-09 19:20:18 +02:00
|
|
|
qp_root_src = os.path.join(os.environ['QP_ROOT'], "src")
|
|
|
|
qp_root_plugin = os.path.join(os.environ['QP_ROOT'], "plugins")
|
2015-06-04 16:40:00 +02:00
|
|
|
|
|
|
|
if arguments["list"]:
|
2015-06-09 19:20:18 +02:00
|
|
|
|
|
|
|
if arguments["--installed"]:
|
|
|
|
l_repository = [qp_root_src]
|
|
|
|
|
|
|
|
m_instance = ModuleHandler(l_repository)
|
|
|
|
|
2015-06-09 16:06:01 +02:00
|
|
|
for module in m_instance.l_module:
|
2015-06-04 16:40:00 +02:00
|
|
|
print module
|
|
|
|
|
|
|
|
elif arguments["create"]:
|
2015-06-09 19:20:18 +02:00
|
|
|
m_instance = ModuleHandler(l_repository)
|
|
|
|
|
2015-06-04 16:40:00 +02:00
|
|
|
l_children = arguments["<children_module>"]
|
|
|
|
|
2015-06-09 19:20:18 +02:00
|
|
|
qp_root = os.environ['QP_ROOT']
|
|
|
|
path = os.path.join(qp_root_src, arguments["<name>"])
|
2015-06-04 16:40:00 +02:00
|
|
|
|
|
|
|
print "You will create the module:"
|
|
|
|
print path
|
|
|
|
|
|
|
|
for children in l_children:
|
2015-06-09 16:06:01 +02:00
|
|
|
if children not in m_instance.dict_descendant:
|
2015-06-04 16:40:00 +02:00
|
|
|
print "This module ({0}) is not a valide module.".format(children)
|
|
|
|
print "Run `list` flag for the list of module avalaible"
|
|
|
|
print "Aborting..."
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
print "You ask for this submodule:"
|
|
|
|
print l_children
|
|
|
|
|
|
|
|
print "You can use all the routine in this module"
|
2015-06-09 16:06:01 +02:00
|
|
|
print l_children + m_instance.l_descendant_unique(l_children)
|
2015-06-04 16:40:00 +02:00
|
|
|
|
|
|
|
print "This can be reduce to:"
|
2015-06-09 16:06:01 +02:00
|
|
|
l_child_reduce = m_instance.l_reduce_tree(l_children)
|
2015-06-04 16:40:00 +02:00
|
|
|
print l_child_reduce
|
|
|
|
save_new_module(path, l_child_reduce)
|
2015-06-09 19:20:18 +02:00
|
|
|
|
|
|
|
elif arguments["download"]:
|
|
|
|
|
|
|
|
d_local = get_dict_child([qp_root_src])
|
|
|
|
d_remote = get_dict_child(arguments["<path_folder>"])
|
|
|
|
|
|
|
|
d_child = d_local.copy()
|
|
|
|
d_child.update(d_remote)
|
|
|
|
|
|
|
|
name = arguments["<name>"]
|
|
|
|
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["<name>"]
|
|
|
|
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
|