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):
"""
"""
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=[]):
"""
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()
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):
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
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)
"\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)
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:
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,
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])