diff bin/listpackages.py @ 246:59e2d8e26635

Extend --revision parameter of bin/listpackages.py to accept rules revision too. Add test cases for listpackages.
author Bernhard Herzog <bh@intevation.de>
date Fri, 06 Mar 2009 19:21:56 +0000
parents 24d119c27150
children 5dd710b167d2
line wrap: on
line diff
--- a/bin/listpackages.py	Tue Feb 24 18:28:25 2009 +0000
+++ b/bin/listpackages.py	Fri Mar 06 19:21:56 2009 +0000
@@ -1,5 +1,5 @@
 #! /usr/bin/python2.4
-# Copyright (C) 2007, 2008 by Intevation GmbH
+# Copyright (C) 2007, 2008, 2009 by Intevation GmbH
 # Authors:
 # Bernhard Herzog <bh@intevation.de>
 #
@@ -17,9 +17,12 @@
 def parse_commandline():
     parser = create_parser()
     parser.set_defaults(binary=False, source=False)
-    parser.add_option("--revision", type="int",
+    parser.add_option("--revision",
                       help=("The revision whose files are to be listed."
-                            " If not given, the latest revision is used"))
+                            " 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."))
@@ -29,19 +32,40 @@
                       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 list_track_packages(track, revision, source, binary):
+    main_rev, rules_rev = revision
+
     revisions = track.get_revisions()
     if not revisions:
         print >>sys.stderr, "No revisions have been packaged"
         sys.exit(1)
 
-    if revision is None:
+    if main_rev is None:
         revpkg = revisions[-1]
     else:
-        for revpkg in revisions:
-            if revpkg.revision == revision:
-                break
+        # 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[::-1]:
+            if revpkg.revision == main_rev:
+                if rules_rev is None or revpkg.rules_revision == rules_rev:
+                    break
         else:
             revpkg = None
 
@@ -69,6 +93,7 @@
 
 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)
 
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)