bh@287: #! /usr/bin/python bh@246: # Copyright (C) 2007, 2008, 2009 by Intevation GmbH bh@89: # Authors: bh@89: # Bernhard Herzog bh@89: # bh@89: # This program is free software under the GPL (>=v2) bh@89: # Read the file COPYING coming with the software for details. bh@89: bh@89: """List the absolute filenames of packages created by treepkg""" bh@89: bh@89: import sys bh@89: bh@89: import treepkgcmd bh@89: from treepkg.options import create_parser bh@89: from treepkg.report import get_packager_group bh@89: bh@89: def parse_commandline(): bh@89: parser = create_parser() bh@254: parser.set_defaults(binary=False, source=False, newest=1) bh@246: parser.add_option("--revision", bh@89: help=("The revision whose files are to be listed." bh@246: " If not given, the latest revision is used." bh@246: " The value may be given as REV-RULESREV to specify" bh@246: " both the main source revision and the revision of" bh@246: " the packaging rules")) bh@89: parser.add_option("--track", bh@199: help=("The package track whose files are to be listed." bh@199: " If not given, files of all tracks are listed.")) bh@89: parser.add_option("--source", action="store_true", bh@89: help=("List source packages")) bh@89: parser.add_option("--binary", action="store_true", bh@89: help=("List binary packages")) bh@253: parser.add_option("--newest", type="int", bh@254: help=("Number of newest revisions to list." bh@254: " Defaults to 1.")) bh@89: return parser.parse_args() bh@89: bh@246: def parse_revision(raw_revision): bh@246: if raw_revision is None: bh@246: return None, None bh@246: bh@246: split_revision = raw_revision.split("-") bh@246: if len(split_revision) > 2: bh@246: raise ValueError("Cannot parse revision %r; too many '-' signs" bh@246: % raw_revision) aheinecke@328: revision = split_revision[0] bh@246: if len(split_revision) == 1: bh@246: rulesrev = None bh@246: else: aheinecke@328: rulesrev = split_revision[1] bh@246: bh@246: return revision, rulesrev bh@246: bh@248: def format_revision(main_rev, rules_rev): bh@248: formatted = str(main_rev) bh@248: if rules_rev is not None: bh@248: formatted += "-" + str(rules_rev) bh@248: return formatted bh@248: bh@89: bh@253: def list_track_packages(track, revision, num_newest, source, binary): bh@246: main_rev, rules_rev = revision bh@246: bh@89: revisions = track.get_revisions() bh@248: if not revisions and main_rev is None: bh@248: return bh@89: bh@251: revisions = sorted(revisions, key=lambda r: r.status.start, reverse=True) bh@251: bh@253: candidates = [] bh@253: bh@246: if main_rev is None: bh@253: candidates = [revpkg for revpkg in revisions bh@253: if revpkg.status.status.finished bh@253: and not revpkg.status.status.error] bh@253: candidates = candidates[:num_newest] bh@89: else: bh@251: for revpkg in revisions: bh@246: if revpkg.revision == main_rev: bh@246: if rules_rev is None or revpkg.rules_revision == rules_rev: bh@253: candidates = [revpkg] bh@246: break bh@89: else: bh@253: print >>sys.stderr, "No revision", format_revision(main_rev, bh@253: rules_rev) bh@253: sys.exit(1) bh@89: bh@253: for revpkg in candidates: bh@89: if source: bh@89: for filename in revpkg.list_source_files(): bh@89: print filename bh@89: if binary: bh@89: for filename in revpkg.list_binary_files(): bh@89: print filename bh@89: bh@253: def list_packages(config_file, trackname, revision, num_newest, source, binary): bh@89: group = get_packager_group(config_file) bh@199: tracks = group.get_package_tracks() bh@199: if trackname is not None: bh@199: tracks = [track for track in tracks if track.name == trackname] bh@199: if not tracks: bh@199: print >>sys.stderr, "no track named", trackname bh@199: sys.exit(1) bh@199: for track in tracks: bh@253: list_track_packages(track, revision, num_newest, source, binary) bh@89: bh@89: def main(): bh@89: options, args = parse_commandline() bh@246: options.revision = parse_revision(options.revision) bh@89: list_packages(options.config_file, options.track, options.revision, bh@253: num_newest=options.newest, bh@89: source=options.source, binary=options.binary) bh@89: bh@89: main()