| Line | |
|---|
| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | """Wrapper script that runs a pkgcore script from sys.path.""" |
|---|
| 4 | |
|---|
| 5 | import os.path as osp |
|---|
| 6 | import sys |
|---|
| 7 | |
|---|
| 8 | if __name__ == '__main__': |
|---|
| 9 | try: |
|---|
| 10 | from pkgcore.util import modules, commandline |
|---|
| 11 | except ImportError: |
|---|
| 12 | print >> sys.stderr, 'Cannot import pkgcore!' |
|---|
| 13 | print >> sys.stderr, 'Verify it is properly installed and/or ' \ |
|---|
| 14 | 'PYTHONPATH is set correctly.' |
|---|
| 15 | print >> sys.stderr, 'Add --debug to the commandline for a traceback.' |
|---|
| 16 | if '--debug' in sys.argv: |
|---|
| 17 | raise |
|---|
| 18 | sys.exit(1) |
|---|
| 19 | |
|---|
| 20 | name = osp.basename(sys.argv[0]) |
|---|
| 21 | try: |
|---|
| 22 | script = modules.load_module('pkgcore.scripts.%s' % (name,)) |
|---|
| 23 | except modules.FailedImport: |
|---|
| 24 | print >> sys.stderr, 'Cannot load script %s.' % (name,) |
|---|
| 25 | print >> sys.stderr, 'Add --debug to the commandline for a traceback.' |
|---|
| 26 | if '--debug' in sys.argv: |
|---|
| 27 | raise |
|---|
| 28 | sys.exit(1) |
|---|
| 29 | else: |
|---|
| 30 | subcommands = getattr(script, 'commandline_commands', None) |
|---|
| 31 | if subcommands is None: |
|---|
| 32 | subcommands = {None: (script.OptionParser, script.main)} |
|---|
| 33 | commandline.main(subcommands) |
|---|