bh@89: #! /usr/bin/python2.4 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@89: parser.set_defaults(binary=False, source=False) 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@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) bh@246: revision = int(split_revision[0]) bh@246: if len(split_revision) == 1: bh@246: rulesrev = None bh@246: else: bh@246: rulesrev = int(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@89: def list_track_packages(track, revision, 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@246: if main_rev is None: bh@89: revpkg = revisions[-1] bh@89: else: bh@246: # iterate in reverse, so that we pick up the newest revision bh@246: # packager with the desired revision first if rules_rev is None bh@246: for revpkg in revisions[::-1]: bh@246: if revpkg.revision == main_rev: bh@246: if rules_rev is None or revpkg.rules_revision == rules_rev: bh@246: break bh@89: else: bh@89: revpkg = None bh@89: bh@89: if revpkg is not None: 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: else: bh@248: print >>sys.stderr, "No revision", format_revision(main_rev, rules_rev) bh@89: sys.exit(1) bh@89: bh@89: def list_packages(config_file, trackname, revision, 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@199: list_track_packages(track, revision, 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@89: source=options.source, binary=options.binary) bh@89: bh@89: main()