2015-06-04 16:40:00 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2015-07-16 14:25:20 +02:00
|
|
|
Usage:
|
2015-10-06 15:33:11 +02:00
|
|
|
qp_install_module.py create -n <name> [<children_modules>...]
|
2015-06-09 19:20:18 +02:00
|
|
|
qp_install_module.py download -n <name> [<path_folder>...]
|
2015-06-22 10:37:17 +02:00
|
|
|
qp_install_module.py install <name>...
|
2015-06-25 10:22:19 +02:00
|
|
|
qp_install_module.py list (--installed | --available-local)
|
2015-07-16 14:41:39 +02:00
|
|
|
qp_install_module.py uninstall <name>...
|
2015-06-09 19:20:18 +02:00
|
|
|
|
2015-06-05 09:50:24 +02:00
|
|
|
|
|
|
|
Options:
|
2015-10-06 15:33:11 +02:00
|
|
|
list: List all the modules available
|
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
|
2015-07-15 11:00:23 +02:00
|
|
|
import subprocess
|
2015-06-04 16:40:00 +02:00
|
|
|
|
|
|
|
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-07-28 17:02:00 +02:00
|
|
|
from qp_update_readme import D_KEY
|
2015-07-16 17:45:42 +02:00
|
|
|
from qp_path import QP_SRC, QP_PLUGINS, QP_ROOT
|
2015-06-04 16:40:00 +02:00
|
|
|
except ImportError:
|
2015-10-06 15:33:11 +02:00
|
|
|
print "Please check if you have sourced the ${QP_ROOT}/quantum_package.rc"
|
|
|
|
print "(`source ${QP_ROOT}/quantum_package.rc`)"
|
2015-07-02 09:40:21 +02:00
|
|
|
print sys.exit(1)
|
2015-06-04 16:40:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
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:
|
2015-10-06 15:33:11 +02:00
|
|
|
print "The module ({0}) already exists...".format(path)
|
2015-06-04 16:40:00 +02:00
|
|
|
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")
|
2015-07-28 17:02:00 +02:00
|
|
|
f.write(D_KEY["needed_module"])
|
|
|
|
f.write(D_KEY["documentation"])
|
2015-06-04 16:40:00 +02:00
|
|
|
|
2015-11-27 09:02:20 +01:00
|
|
|
with open(os.path.join(path, "%s.main.irp.f"%(module_name) ), "w") as f:
|
|
|
|
f.write("program {0}".format(module_name) )
|
|
|
|
f.write(""" implicit none
|
|
|
|
BEGIN_DOC
|
|
|
|
! TODO
|
|
|
|
END_DOC
|
|
|
|
print *, ' _/ '
|
|
|
|
print *, ' -:\_?, _Jm####La '
|
|
|
|
print *, 'J"(:" > _]#AZ#Z#UUZ##, '
|
|
|
|
print *, '_,::./ %(|i%12XmX1*1XL _?, '
|
|
|
|
print *, ' \..\ _\(vmWQwodY+ia%lnL _",/ ( '
|
|
|
|
print *, ' .:< ]J=mQD?WXn<uQWmmvd, -.-:=!\'
|
|
|
|
print *, ' "{Z jC]QW|=3Zv)Bi3BmXv3 = _7'
|
|
|
|
print *, ' ]h[Z6)WQ;)jZs]C;|$BZv+, : ./ '
|
|
|
|
print *, ' -#sJX%$Wmm#ev]hinW#Xi:` c ; '
|
|
|
|
print *, ' #X#X23###1}vI$WWmX1>|,)nr" '
|
|
|
|
print *, ' 4XZ#Xov1v}=)vnXAX1nnv;1n" '
|
|
|
|
print *, ' ]XX#ZXoovvvivnnnlvvo2*i7 '
|
|
|
|
print *, ' "23Z#1S2oo2XXSnnnoSo2>v" '
|
|
|
|
print *, ' miX#L -~`""!!1}oSoe|i7 '
|
|
|
|
print *, ' 4cn#m, v221=|v[ '
|
|
|
|
print *, ' ]hI3Zma,;..__wXSe=+vo '
|
|
|
|
print *, ' ]Zov*XSUXXZXZXSe||vo2 '
|
|
|
|
print *, ' ]Z#><iiii|i||||==vn2( '
|
|
|
|
print *, ' ]Z#i<ii||+|=||=:{no2[ '
|
|
|
|
print *, ' ]ZUsiiiiivi|=||=vo22[ '
|
|
|
|
print *, ' ]XZvlliiIi|i=|+|vooo '
|
|
|
|
print *, ' =v1llli||||=|||||lii( '
|
|
|
|
print *, ' ]iillii||||||||=>=|< '
|
|
|
|
print *, ' -ziiiii||||||+||==+> '
|
|
|
|
print *, ' -%|+++||=|=+|=|==/ '
|
|
|
|
print *, ' -a>====+|====-:- '
|
|
|
|
print *, ' "~,- -- /- '
|
|
|
|
print *, ' -. )> '
|
|
|
|
print *, ' .~ +- '
|
|
|
|
print *, ' . .... : . '
|
|
|
|
print *, ' -------~ '
|
|
|
|
print *, ''
|
|
|
|
end
|
|
|
|
""")
|
|
|
|
|
|
|
|
def main(arguments):
|
2015-06-04 16:40:00 +02:00
|
|
|
if arguments["list"]:
|
2015-06-09 19:20:18 +02:00
|
|
|
|
|
|
|
if arguments["--installed"]:
|
2015-06-23 10:04:59 +02:00
|
|
|
l_repository = [QP_SRC]
|
2015-06-25 10:22:19 +02:00
|
|
|
elif arguments["--available-local"]:
|
2015-06-23 10:04:59 +02:00
|
|
|
l_repository = [QP_PLUGINS]
|
2015-06-09 19:20:18 +02:00
|
|
|
|
|
|
|
m_instance = ModuleHandler(l_repository)
|
|
|
|
|
2015-06-22 10:22:00 +02:00
|
|
|
for module in sorted(m_instance.l_module):
|
2015-06-17 19:00:31 +02:00
|
|
|
print "* {0}".format(module)
|
2015-06-04 16:40:00 +02:00
|
|
|
|
|
|
|
elif arguments["create"]:
|
2015-06-23 10:04:59 +02:00
|
|
|
m_instance = ModuleHandler([QP_SRC])
|
2015-06-09 19:20:18 +02:00
|
|
|
|
2015-10-06 15:33:11 +02:00
|
|
|
l_children = arguments["<children_modules>"]
|
2015-06-04 16:40:00 +02:00
|
|
|
|
2015-07-16 11:39:52 +02:00
|
|
|
name = arguments["<name>"][0]
|
|
|
|
|
|
|
|
path = os.path.join(QP_PLUGINS, name)
|
2015-06-04 16:40:00 +02:00
|
|
|
|
2015-10-06 15:33:11 +02:00
|
|
|
print "Created module:"
|
|
|
|
print path, '\n'
|
2015-06-04 16:40:00 +02:00
|
|
|
|
|
|
|
for children in l_children:
|
2015-06-09 16:06:01 +02:00
|
|
|
if children not in m_instance.dict_descendant:
|
2015-10-06 15:33:11 +02:00
|
|
|
print "This module ({0}) is not a valid module.".format(children)
|
|
|
|
print "Run `list` for the list of available modules."
|
|
|
|
print "Maybe you need to install some other module first."
|
2015-06-04 16:40:00 +02:00
|
|
|
print "Aborting..."
|
|
|
|
sys.exit(1)
|
|
|
|
|
2015-10-06 15:33:11 +02:00
|
|
|
print "Needed module:"
|
|
|
|
print l_children, '\n'
|
2015-06-04 16:40:00 +02:00
|
|
|
|
2015-10-06 15:33:11 +02:00
|
|
|
print "This corresponds to using the following modules:"
|
|
|
|
print l_children + m_instance.l_descendant_unique(l_children), '\n'
|
2015-06-04 16:40:00 +02:00
|
|
|
|
2015-10-06 15:33:11 +02:00
|
|
|
print "Which is reduced to:"
|
2015-06-09 16:06:01 +02:00
|
|
|
l_child_reduce = m_instance.l_reduce_tree(l_children)
|
2015-10-06 15:33:11 +02:00
|
|
|
print l_child_reduce, '\n'
|
|
|
|
|
2015-07-16 11:39:52 +02:00
|
|
|
print "Installation",
|
2015-06-04 16:40:00 +02:00
|
|
|
save_new_module(path, l_child_reduce)
|
2015-06-09 19:20:18 +02:00
|
|
|
|
2015-07-16 11:39:52 +02:00
|
|
|
print " [ OK ]"
|
2015-10-06 20:54:10 +02:00
|
|
|
# print "` {0} install {1} `".format(os.path.basename(__file__), name)
|
2015-10-06 15:33:11 +02:00
|
|
|
print ""
|
2015-11-27 09:02:20 +01:00
|
|
|
arguments["create"]=False
|
|
|
|
arguments["install"]=True
|
|
|
|
main(arguments)
|
2015-07-16 11:39:52 +02:00
|
|
|
|
2015-06-09 19:20:18 +02:00
|
|
|
elif arguments["download"]:
|
2015-11-27 09:02:20 +01:00
|
|
|
print "Not yet implemented"
|
2015-06-17 19:00:31 +02:00
|
|
|
pass
|
2015-06-23 10:04:59 +02:00
|
|
|
# d_local = get_dict_child([QP_SRC])
|
2015-06-17 19:00:31 +02:00
|
|
|
# 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"]:
|
2015-06-09 19:20:18 +02:00
|
|
|
|
2015-06-23 10:04:59 +02:00
|
|
|
d_local = get_dict_child([QP_SRC])
|
|
|
|
d_plugin = get_dict_child([QP_PLUGINS])
|
2015-06-09 19:20:18 +02:00
|
|
|
|
|
|
|
d_child = d_local.copy()
|
2015-06-17 19:00:31 +02:00
|
|
|
d_child.update(d_plugin)
|
2015-06-09 19:20:18 +02:00
|
|
|
|
2015-06-17 19:00:31 +02:00
|
|
|
l_name = arguments["<name>"]
|
2015-06-09 19:20:18 +02:00
|
|
|
|
2015-06-17 19:00:31 +02:00
|
|
|
for name in l_name:
|
|
|
|
if name in d_local:
|
|
|
|
print "{0} Is already installed".format(name)
|
2015-06-09 19:20:18 +02:00
|
|
|
|
2015-06-17 19:00:31 +02:00
|
|
|
l_module_descendant = get_l_module_descendant(d_child, l_name)
|
2015-06-09 19:20:18 +02:00
|
|
|
|
2015-06-17 19:00:31 +02:00
|
|
|
l_module_to_cp = [module for module in l_module_descendant if module not in d_local]
|
2015-06-09 19:20:18 +02:00
|
|
|
|
2015-06-17 19:00:31 +02:00
|
|
|
if l_module_to_cp:
|
2015-06-09 19:20:18 +02:00
|
|
|
|
2015-06-17 19:00:31 +02:00
|
|
|
print "You will need all these modules"
|
|
|
|
print l_module_to_cp
|
2015-06-09 19:20:18 +02:00
|
|
|
|
2015-06-17 19:00:31 +02:00
|
|
|
print "Installation...",
|
2015-06-09 19:20:18 +02:00
|
|
|
|
2015-06-17 19:00:31 +02:00
|
|
|
for module_to_cp in l_module_to_cp:
|
2015-06-23 10:04:59 +02:00
|
|
|
src = os.path.join(QP_PLUGINS, module_to_cp)
|
|
|
|
des = os.path.join(QP_SRC, module_to_cp)
|
2015-06-22 10:22:00 +02:00
|
|
|
try:
|
|
|
|
os.symlink(src, des)
|
|
|
|
except OSError:
|
2015-06-23 10:04:59 +02:00
|
|
|
print "Your src directory is broken. Please remove %s" % des
|
2015-06-22 10:22:00 +02:00
|
|
|
raise
|
2015-07-15 11:00:23 +02:00
|
|
|
try:
|
|
|
|
subprocess.check_call(["qp_create_ninja.py", "update"])
|
|
|
|
except:
|
|
|
|
raise
|
2015-07-16 17:45:42 +02:00
|
|
|
|
|
|
|
print "[ OK ]"
|
2015-06-17 19:00:31 +02:00
|
|
|
print "You can now compile as usual"
|
2015-07-16 17:45:42 +02:00
|
|
|
print "`cd {0} ; ninja` for exemple".format(QP_ROOT)
|
|
|
|
print " or --in developement mode-- you can cd in a directory and compile here"
|
2015-06-22 10:37:17 +02:00
|
|
|
|
|
|
|
elif arguments["uninstall"]:
|
|
|
|
|
2015-06-23 10:04:59 +02:00
|
|
|
m_instance = ModuleHandler([QP_SRC])
|
|
|
|
d_descendant = m_instance.dict_descendant
|
|
|
|
|
|
|
|
d_local = get_dict_child([QP_SRC])
|
2015-06-22 10:37:17 +02:00
|
|
|
l_name = arguments["<name>"]
|
|
|
|
|
2015-06-23 10:04:59 +02:00
|
|
|
l_failed = [name for name in l_name if name not in d_local]
|
2015-07-15 11:00:23 +02:00
|
|
|
|
2015-06-22 10:37:17 +02:00
|
|
|
if l_failed:
|
|
|
|
print "Modules not installed:"
|
|
|
|
for name in sorted(l_failed):
|
2015-06-23 10:04:59 +02:00
|
|
|
print "* %s" % name
|
2015-06-22 10:37:17 +02:00
|
|
|
sys.exit(1)
|
2015-07-15 11:00:23 +02:00
|
|
|
|
2015-07-16 14:41:39 +02:00
|
|
|
l_name_to_remove = l_name + [module for module in m_instance.l_module for name in l_name if name in d_descendant[module]]
|
2015-07-15 11:00:23 +02:00
|
|
|
|
2015-07-16 14:41:39 +02:00
|
|
|
print "You will remove all of:"
|
|
|
|
print l_name_to_remove
|
2015-06-23 10:04:59 +02:00
|
|
|
|
2015-07-16 14:41:39 +02:00
|
|
|
for module in set(l_name_to_remove):
|
2015-06-23 10:04:59 +02:00
|
|
|
|
2015-07-15 11:00:23 +02:00
|
|
|
try:
|
|
|
|
subprocess.check_call(["module_handler.py", "clean", module])
|
|
|
|
except:
|
|
|
|
raise
|
2015-06-23 10:04:59 +02:00
|
|
|
|
2015-07-16 14:41:39 +02:00
|
|
|
for module in set(l_name_to_remove):
|
|
|
|
|
2015-07-15 11:00:23 +02:00
|
|
|
try:
|
|
|
|
os.unlink(os.path.join(QP_SRC, module))
|
|
|
|
except OSError:
|
2015-10-06 15:33:11 +02:00
|
|
|
print "%s is a core module which can't be removed" % module
|
|
|
|
|
2015-11-27 09:02:20 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
arguments = docopt(__doc__)
|
|
|
|
main(arguments)
|
|
|
|
|