[Treepkg-commits] r13 - in trunk: test treepkg

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Sep 11 15:46:53 CEST 2007


Author: bh
Date: 2007-09-11 15:46:53 +0200 (Tue, 11 Sep 2007)
New Revision: 13

Modified:
   trunk/test/test_packager.py
   trunk/treepkg/packager.py
   trunk/treepkg/util.py
Log:
Add methods RevisionPackager.list_source_files and
RevisionPackager.list_binary_files to list the binary and source files
of a revision.  Also add corresponding tests.


Modified: trunk/test/test_packager.py
===================================================================
--- trunk/test/test_packager.py	2007-09-11 10:05:15 UTC (rev 12)
+++ trunk/test/test_packager.py	2007-09-11 13:46:53 UTC (rev 13)
@@ -172,3 +172,65 @@
                                ("binary", [])])])])
         track = PackageTrack("testtrack", self.trackdir, "", "", "", "", "")
         self.assertEquals(track.last_packaged_revision(), 704195)
+
+
+class TestRevisionPackager(unittest.TestCase, FileTestMixin):
+
+    def setUp(self):
+        self.trackdir = self.create_temp_dir(self.id() + "-track")
+
+    def test_list_source_files(self):
+        # Note: The revisions in the pkg dir are not ordered so that we
+        # can check whether get_revision_numbers returns a sorted list
+        # of revisions
+        self.create_files(self.trackdir,
+                          [("pkg",
+                            [("704195-1",
+                              [("status",
+                                ("TreePackagerStatus 0.0\n"
+                                 "status: binary_package_created\n"
+                                 "start: 2007-09-10 17:16:48\n"
+                                 "stop: 2007-09-11 00:07:36\n")),
+                               ("src", [("test_1.0.orig.tar.gz", ""),
+                                        ("test_1.0-1.diff.gz", ""),
+                                        ("test_1.0-1.dsc", "")]),
+                               ("binary", [])]),
+                             ("702432-1",
+                              [("status", ""),
+                               ("src", []),
+                               ("binary", [])])])])
+        track = PackageTrack("testtrack", self.trackdir, "", "", "", "", "")
+        revpkg = RevisionPackager(track, 704195)
+        srcdir = os.path.join(self.trackdir, "pkg", "704195-1", "src")
+        self.assertEquals(revpkg.list_source_files(),
+                          [os.path.join(srcdir, filename)
+                           for filename in ["test_1.0-1.diff.gz",
+                                            "test_1.0-1.dsc",
+                                            "test_1.0.orig.tar.gz"]])
+
+    def test_list_binary_files(self):
+        # Note: The revisions in the pkg dir are not ordered so that we
+        # can check whether get_revision_numbers returns a sorted list
+        # of revisions
+        self.create_files(self.trackdir,
+                          [("pkg",
+                            [("704195-1",
+                              [("status",
+                                ("TreePackagerStatus 0.0\n"
+                                 "status: binary_package_created\n"
+                                 "start: 2007-09-10 17:16:48\n"
+                                 "stop: 2007-09-11 00:07:36\n")),
+                               ("src", []),
+                               ("binary", [("test_1.0-1_i386.deb", ""),
+                                           ("test_1.0-1_i386.changes", "")])]),
+                             ("702432-1",
+                              [("status", ""),
+                               ("src", []),
+                               ("binary", [])])])])
+        track = PackageTrack("testtrack", self.trackdir, "", "", "", "", "")
+        revpkg = RevisionPackager(track, 704195)
+        srcdir = os.path.join(self.trackdir, "pkg", "704195-1", "binary")
+        self.assertEquals(revpkg.list_binary_files(),
+                          [os.path.join(srcdir, filename)
+                           for filename in ["test_1.0-1_i386.changes",
+                                            "test_1.0-1_i386.deb"]])

Modified: trunk/treepkg/packager.py
===================================================================
--- trunk/treepkg/packager.py	2007-09-11 10:05:15 UTC (rev 12)
+++ trunk/treepkg/packager.py	2007-09-11 13:46:53 UTC (rev 13)
@@ -229,6 +229,20 @@
     def has_build_log(self):
         return os.path.exists(self.build_log)
 
+    def list_source_files(self):
+        """Returns a list with the names of the files of the source package.
+        The implementation assumes that all files in self.src_dir belong
+        to the source package.
+        """
+        return sorted(util.listdir_abs(self.src_dir))
+
+    def list_binary_files(self):
+        """Returns a list with the names of the files of the binary packages.
+        The implementation assumes that all files in self.binary_dir belong
+        to the binary packages.
+        """
+        return sorted(util.listdir_abs(self.binary_dir))
+
     def package(self):
         try:
             util.ensure_directory(self.work_dir)

Modified: trunk/treepkg/util.py
===================================================================
--- trunk/treepkg/util.py	2007-09-11 10:05:15 UTC (rev 12)
+++ trunk/treepkg/util.py	2007-09-11 13:46:53 UTC (rev 13)
@@ -50,6 +50,9 @@
     if not os.path.isdir(directory):
         os.makedirs(directory)
 
+def listdir_abs(directory):
+    """Like os.listdir, but returns a list of absolute pathnames"""
+    return [os.path.join(directory, d) for d in os.listdir(directory)]
 
 def copytree(src, dst, symlinks=False):
     """Recursively copy a directory tree using copy2().



More information about the Treepkg-commits mailing list