2013-07-15 20:21:24 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
2015-11-21 18:24:00 +08:00
|
|
|
Bootstrap helps you to test pyFAI scripts without installing them
|
2014-11-28 01:42:28 +08:00
|
|
|
by patching your PYTHONPATH on the fly
|
2013-07-15 20:21:24 +08:00
|
|
|
|
|
|
|
example: ./bootstrap.py pyFAI-integrate test/testimages/Pilatus1M.edf
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
__authors__ = ["Frédéric-Emmanuel Picca", "Jérôme Kieffer"]
|
|
|
|
__contact__ = "jerome.kieffer@esrf.eu"
|
|
|
|
__license__ = "GPLv3+"
|
2015-11-21 18:24:00 +08:00
|
|
|
__date__ = "21/11/2015"
|
2014-11-28 01:42:28 +08:00
|
|
|
|
2013-07-15 20:21:24 +08:00
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import distutils.util
|
|
|
|
import subprocess
|
|
|
|
|
2014-11-27 20:56:37 +08:00
|
|
|
|
2015-11-21 18:24:00 +08:00
|
|
|
TARGET = os.path.basename(os.path.dirname(os.path.abspath(__file__))).split("-")[0]
|
|
|
|
|
|
|
|
|
2013-07-15 20:21:24 +08:00
|
|
|
def _copy(infile, outfile):
|
|
|
|
"link or copy file according to the OS. Nota those are HARD_LINKS"
|
|
|
|
if "link" in dir(os):
|
|
|
|
os.link(infile, outfile)
|
|
|
|
else:
|
|
|
|
shutil.copy(infile, outfile)
|
|
|
|
|
2014-11-27 20:56:37 +08:00
|
|
|
|
2013-07-15 20:21:24 +08:00
|
|
|
def _distutils_dir_name(dname="lib"):
|
|
|
|
"""
|
|
|
|
Returns the name of a distutils build directory
|
|
|
|
"""
|
|
|
|
platform = distutils.util.get_platform()
|
|
|
|
architecture = "%s.%s-%i.%i" % (dname, platform,
|
|
|
|
sys.version_info[0], sys.version_info[1])
|
|
|
|
return architecture
|
|
|
|
|
|
|
|
|
|
|
|
def _distutils_scripts_name():
|
|
|
|
"""Return the name of the distrutils scripts sirectory"""
|
|
|
|
f = "scripts-{version[0]}.{version[1]}"
|
|
|
|
return f.format(version=sys.version_info)
|
|
|
|
|
|
|
|
|
|
|
|
def _get_available_scripts(path):
|
|
|
|
res = []
|
|
|
|
try:
|
|
|
|
res = " ".join([s.rstrip('.py') for s in os.listdir(path)])
|
|
|
|
except OSError:
|
|
|
|
res = ["no script available, did you ran "
|
|
|
|
"'python setup.py build' before bootstrapping ?"]
|
|
|
|
return res
|
|
|
|
|
2014-11-27 20:56:37 +08:00
|
|
|
|
2013-07-15 20:21:24 +08:00
|
|
|
def _copy_files(source, dest, extn):
|
|
|
|
"""
|
2015-11-21 18:24:00 +08:00
|
|
|
copy all files with a given extension from source to destination
|
2013-07-15 20:21:24 +08:00
|
|
|
"""
|
2014-05-20 23:33:32 +08:00
|
|
|
if not os.path.isdir(dest):
|
|
|
|
os.makedirs(dest)
|
2013-07-15 20:21:24 +08:00
|
|
|
full_src = os.path.join(os.path.dirname(__file__), source)
|
|
|
|
for clf in os.listdir(full_src):
|
|
|
|
if clf.endswith(extn) and clf not in os.listdir(dest):
|
|
|
|
_copy(os.path.join(full_src, clf), os.path.join(dest, clf))
|
|
|
|
|
2015-01-23 22:07:12 +08:00
|
|
|
|
|
|
|
def runfile(fname):
|
|
|
|
try:
|
|
|
|
execfile(fname)
|
|
|
|
except SyntaxError:
|
|
|
|
env = os.environ.copy()
|
|
|
|
env.update({"PYTHONPATH": LIBPATH + os.pathsep + os.environ.get("PYTHONPATH", ""),
|
|
|
|
"PATH": SCRIPTSPATH + os.pathsep + os.environ.get("PATH", "")})
|
|
|
|
run = subprocess.Popen(sys.argv, shell=False, env=env)
|
|
|
|
run.wait()
|
|
|
|
|
2014-04-29 14:39:14 +08:00
|
|
|
home = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
SCRIPTSPATH = os.path.join(home,
|
2013-07-15 20:21:24 +08:00
|
|
|
'build', _distutils_scripts_name())
|
2014-04-29 14:39:14 +08:00
|
|
|
LIBPATH = (os.path.join(home,
|
|
|
|
'build', _distutils_dir_name('lib')))
|
2013-07-15 20:21:24 +08:00
|
|
|
|
|
|
|
if (not os.path.isdir(SCRIPTSPATH)) or (not os.path.isdir(LIBPATH)):
|
|
|
|
build = subprocess.Popen([sys.executable, "setup.py", "build"],
|
|
|
|
shell=False, cwd=os.path.dirname(__file__))
|
|
|
|
print("Build process ended with rc= %s" % build.wait())
|
2015-11-21 18:24:00 +08:00
|
|
|
_copy_files("openCL", os.path.join(LIBPATH, TARGET, "openCL"), ".cl")
|
|
|
|
_copy_files("gui", os.path.join(LIBPATH, TARGET, "gui"), ".ui")
|
|
|
|
_copy_files("calibration", os.path.join(LIBPATH, TARGET, "calibration"), ".D")
|
2013-07-15 20:21:24 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print("usage: ./bootstrap.py <script>\n")
|
|
|
|
print("Available scripts : %s\n" %
|
|
|
|
_get_available_scripts(SCRIPTSPATH))
|
|
|
|
sys.exit(1)
|
2014-05-22 23:00:55 +08:00
|
|
|
os.system("cd %s;python setup.py build; cd -" % home)
|
2013-07-15 20:21:24 +08:00
|
|
|
print("Executing %s from source checkout" % (sys.argv[1]))
|
|
|
|
|
|
|
|
sys.path.insert(0, LIBPATH)
|
|
|
|
print("01. Patched sys.path with %s" % LIBPATH)
|
|
|
|
|
|
|
|
sys.path.insert(0, SCRIPTSPATH)
|
|
|
|
print("02. Patched sys.path with %s" % SCRIPTSPATH)
|
|
|
|
|
|
|
|
script = sys.argv[1]
|
|
|
|
sys.argv = sys.argv[1:]
|
|
|
|
print("03. patch the sys.argv : ", sys.argv)
|
|
|
|
|
|
|
|
print("04. Executing %s.main()" % (script,))
|
2014-04-29 14:39:14 +08:00
|
|
|
fullpath = os.path.join(SCRIPTSPATH, script)
|
|
|
|
if os.path.exists(fullpath):
|
2015-01-23 22:07:12 +08:00
|
|
|
runfile(fullpath)
|
2014-04-29 14:39:14 +08:00
|
|
|
else:
|
|
|
|
if os.path.exists(script):
|
2015-01-23 22:07:12 +08:00
|
|
|
runfile(script)
|
2014-04-29 14:39:14 +08:00
|
|
|
else:
|
|
|
|
for dirname in os.environ.get("PATH", "").split(os.pathsep):
|
|
|
|
fullpath = os.path.join(dirname, script)
|
|
|
|
if os.path.exists(fullpath):
|
2015-01-23 22:07:12 +08:00
|
|
|
runfile(fullpath)
|
2014-04-29 14:39:14 +08:00
|
|
|
break
|
|
|
|
|