comparison 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
comparison
equal deleted inserted replaced
252:2e0b373414b8 253:7d932fac1055
28 " If not given, files of all tracks are listed.")) 28 " If not given, files of all tracks are listed."))
29 parser.add_option("--source", action="store_true", 29 parser.add_option("--source", action="store_true",
30 help=("List source packages")) 30 help=("List source packages"))
31 parser.add_option("--binary", action="store_true", 31 parser.add_option("--binary", action="store_true",
32 help=("List binary packages")) 32 help=("List binary packages"))
33 parser.add_option("--newest", type="int",
34 help=("List binary packages"))
33 return parser.parse_args() 35 return parser.parse_args()
34 36
35 def parse_revision(raw_revision): 37 def parse_revision(raw_revision):
36 if raw_revision is None: 38 if raw_revision is None:
37 return None, None 39 return None, None
53 if rules_rev is not None: 55 if rules_rev is not None:
54 formatted += "-" + str(rules_rev) 56 formatted += "-" + str(rules_rev)
55 return formatted 57 return formatted
56 58
57 59
58 def list_track_packages(track, revision, source, binary): 60 def list_track_packages(track, revision, num_newest, source, binary):
59 main_rev, rules_rev = revision 61 main_rev, rules_rev = revision
60 62
61 revisions = track.get_revisions() 63 revisions = track.get_revisions()
62 if not revisions and main_rev is None: 64 if not revisions and main_rev is None:
63 return 65 return
64 66
65 revisions = sorted(revisions, key=lambda r: r.status.start, reverse=True) 67 revisions = sorted(revisions, key=lambda r: r.status.start, reverse=True)
66 68
69 candidates = []
70
67 if main_rev is None: 71 if main_rev is None:
68 filtered = [revpkg for revpkg in revisions 72 candidates = [revpkg for revpkg in revisions
69 if revpkg.status.status.finished 73 if revpkg.status.status.finished
70 and not revpkg.status.status.error] 74 and not revpkg.status.status.error]
71 if filtered: 75 if num_newest is None:
72 revpkg = filtered[0] 76 num_newest = 1
73 else: 77 candidates = candidates[:num_newest]
74 revpkg = None
75 else: 78 else:
76 # iterate in reverse, so that we pick up the newest revision
77 # packager with the desired revision first if rules_rev is None
78 for revpkg in revisions: 79 for revpkg in revisions:
79 if revpkg.revision == main_rev: 80 if revpkg.revision == main_rev:
80 if rules_rev is None or revpkg.rules_revision == rules_rev: 81 if rules_rev is None or revpkg.rules_revision == rules_rev:
82 candidates = [revpkg]
81 break 83 break
82 else: 84 else:
83 revpkg = None 85 print >>sys.stderr, "No revision", format_revision(main_rev,
86 rules_rev)
87 sys.exit(1)
84 88
85 if revpkg is not None: 89 for revpkg in candidates:
86 if source: 90 if source:
87 for filename in revpkg.list_source_files(): 91 for filename in revpkg.list_source_files():
88 print filename 92 print filename
89 if binary: 93 if binary:
90 for filename in revpkg.list_binary_files(): 94 for filename in revpkg.list_binary_files():
91 print filename 95 print filename
92 else:
93 print >>sys.stderr, "No revision", format_revision(main_rev, rules_rev)
94 sys.exit(1)
95 96
96 def list_packages(config_file, trackname, revision, source, binary): 97 def list_packages(config_file, trackname, revision, num_newest, source, binary):
97 group = get_packager_group(config_file) 98 group = get_packager_group(config_file)
98 tracks = group.get_package_tracks() 99 tracks = group.get_package_tracks()
99 if trackname is not None: 100 if trackname is not None:
100 tracks = [track for track in tracks if track.name == trackname] 101 tracks = [track for track in tracks if track.name == trackname]
101 if not tracks: 102 if not tracks:
102 print >>sys.stderr, "no track named", trackname 103 print >>sys.stderr, "no track named", trackname
103 sys.exit(1) 104 sys.exit(1)
104 for track in tracks: 105 for track in tracks:
105 list_track_packages(track, revision, source, binary) 106 list_track_packages(track, revision, num_newest, source, binary)
106 107
107 def main(): 108 def main():
108 options, args = parse_commandline() 109 options, args = parse_commandline()
109 options.revision = parse_revision(options.revision) 110 options.revision = parse_revision(options.revision)
110 list_packages(options.config_file, options.track, options.revision, 111 list_packages(options.config_file, options.track, options.revision,
112 num_newest=options.newest,
111 source=options.source, binary=options.binary) 113 source=options.source, binary=options.binary)
112 114
113 main() 115 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)