Add local_install / local_run tools

This commit is contained in:
Laurent Bachelier 2013-03-25 02:48:52 +01:00 committed by Florent
commit 64119bc03f
5 changed files with 137 additions and 28 deletions

36
tools/local_install.py Normal file
View file

@ -0,0 +1,36 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
import sys
import os
print "Weboob local installer"
print
if len(sys.argv) < 2:
print "This tool will install Weboob to be usuable without requiring"
print "messing with your system, which should only be touched by a package manager."
print
print "Usage: %s DESTINATION" % sys.argv[0]
print
print >>sys.stderr, "Error: Please provide a destination, " \
"for example %s/bin" % os.getenv('HOME')
sys.exit(1)
else:
dest = os.path.expanduser(sys.argv[1])
print "Installing weboob applications into %s." % dest
subprocess.check_call(
[sys.executable, 'setup.py',
'install', '--user', '--install-scripts', dest] + sys.argv[2:],
cwd=os.path.join(os.path.dirname(__file__), os.pardir))
subprocess.check_call([sys.executable, os.path.join(dest, 'weboob-config'), 'update'])
print
print "Installation done. Applications are available in %s." % dest
print "You can remove the source files."
print
print "To have easy access to the Weboob applications,"
print "you should add the following line to your ~/.bashrc or ~/.zshrc file:"
print "export PATH=\"$PATH:%s\"" % dest
print "And then restart your shells."

10
tools/local_install.sh Executable file
View file

@ -0,0 +1,10 @@
#!/bin/sh
set -e
if [ -z "${PYTHON}" ]; then
which python >/dev/null 2>&1 && PYTHON=$(which python)
which python2 >/dev/null 2>&1 && PYTHON=$(which python2)
which python2.7 >/dev/null 2>&1 && PYTHON=$(which python2.7)
fi
exec "${PYTHON}" "$(dirname $0)/local_install.py" "$@"

44
tools/local_run.py Normal file
View file

@ -0,0 +1,44 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
import sys
import os
import shutil
if len(sys.argv) < 2:
print "Usage: %s SCRIPTNAME [args]" % sys.argv[0]
sys.exit(1)
else:
script = sys.argv[1]
args = sys.argv[2:]
project = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))
wd = os.path.join(project, 'localconfig')
if not os.path.isdir(wd):
os.path.makedirs(wd)
env = os.environ.copy()
env['PYTHONPATH'] = project
env['WEBOOB_WORKDIR'] = wd
shutil.copyfile(
os.path.expanduser('~/.config/weboob/backends'),
os.path.join(project, wd, 'backends'))
with open(os.path.join(wd, 'sources.list'), 'w') as f:
f.write("file://%s\n" % os.path.join(project, 'modules'))
# Hide output unless there is an error
p = subprocess.Popen(
[sys.executable, os.path.join(project, 'scripts', 'weboob-config'), 'update'],
env=env,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
s = p.communicate()
if p.returncode != 0:
print s[0]
sys.exit(p.returncode)
os.execvpe(
sys.executable,
['-Wall', os.path.join(project, 'scripts', script)] + args,
env)

10
tools/local_run.sh Executable file
View file

@ -0,0 +1,10 @@
#!/bin/sh
set -e
if [ -z "${PYTHON}" ]; then
which python >/dev/null 2>&1 && PYTHON=$(which python)
which python2 >/dev/null 2>&1 && PYTHON=$(which python2)
which python2.7 >/dev/null 2>&1 && PYTHON=$(which python2.7)
fi
exec "${PYTHON}" "$(dirname $0)/local_run.py" "$@"