root/releases/pkgcore/0.1/bin/pwrapper @ marienz%2540gentoo.org-20060915210029-7d703b8f5c9c0513

Revision marienz%2540gentoo.org-20060915210029-7d703b8f5c9c0513, 1.1 KB (checked in by Marien Zwart <marienz@…>, 2 years ago)

Make scripts testable.

  • Property executable set to True
Line 
1#!/usr/bin/env python
2
3"""Wrapper script that messes with sys.path and runs scripts.
4
5If it sees a ../pkgcore/__init__.py relative to its absolute location
6it adds .. to sys.path. It then imports and runs pkgcore.scripts.<sys.argv[0]>.
7"""
8
9import os.path as osp
10import sys
11
12try:
13    from pkgcore.util import modules, commandline
14except ImportError:
15    print >> sys.stderr, 'Cannot import pkgcore!'
16    print >> sys.stderr, 'Verify it is properly installed and/or ' \
17        'PYTHONPATH is set correctly.'
18    print >> sys.stderr, 'Add --debug to the commandline for a traceback.'
19    if '--debug' in sys.argv:
20        raise
21    sys.exit(1)
22
23if __name__ == '__main__':
24    name = osp.basename(sys.argv[0])
25    try:
26        script = modules.load_module('pkgcore.scripts.%s' % (name,))
27    except modules.FailedImport:
28        print >> sys.stderr, 'Cannot load script %s.' % (name,)
29        print >> sys.stderr, 'Add --debug to the commandline for a traceback.'
30        if '--debug' in sys.argv:
31            raise
32        sys.exit(1)
33    else:
34        commandline.main(script.OptionParser(), script.main)
Note: See TracBrowser for help on using the browser.