| 1 | #!/usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | # Copyright 2007 Charlie Shepherd |
|---|
| 4 | |
|---|
| 5 | import sys |
|---|
| 6 | |
|---|
| 7 | try: |
|---|
| 8 | from pkgcore.util import commandline |
|---|
| 9 | from pkgcore.util.repo_utils import get_raw_repos, get_virtual_repos |
|---|
| 10 | except ImportError: |
|---|
| 11 | print >> sys.stderr, 'Cannot import pkgcore!' |
|---|
| 12 | print >> sys.stderr, 'Verify it is properly installed and/or ' \ |
|---|
| 13 | 'PYTHONPATH is set correctly.' |
|---|
| 14 | print >> sys.stderr, 'Add --debug to the commandline for a traceback.' |
|---|
| 15 | if '--debug' in sys.argv: |
|---|
| 16 | raise |
|---|
| 17 | sys.exit(1) |
|---|
| 18 | |
|---|
| 19 | class OptionParser(commandline.OptionParser): |
|---|
| 20 | |
|---|
| 21 | def __init__(self, **kwargs): |
|---|
| 22 | commandline.OptionParser.__init__( |
|---|
| 23 | self, description=__doc__, usage='%prog [options]', |
|---|
| 24 | **kwargs) |
|---|
| 25 | self.add_option("--repo", "-r", action='callback', type='string', |
|---|
| 26 | callback=commandline.config_callback, callback_args=('repo',), |
|---|
| 27 | help='repo to give info about (default from domain if omitted)') |
|---|
| 28 | |
|---|
| 29 | def check_values(self, values, args): |
|---|
| 30 | values, args = commandline.OptionParser.check_values( |
|---|
| 31 | self, values, args) |
|---|
| 32 | |
|---|
| 33 | if args: self.error("This script takes no arguments") |
|---|
| 34 | |
|---|
| 35 | # Get repo(s) to operate on. |
|---|
| 36 | if values.repo: |
|---|
| 37 | repos = (values.repo,) |
|---|
| 38 | else: |
|---|
| 39 | repos = values.config.get_default('domain').repos |
|---|
| 40 | values.repos = get_virtual_repos(get_raw_repos(repos), False) |
|---|
| 41 | |
|---|
| 42 | return values, () |
|---|
| 43 | |
|---|
| 44 | def main(options, out, err): |
|---|
| 45 | for repo in options.repos: |
|---|
| 46 | out.write("Repo ID: %s" % repo.repo_id) |
|---|
| 47 | location = getattr(repo, "location", None) |
|---|
| 48 | if location: |
|---|
| 49 | out.write("Repo location: %s" % location) |
|---|
| 50 | else: |
|---|
| 51 | out.write("Repo has no on-disk location") |
|---|
| 52 | out.write("%d packages" % len(repo.versions)) |
|---|
| 53 | out.write("%d categories" % len(repo.packages)) |
|---|
| 54 | out.write() |
|---|
| 55 | |
|---|
| 56 | if __name__ == '__main__': |
|---|
| 57 | commandline.main({None: (OptionParser, main)}) |
|---|