Mercurial > treepkg
view bin/listpackages.py @ 252:2e0b373414b8
Make bin/listpackages.py ignore revisions that have not been built
successfully, unless the revision has been explicitly selected. Add a
test case for this.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Tue, 14 Apr 2009 09:41:59 +0000 |
parents | 243f206574cb |
children | 7d932fac1055 |
line wrap: on
line source
#! /usr/bin/python2.4 # Copyright (C) 2007, 2008, 2009 by Intevation GmbH # Authors: # Bernhard Herzog <bh@intevation.de> # # This program is free software under the GPL (>=v2) # Read the file COPYING coming with the software for details. """List the absolute filenames of packages created by treepkg""" import sys import treepkgcmd from treepkg.options import create_parser from treepkg.report import get_packager_group def parse_commandline(): parser = create_parser() parser.set_defaults(binary=False, source=False) parser.add_option("--revision", help=("The revision whose files are to be listed." " If not given, the latest revision is used." " The value may be given as REV-RULESREV to specify" " both the main source revision and the revision of" " the packaging rules")) parser.add_option("--track", help=("The package track whose files are to be listed." " If not given, files of all tracks are listed.")) parser.add_option("--source", action="store_true", help=("List source packages")) parser.add_option("--binary", action="store_true", help=("List binary packages")) return parser.parse_args() def parse_revision(raw_revision): if raw_revision is None: return None, None split_revision = raw_revision.split("-") if len(split_revision) > 2: raise ValueError("Cannot parse revision %r; too many '-' signs" % raw_revision) revision = int(split_revision[0]) if len(split_revision) == 1: rulesrev = None else: rulesrev = int(split_revision[1]) return revision, rulesrev def format_revision(main_rev, rules_rev): formatted = str(main_rev) if rules_rev is not None: formatted += "-" + str(rules_rev) return formatted def list_track_packages(track, revision, source, binary): main_rev, rules_rev = revision revisions = track.get_revisions() if not revisions and main_rev is None: return revisions = sorted(revisions, key=lambda r: r.status.start, reverse=True) if main_rev is None: filtered = [revpkg for revpkg in revisions if revpkg.status.status.finished and not revpkg.status.status.error] if filtered: revpkg = filtered[0] else: revpkg = None else: # iterate in reverse, so that we pick up the newest revision # packager with the desired revision first if rules_rev is None for revpkg in revisions: if revpkg.revision == main_rev: if rules_rev is None or revpkg.rules_revision == rules_rev: break else: revpkg = None if revpkg is not None: if source: for filename in revpkg.list_source_files(): print filename if binary: for filename in revpkg.list_binary_files(): print filename else: print >>sys.stderr, "No revision", format_revision(main_rev, rules_rev) sys.exit(1) def list_packages(config_file, trackname, revision, source, binary): group = get_packager_group(config_file) tracks = group.get_package_tracks() if trackname is not None: tracks = [track for track in tracks if track.name == trackname] if not tracks: print >>sys.stderr, "no track named", trackname sys.exit(1) for track in tracks: list_track_packages(track, revision, source, binary) def main(): options, args = parse_commandline() options.revision = parse_revision(options.revision) list_packages(options.config_file, options.track, options.revision, source=options.source, binary=options.binary) main()