Mercurial > treepkg
changeset 88:3ae54f99db26
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.
author | Bernhard Herzog <bh@intevation.de> |
---|---|
date | Tue, 11 Sep 2007 13:46:53 +0000 (2007-09-11) |
parents | 08d8ffd40f27 |
children | 3caf4a5ecbf0 |
files | test/test_packager.py treepkg/packager.py treepkg/util.py |
diffstat | 3 files changed, 79 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/test/test_packager.py Tue Sep 11 10:05:15 2007 +0000 +++ b/test/test_packager.py Tue Sep 11 13:46:53 2007 +0000 @@ -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"]])
--- a/treepkg/packager.py Tue Sep 11 10:05:15 2007 +0000 +++ b/treepkg/packager.py Tue Sep 11 13:46:53 2007 +0000 @@ -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)
--- a/treepkg/util.py Tue Sep 11 10:05:15 2007 +0000 +++ b/treepkg/util.py Tue Sep 11 13:46:53 2007 +0000 @@ -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().