changeset 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 21da92cea416
children 55337021fe5b
files bin/listpackages.py test/test_listpackages.py
diffstat 2 files changed, 270 insertions(+), 7 deletions(-) [+]
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)
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/test_listpackages.py	Fri Mar 06 19:21:56 2009 +0000
@@ -0,0 +1,238 @@
+# Copyright (C) 2009 by Intevation GmbH
+# Authors:
+# Bernhard Herzog <bh@intevation.de>
+#
+# This program is free software under the GPL (>=v2)
+# Read the file COPYING coming with the software for details.
+
+
+import sys
+import os
+import difflib
+import unittest
+
+from filesupport import FileTestMixin
+
+from treepkg.run import call, capture_output, SubprocessError
+
+
+def package_track_files(track, version, binaries, revisions):
+    src_templates = ["%s_%s.%%s%s" % (track, version, suffix)
+                     for suffix in [".orig.tar.gz", "-1.diff.gz", "-1.dsc"]]
+    bin_templates = ["%s_%s.%%s-1_i386.deb" % (basename, version)
+                     for basename in binaries]
+    return (track,
+            [("pkg", [("%s-%s" % (rev, rules_rev),
+                       [("status", "TreePackagerStatus 0.0\n"),
+                        ("src", [(template % (rev,), "")
+                                 for template in src_templates]),
+                        ("binary", [(template % (rev,), "")
+                                    for template in bin_templates])])
+                      for rev, rules_rev in revisions])])
+
+class ListPackagesTest(unittest.TestCase, FileTestMixin):
+
+    treepkg_cfg_template = """\
+[DEFAULT]
+tracks_dir: %(tracksdir)s
+root_cmd: true
+pbuilderrc:
+deb_email: packager@example.com
+deb_fullname: Sample Packager
+debrevision_prefix: treepkg
+handle_dependencies: False
+
+[treepkg]
+check_interval: 3600
+instructions_file:
+
+[pkg_kdepim]
+svn_url: svn://anonsvn.kde.org/home/kde/branches/kdepim/enterprise/kdepim
+base_dir: %%(tracks_dir)s/kdepim
+packager_class: recipes.kde_enterprise_3_5.kdepim
+
+[pkg_kdepimlibs]
+svn_url: svn://anonsvn.kde.org/home/kde/branches/kdepim/enterprise/kdepimlibs
+base_dir: %%(tracks_dir)s/kdepimlibs
+packager_class: recipes.kde_enterprise_3_5.kdepim
+"""
+
+    track_files = []
+
+    def setUp(self):
+        self.bindir = os.path.join(os.path.dirname(__file__),
+                                   os.pardir, "bin")
+        self.listpackages = os.path.join(self.bindir, "listpackages.py")
+        self.tracksdir = self.create_files("tracks", self.track_files)
+        config = self.treepkg_cfg_template % dict(tracksdir=self.tracksdir)
+        self.config_file = self.create_temp_file("treepkg.cfg", config)
+        self.base_command = [sys.executable, self.listpackages,
+                             "--config-file=" + self.config_file]
+
+    def run_command(self, extra_args, expected_exit_code=0):
+        cmd = self.base_command + list(extra_args)
+        try:
+            output = capture_output(cmd)
+        except SubprocessError, exc:
+            if expected_exit_code != exc.returncode:
+                raise
+            output = exc.output
+        return output
+
+    def check_cmd(self, args, expected):
+        expected_lines = [os.path.join(self.tracksdir, filename) + "\n"
+                          for filename in expected.splitlines()]
+        try:
+            output_lines = [line + "\n"
+                            for line in self.run_command(args).splitlines()]
+        except SubprocessError, exc:
+            print >>sys.stderr, "Unexpected output:", exc.output
+            raise
+
+        # the order of the listed packages doesn't matter, so sort the
+        # lists before comparing them
+        expected_lines.sort()
+        output_lines.sort()
+
+        if expected_lines != output_lines:
+            diff = difflib.unified_diff(expected_lines, output_lines,
+                                        "expected", "found")
+            raise self.failureException("\n" + "".join(diff))
+
+
+class TestListPackagesTrackNoRevision(ListPackagesTest):
+
+    track_files = [package_track_files("kdepim", "1.0.1",
+                                       ["kdepim", "kleopatra"],
+                                       [(704195, 31), (702432, 47)])]
+
+    def test_listpackages_source(self):
+        self.check_cmd(["--track=kdepim", "--source"],
+                       """\
+kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.diff.gz
+kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.dsc
+kdepim/pkg/704195-31/src/kdepim_1.0.1.704195.orig.tar.gz
+""")
+
+    def test_listpackages_binary(self):
+        self.check_cmd(["--track=kdepim", "--binary"],
+                       """\
+kdepim/pkg/704195-31/binary/kdepim_1.0.1.704195-1_i386.deb
+kdepim/pkg/704195-31/binary/kleopatra_1.0.1.704195-1_i386.deb
+""")
+
+
+class TestListPackagesNoTrackNoRevision(ListPackagesTest):
+
+    track_files = [package_track_files("kdepim", "1.0.1",
+                                       ["kdepim", "kleopatra"],
+                                       [(704195, 31), (702432, 47)]),
+                   package_track_files("kdepimlibs", "1.0.1",
+                                       ["kdepimlibs"],
+                                       [(803691, 4321), (803692, 4322)]),
+                   ]
+
+    def test_listpackages_source(self):
+        self.check_cmd(["--source"],
+                       """\
+kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.diff.gz
+kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.dsc
+kdepim/pkg/704195-31/src/kdepim_1.0.1.704195.orig.tar.gz
+kdepimlibs/pkg/803692-4322/src/kdepimlibs_1.0.1.803692-1.diff.gz
+kdepimlibs/pkg/803692-4322/src/kdepimlibs_1.0.1.803692-1.dsc
+kdepimlibs/pkg/803692-4322/src/kdepimlibs_1.0.1.803692.orig.tar.gz""")
+
+    def test_listpackages_binary(self):
+        self.check_cmd(["--binary"],
+                       """\
+kdepim/pkg/704195-31/binary/kdepim_1.0.1.704195-1_i386.deb
+kdepim/pkg/704195-31/binary/kleopatra_1.0.1.704195-1_i386.deb
+kdepimlibs/pkg/803692-4322/binary/kdepimlibs_1.0.1.803692-1_i386.deb""")
+
+
+class TestListPackagesTrackRevision(ListPackagesTest):
+
+    track_files = [package_track_files("kdepim", "1.0.1",
+                                       ["kdepim", "kleopatra"],
+                                       [(704195, 31), (702432, 47)]),
+                   package_track_files("kdepimlibs", "1.0.1",
+                                       ["kdepimlibs"],
+                                       [(803691, 4321), (803692, 4322)]),
+                   ]
+
+    def test_listpackages_source(self):
+        self.check_cmd(["--source", "--track=kdepim", "--revision=702432"],
+                       """\
+kdepim/pkg/702432-47/src/kdepim_1.0.1.702432-1.diff.gz
+kdepim/pkg/702432-47/src/kdepim_1.0.1.702432-1.dsc
+kdepim/pkg/702432-47/src/kdepim_1.0.1.702432.orig.tar.gz""")
+
+    def test_listpackages_binary(self):
+        self.check_cmd(["--binary", "--track=kdepim", "--revision=702432"],
+                       """\
+kdepim/pkg/702432-47/binary/kdepim_1.0.1.702432-1_i386.deb
+kdepim/pkg/702432-47/binary/kleopatra_1.0.1.702432-1_i386.deb""")
+
+
+
+class TestListPackagesMultipleRulesRevisions(ListPackagesTest):
+
+    track_files = [package_track_files("kdepim", "1.0.1",
+                                       ["kdepim", "kleopatra"],
+                                       [(704195, 31), (704195, 33),
+                                        (702432, 47)]),
+                   package_track_files("kdepimlibs", "1.0.1",
+                                       ["kdepimlibs"],
+                                       [(803691, 4321), (803692, 4322)]),
+                   ]
+
+    def test_listpackages_source_no_rev(self):
+        self.check_cmd(["--source", "--track=kdepim"],
+                       """\
+kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.diff.gz
+kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.dsc
+kdepim/pkg/704195-33/src/kdepim_1.0.1.704195.orig.tar.gz""")
+
+    def test_listpackages_binary_no_rev(self):
+        self.check_cmd(["--binary", "--track=kdepim"],
+                       """\
+kdepim/pkg/704195-33/binary/kdepim_1.0.1.704195-1_i386.deb
+kdepim/pkg/704195-33/binary/kleopatra_1.0.1.704195-1_i386.deb""")
+
+    def test_listpackages_source_and_binary_no_rev(self):
+        self.check_cmd(["--source", "--track=kdepim", "--binary"],
+                       """\
+kdepim/pkg/704195-33/binary/kdepim_1.0.1.704195-1_i386.deb
+kdepim/pkg/704195-33/binary/kleopatra_1.0.1.704195-1_i386.deb
+kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.diff.gz
+kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.dsc
+kdepim/pkg/704195-33/src/kdepim_1.0.1.704195.orig.tar.gz
+""")
+
+    def test_listpackages_source_no_rulesrev(self):
+        self.check_cmd(["--source", "--track=kdepim", "--revision=704195"],
+                       """\
+kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.diff.gz
+kdepim/pkg/704195-33/src/kdepim_1.0.1.704195-1.dsc
+kdepim/pkg/704195-33/src/kdepim_1.0.1.704195.orig.tar.gz""")
+
+    def test_listpackages_binary_no_rulesrev(self):
+        self.check_cmd(["--binary", "--track=kdepim", "--revision=704195"],
+                       """\
+kdepim/pkg/704195-33/binary/kdepim_1.0.1.704195-1_i386.deb
+kdepim/pkg/704195-33/binary/kleopatra_1.0.1.704195-1_i386.deb""")
+
+    def test_listpackages_source_rulesrev(self):
+        self.check_cmd(["--source", "--track=kdepim", "--revision=704195-31"],
+                       """\
+kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.diff.gz
+kdepim/pkg/704195-31/src/kdepim_1.0.1.704195-1.dsc
+kdepim/pkg/704195-31/src/kdepim_1.0.1.704195.orig.tar.gz""")
+
+    def test_listpackages_binary_rulesrev(self):
+        self.check_cmd(["--binary", "--track=kdepim", "--revision=704195-31"],
+                       """\
+kdepim/pkg/704195-31/binary/kdepim_1.0.1.704195-1_i386.deb
+kdepim/pkg/704195-31/binary/kleopatra_1.0.1.704195-1_i386.deb""")
+
+
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)