local_install.py 1.9 KB
Newer Older
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3 4
from __future__ import print_function

5
import os
6 7 8
import subprocess
import sys

9 10 11 12 13 14
if '--local-modules' in sys.argv:
    local_modules = True
    sys.argv.remove('--local-modules')
else:
    local_modules = False

15 16
print("Weboob local installer")
print()
17

18
if len(sys.argv) < 2:
19 20 21
    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()
22
    print("Usage: %s DESTINATION" % sys.argv[0])
23
    print()
24 25
    print("Error: Please provide a destination, "
          "for example ‘%s/bin’" % os.getenv('HOME'), file=sys.stderr)
26 27 28 29
    sys.exit(1)
else:
    dest = os.path.expanduser(sys.argv[1])

30
print("Installing weboob applications into ‘%s’." % dest)
31

32 33 34 35 36 37 38 39 40 41 42 43 44

if local_modules:
    sourceslist = os.path.join(
        os.environ.get('XDG_CONFIG_HOME', os.path.join(os.path.expanduser('~'), '.config')),
        'weboob', 'sources.list')
    if not os.path.isdir(os.path.dirname(sourceslist)):
        os.makedirs(os.path.dirname(sourceslist))
    if not os.path.exists(sourceslist):
        with open(sourceslist, 'w') as f:
            f.write('file://' + os.path.realpath(
                os.path.join(os.path.dirname(__file__), os.pardir, 'modules')
            ))

45 46
subprocess.check_call(
    [sys.executable, 'setup.py',
47
        'install', '--user', '--install-scripts=%s' % dest] + sys.argv[2:],
48 49
    cwd=os.path.join(os.path.dirname(__file__), os.pardir))

50
subprocess.call([sys.executable, os.path.join(dest, 'weboob-config'), 'update'])
51

52 53 54 55 56 57 58 59
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.")