diff bin/listpackages.py @ 253:7d932fac1055

Add --newest=N option to listpackages to get more than one newest revision. Add corresponding tests.
author Bernhard Herzog <bh@intevation.de>
date Tue, 14 Apr 2009 12:45:12 +0000
parents 2e0b373414b8
children b1776fc8e24a
line wrap: on
line diff
--- a/bin/listpackages.py	Tue Apr 14 09:41:59 2009 +0000
+++ b/bin/listpackages.py	Tue Apr 14 12:45:12 2009 +0000
@@ -30,6 +30,8 @@
                       help=("List source packages"))
     parser.add_option("--binary", action="store_true",
                       help=("List binary packages"))
+    parser.add_option("--newest", type="int",
+                      help=("List binary packages"))
     return parser.parse_args()
 
 def parse_revision(raw_revision):
@@ -55,7 +57,7 @@
     return formatted
 
 
-def list_track_packages(track, revision, source, binary):
+def list_track_packages(track, revision, num_newest, source, binary):
     main_rev, rules_rev = revision
 
     revisions = track.get_revisions()
@@ -64,36 +66,35 @@
 
     revisions = sorted(revisions, key=lambda r: r.status.start, reverse=True)
 
+    candidates = []
+
     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
+        candidates = [revpkg for revpkg in revisions
+                      if revpkg.status.status.finished
+                         and not revpkg.status.status.error]
+        if num_newest is None:
+            num_newest = 1
+        candidates = candidates[:num_newest]
     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:
+                    candidates = [revpkg]
                     break
         else:
-            revpkg = None
+            print >>sys.stderr, "No revision", format_revision(main_rev,
+                                                               rules_rev)
+            sys.exit(1)
 
-    if revpkg is not None:
+    for revpkg in candidates:
         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):
+def list_packages(config_file, trackname, revision, num_newest, source, binary):
     group = get_packager_group(config_file)
     tracks = group.get_package_tracks()
     if trackname is not None:
@@ -102,12 +103,13 @@
             print >>sys.stderr, "no track named", trackname
             sys.exit(1)
     for track in tracks:
-        list_track_packages(track, revision, source, binary)
+        list_track_packages(track, revision, num_newest, source, binary)
 
 def main():
     options, args = parse_commandline()
     options.revision = parse_revision(options.revision)
     list_packages(options.config_file, options.track, options.revision,
+                  num_newest=options.newest,
                   source=options.source, binary=options.binary)
 
 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)