aboutsummaryrefslogtreecommitdiff
blob: ecbc3ce764dba1a73233686844d027383c8c3f5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python

"""Wrapper script that messes with sys.path and runs scripts.

This should only be run from inside the "bin" subdir of a pkgcore
checkout or unpacked tarball. It adds the parent of that "bin" dir to
sys.path unconditionally.
"""

from importlib import import_module
import os
import sys

sys.path.insert(1, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

if __name__ == '__main__':
    try:
        from pkgcore.util import commandline
        name = os.path.basename(sys.argv[0]).replace("-", "_")
        script = import_module('pkgcore.scripts.%s' % (name,))
    except ImportError as e:
        sys.stderr.write(str(e) + '!\n')
        sys.stderr.write(
            'Verify that snakeoil and pkgcore are properly installed '
            'and/or PYTHONPATH is set correctly for python %s.\n' %
            (".".join(map(str, sys.version_info[:3])),))
        if '--debug' in sys.argv:
            raise
        sys.stderr.write('Add --debug to the commandline for a traceback.\n')
        sys.exit(1)

    os.environ.update({
        'PKGCORE_SCRIPT_PATH': os.path.dirname(os.path.abspath(__file__)),
        'PKGCORE_CONFIG_PATH': os.path.join(
            os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'config'),
    })
    subcommands = getattr(script, 'argparser', None)
    commandline.main(subcommands)