summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2011-07-25 17:40:11 +0200
committerGuido Günther <agx@sigxcpu.org>2011-07-25 21:22:30 +0200
commitf0ba62c753ff08fe6ad1e30108e9668d984adfd0 (patch)
treecdba968b06664c3ccaabfd3b9c50652db77742fe
parent33d5156335a6a602102d7387624e05729d46d5ff (diff)
Drop unpack_orig and tar_toplevel
-rw-r--r--gbp/deb.py62
-rwxr-xr-xgit-buildpackage12
-rwxr-xr-xgit-import-dsc12
-rwxr-xr-xgit-import-orig2
-rw-r--r--tests/02_test_import.py4
5 files changed, 44 insertions, 48 deletions
diff --git a/gbp/deb.py b/gbp/deb.py
index 806f2fc6..f88ff682 100644
--- a/gbp/deb.py
+++ b/gbp/deb.py
@@ -227,7 +227,7 @@ class UpstreamSource(object):
raise GbpError, "Filters must be a list"
self._unpack_archive(dir, filters)
- self.unpacked = tar_toplevel(dir)
+ self.unpacked = self._unpacked_toplevel(dir)
def _unpack_archive(self, dir, filters):
"""
@@ -235,12 +235,37 @@ class UpstreamSource(object):
"""
ext = os.path.splitext(self.path)[1]
if ext in [ ".zip", ".xpi" ]:
- try:
- gbpc.UnpackZipArchive(self.path, dir)()
- except gbpc.CommandExecFailed:
- raise GbpError, "Unpacking of %s failed" % self.path
+ self._unpack_zip(dir)
else:
- unpack_orig(self.path, dir, filters)
+ self._unpack_tar(dir, filters)
+
+ def _unpack_zip(self, dir):
+ try:
+ gbpc.UnpackZipArchive(self.path, dir)()
+ except gbpc.CommandExecFailed:
+ raise GbpError, "Unpacking of %s failed" % self.path
+
+ def _unpacked_toplevel(self, dir):
+ """unpacked archives can contain a leading directory not"""
+ unpacked = glob.glob('%s/*' % dir)
+ unpacked.extend(glob.glob("%s/.*" % dir)) # include hidden files and folders
+ # Check that dir contains nothing but a single folder:
+ if len(unpacked) == 1 and os.path.isdir(unpacked[0]):
+ return unpacked[0]
+ else:
+ return dir
+
+ def _unpack_tar(self, dir, filters):
+ """
+ unpack a .orig.tar.gz to tmpdir, leave the cleanup to the caller in case of
+ an error
+ """
+ try:
+ unpackArchive = gbpc.UnpackTarArchive(self.path, dir, filters)
+ unpackArchive()
+ except gbpc.CommandExecFailed:
+ # unpackArchive already printed an error message
+ raise GbpError
def pack(self, newarchive, filters=[]):
"""
@@ -504,31 +529,6 @@ def do_uscan():
return parse_uscan(out)
-def unpack_orig(archive, tmpdir, filters):
- """
- unpack a .orig.tar.gz to tmpdir, leave the cleanup to the caller in case of
- an error
- """
- try:
- unpackArchive = gbpc.UnpackTarArchive(archive, tmpdir, filters)
- unpackArchive()
- except gbpc.CommandExecFailed:
- # unpackArchive already printed an error message
- raise GbpError
- return unpackArchive.dir
-
-
-def tar_toplevel(dir):
- """tar archives can contain a leading directory not"""
- unpacked = glob.glob('%s/*' % dir)
- unpacked.extend(glob.glob("%s/.*" % dir)) # include hidden files and folders
- # Check that dir contains nothing but a single folder:
- if len(unpacked) == 1 and os.path.isdir(unpacked[0]):
- return unpacked[0]
- else:
- return dir
-
-
def get_arch():
pipe = subprocess.Popen(["dpkg", "--print-architecture"], shell=False, stdout=subprocess.PIPE)
arch = pipe.stdout.readline().strip()
diff --git a/git-buildpackage b/git-buildpackage
index 325b8cbc..d18fa93d 100755
--- a/git-buildpackage
+++ b/git-buildpackage
@@ -246,19 +246,19 @@ def extract_orig(orig_tarball, dest_dir):
gbp.log.info("Extracting %s to '%s'" % (os.path.basename(orig_tarball), dest_dir))
move_old_export(dest_dir)
- du.unpack_orig(orig_tarball, dest_dir, '')
+ upstream = gbp.deb.UpstreamSource(orig_tarball)
+ upstream.unpack(dest_dir)
# Check if tarball extracts into a single folder or not:
- tar_topdir = du.tar_toplevel(dest_dir)
- if tar_topdir != dest_dir:
+ if upstream.unpacked != dest_dir:
# If it extracts a single folder, move all of its contents to dest_dir:
- r = glob("%s/*" % tar_topdir)
- r.extend(glob("%s/.*" % tar_topdir)) # include hidden files and folders
+ r = glob("%s/*" % upstream.unpacked)
+ r.extend(glob("%s/.*" % upstream.unpacked)) # include hidden files and folders
for f in r:
os.rename(f, os.path.join(dest_dir, os.path.basename(f)))
# Remove that single folder:
- os.rmdir(tar_topdir)
+ os.rmdir(upstream.unpacked)
def guess_comp_type(repo, comp_type, cp, tarball_dir):
diff --git a/git-import-dsc b/git-import-dsc
index 0cf4223e..16a9771f 100755
--- a/git-import-dsc
+++ b/git-import-dsc
@@ -27,8 +27,8 @@ import pipes
import time
from email.Utils import parseaddr
import gbp.command_wrappers as gbpc
-from gbp.deb import (debian_version_chars, parse_changelog, unpack_orig,
- parse_dsc, DscFile, tar_toplevel)
+from gbp.deb import (debian_version_chars, parse_changelog,
+ parse_dsc, DscFile, UpstreamSource)
from gbp.git import (build_tag, create_repo, GitRepository,
GitRepositoryError, rfc822_date_to_git)
from gbp.config import GbpOptionParser, GbpOptionGroup, no_upstream_branch_msg
@@ -250,8 +250,8 @@ def main(argv):
os.chdir(repo.path)
dirs['tmp'] = os.path.abspath(tempfile.mkdtemp(dir='..'))
- unpack_dir = unpack_orig(src.tgz, dirs['tmp'], options.filters)
- unpack_dir = tar_toplevel(unpack_dir)
+ upstream = UpstreamSource(src.tgz)
+ upstream.unpack(dirs['tmp'], options.filters)
format = [(options.upstream_tag, "Upstream"), (options.debian_tag, "Debian")][src.native]
tag = build_tag(format[0], src.upstream_version)
@@ -281,7 +281,7 @@ def main(argv):
"\nAlso check the --create-missing-branches option.")
raise GbpError
- commit = repo.commit_dir(unpack_dir,
+ commit = repo.commit_dir(upstream.unpacked,
"Imported %s" % msg,
branch)
gitTag(version=tag, msg=msg, commit=commit)
@@ -296,7 +296,7 @@ def main(argv):
if is_empty and not repo.has_branch(options.debian_branch):
gbpc.GitBranch()(options.debian_branch, commit)
if src.diff or src.deb_tgz:
- apply_debian_patch(repo, unpack_dir, src, options, parents)
+ apply_debian_patch(repo, upstream.unpacked, src, options, parents)
else:
gbp.log.warn("Didn't find a diff to apply.")
if repo.get_branch() == options.debian_branch or is_empty:
diff --git a/git-import-orig b/git-import-orig
index 08db8970..5e9bbb53 100755
--- a/git-import-orig
+++ b/git-import-orig
@@ -27,7 +27,7 @@ import subprocess
import tempfile
import gbp.command_wrappers as gbpc
from gbp.deb import (parse_changelog, UpstreamSource,
- NoChangelogError, has_epoch, tar_toplevel,
+ NoChangelogError, has_epoch,
guess_upstream_version, do_uscan,
parse_changelog_repo, is_valid_packagename,
packagename_msg, is_valid_upstreamversion,
diff --git a/tests/02_test_import.py b/tests/02_test_import.py
index 33628ea7..f1e93c97 100644
--- a/tests/02_test_import.py
+++ b/tests/02_test_import.py
@@ -46,10 +46,6 @@ class TestUnpack:
if not os.getenv("GBP_TESTS_NOCLEAN"):
shutil.rmtree(self.dir)
- def test_unpack(self):
- for (comp, archive) in self.archives.iteritems():
- gbp.deb.unpack_orig(archive[0], ".", [])
-
def test_upstream_source_type(self):
for (comp, archive) in self.archives.iteritems():
source = gbp.deb.UpstreamSource(archive[0])