| Line | |
|---|
| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | """Wrapper script that messes with sys.path and runs scripts. |
|---|
| 4 | |
|---|
| 5 | If it sees a ../pkgcore/__init__.py relative to its absolute location |
|---|
| 6 | it adds .. to sys.path. It then imports and runs pkgcore.scripts.<sys.argv[0]>. |
|---|
| 7 | """ |
|---|
| 8 | |
|---|
| 9 | import os.path as osp |
|---|
| 10 | import sys |
|---|
| 11 | |
|---|
| 12 | try: |
|---|
| 13 | from pkgcore.util import modules, commandline |
|---|
| 14 | except 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 | |
|---|
| 23 | if __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) |
|---|