comparison 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
comparison
equal deleted inserted replaced
245:21da92cea416 246:59e2d8e26635
1 #! /usr/bin/python2.4 1 #! /usr/bin/python2.4
2 # Copyright (C) 2007, 2008 by Intevation GmbH 2 # Copyright (C) 2007, 2008, 2009 by Intevation GmbH
3 # Authors: 3 # Authors:
4 # Bernhard Herzog <bh@intevation.de> 4 # Bernhard Herzog <bh@intevation.de>
5 # 5 #
6 # This program is free software under the GPL (>=v2) 6 # This program is free software under the GPL (>=v2)
7 # Read the file COPYING coming with the software for details. 7 # Read the file COPYING coming with the software for details.
15 from treepkg.report import get_packager_group 15 from treepkg.report import get_packager_group
16 16
17 def parse_commandline(): 17 def parse_commandline():
18 parser = create_parser() 18 parser = create_parser()
19 parser.set_defaults(binary=False, source=False) 19 parser.set_defaults(binary=False, source=False)
20 parser.add_option("--revision", type="int", 20 parser.add_option("--revision",
21 help=("The revision whose files are to be listed." 21 help=("The revision whose files are to be listed."
22 " If not given, the latest revision is used")) 22 " If not given, the latest revision is used."
23 " The value may be given as REV-RULESREV to specify"
24 " both the main source revision and the revision of"
25 " the packaging rules"))
23 parser.add_option("--track", 26 parser.add_option("--track",
24 help=("The package track whose files are to be listed." 27 help=("The package track whose files are to be listed."
25 " If not given, files of all tracks are listed.")) 28 " If not given, files of all tracks are listed."))
26 parser.add_option("--source", action="store_true", 29 parser.add_option("--source", action="store_true",
27 help=("List source packages")) 30 help=("List source packages"))
28 parser.add_option("--binary", action="store_true", 31 parser.add_option("--binary", action="store_true",
29 help=("List binary packages")) 32 help=("List binary packages"))
30 return parser.parse_args() 33 return parser.parse_args()
31 34
35 def parse_revision(raw_revision):
36 if raw_revision is None:
37 return None, None
38
39 split_revision = raw_revision.split("-")
40 if len(split_revision) > 2:
41 raise ValueError("Cannot parse revision %r; too many '-' signs"
42 % raw_revision)
43 revision = int(split_revision[0])
44 if len(split_revision) == 1:
45 rulesrev = None
46 else:
47 rulesrev = int(split_revision[1])
48
49 return revision, rulesrev
50
32 51
33 def list_track_packages(track, revision, source, binary): 52 def list_track_packages(track, revision, source, binary):
53 main_rev, rules_rev = revision
54
34 revisions = track.get_revisions() 55 revisions = track.get_revisions()
35 if not revisions: 56 if not revisions:
36 print >>sys.stderr, "No revisions have been packaged" 57 print >>sys.stderr, "No revisions have been packaged"
37 sys.exit(1) 58 sys.exit(1)
38 59
39 if revision is None: 60 if main_rev is None:
40 revpkg = revisions[-1] 61 revpkg = revisions[-1]
41 else: 62 else:
42 for revpkg in revisions: 63 # iterate in reverse, so that we pick up the newest revision
43 if revpkg.revision == revision: 64 # packager with the desired revision first if rules_rev is None
44 break 65 for revpkg in revisions[::-1]:
66 if revpkg.revision == main_rev:
67 if rules_rev is None or revpkg.rules_revision == rules_rev:
68 break
45 else: 69 else:
46 revpkg = None 70 revpkg = None
47 71
48 if revpkg is not None: 72 if revpkg is not None:
49 if source: 73 if source:
67 for track in tracks: 91 for track in tracks:
68 list_track_packages(track, revision, source, binary) 92 list_track_packages(track, revision, source, binary)
69 93
70 def main(): 94 def main():
71 options, args = parse_commandline() 95 options, args = parse_commandline()
96 options.revision = parse_revision(options.revision)
72 list_packages(options.config_file, options.track, options.revision, 97 list_packages(options.config_file, options.track, options.revision,
73 source=options.source, binary=options.binary) 98 source=options.source, binary=options.binary)
74 99
75 main() 100 main()
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)