aboutsummaryrefslogtreecommitdiff
blob: 35584a79086905a6f28ff67a74bd9879a5b475de (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
#!/usr/bin/env python

"""Wrapper script that runs a pkgcore script from sys.path."""

import os.path as osp
import sys

if __name__ == '__main__':
    try:
        from snakeoil import modules
        from pkgcore.util import commandline
    except ImportError:
        sys.stderr.write('Cannot import pkgcore!\n')
        sys.stderr.write('Verify it is 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)

    name = osp.basename(sys.argv[0]).replace("-", "_")
    try:
        script = modules.load_module('pkgcore.scripts.%s' % (name,))
    except modules.FailedImport:
        sys.stderr.write('Cannot load script %s.\n' % (name,))
        if '--debug' in sys.argv:
            raise
        sys.stderr.write('Add --debug to the commandline for a traceback.\n')
        sys.exit(1)
    subcommands = getattr(script, 'argparser', None)
    commandline.main(subcommands)