[Pkg-bazaar-commits] r123 ./bzr-builddeb/people/jdw/merge_upstream: Add a target_dir parameter to the repack_tarball function.
James Westby
jw+debian at jameswestby.net
Sun Jun 24 10:09:21 UTC 2007
------------------------------------------------------------
revno: 123
committer: James Westby <jw+debian at jameswestby.net>
branch nick: merge_upstream
timestamp: Sun 2007-06-24 11:09:21 +0100
message:
Add a target_dir parameter to the repack_tarball function.
If target_dir is specified then the directory will be created if it doesn't
exist, and the new_filename will be interpreted relative to it.
modified:
__init__.py
repack_tarball.py
tests/test_repack_tarball.py
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py 2007-06-22 16:04:56 +0000
+++ b/__init__.py 2007-06-24 10:09:21 +0000
@@ -43,7 +43,9 @@
from errors import (ChangedError,
StopBuild,
)
+from merge_upstream import merge_upstream
from properties import BuildProperties
+from repack_tarball import repack_tarball
from util import goto_branch, find_changelog, is_clean
dont_purge_opt = Option('dont-purge',
@@ -312,6 +314,7 @@
register_command(cmd_merge_upstream)
+
def test_suite():
from unittest import TestSuite
import tests
=== modified file 'repack_tarball.py'
--- a/repack_tarball.py 2007-06-23 18:15:14 +0000
+++ b/repack_tarball.py 2007-06-24 10:09:21 +0000
@@ -27,27 +27,42 @@
from bzrlib.errors import (NoSuchFile,
FileExists,
BzrCommandError,
+ NotADirectory,
)
-def repack_tarball(orig_name, new_name):
+def repack_tarball(orig_name, new_name, target_dir=None):
"""Repack the file/dir named to a .tar.gz with the chosen name.
This function takes a named file of either .tar.gz, .tar .tgz .tar.bz2
or .zip type, or a directory, and creates the file named in the second
argument in .tar.gz format.
+ If target_dir is specified then that directory will be created if it
+ doesn't exist, and the new_name will be interpreted relative to that
+ directory.
+
The source must exist, and the target cannot exist.
-
+
:param orig_name: the curent name of the file/dir
:type orig_name: string
:param new_name: the desired name of the tarball
:type new_name: string
+ :keyword target_dir: the directory to consider new_name relative to, and
+ will be created if non-extant.
+ :type target_dir: string
:return: None
:warning: .zip files are currently unsupported.
"""
if not os.path.exists(orig_name):
raise NoSuchFile(orig_name)
+ if target_dir is not None:
+ if not os.path.exists(target_dir):
+ os.mkdir(target_dir)
+ else:
+ if not os.path.isdir(target_dir):
+ raise NotADirectory(target_dir)
+ new_name = os.path.join(target_dir, new_name)
if os.path.exists(new_name):
raise FileExists(new_name)
if os.path.isdir(orig_name):
=== modified file 'tests/test_repack_tarball.py'
--- a/tests/test_repack_tarball.py 2007-06-23 10:31:23 +0000
+++ b/tests/test_repack_tarball.py 2007-06-24 10:09:21 +0000
@@ -23,6 +23,7 @@
from bzrlib.errors import (NoSuchFile,
FileExists,
+ NotADirectory,
)
from bzrlib.tests import TestCaseInTempDir
@@ -92,3 +93,32 @@
[self.basedir] +
[os.path.join(self.basedir, file) for file in self.files])
+ def test_repack_tarball_with_target_dir(self):
+ self.create_old_tarball()
+ target_dir = 'tarballs'
+ repack_tarball(self.old_tarball, self.new_tarball, target_dir=target_dir)
+ self.failUnlessExists(target_dir)
+ self.failUnlessExists(os.path.join(target_dir, self.new_tarball))
+ self.failUnlessExists(self.old_tarball)
+
+ def test_repack_tarball_with_target_dir_exists(self):
+ self.create_old_tarball()
+ target_dir = 'tarballs'
+ os.mkdir(target_dir)
+ repack_tarball(self.old_tarball, self.new_tarball, target_dir=target_dir)
+ self.failUnlessExists(target_dir)
+ self.failUnlessExists(os.path.join(target_dir, self.new_tarball))
+ self.failUnlessExists(self.old_tarball)
+ self.failIfExists(self.new_tarball)
+
+ def test_repack_tarball_with_target_dir_not_dir(self):
+ self.create_old_tarball()
+ target_dir = 'tarballs'
+ touch(target_dir)
+ self.assertRaises(NotADirectory, repack_tarball, self.old_tarball,
+ self.new_tarball, target_dir=target_dir)
+ self.failUnlessExists(self.old_tarball)
+ self.failIfExists(self.new_tarball)
+ self.failIfExists(os.path.join(target_dir, self.new_tarball))
+ self.failUnlessExists(target_dir)
+
More information about the Pkg-bazaar-commits
mailing list