Catch unpack exception if unpack fails
authorZhang Qiang <qiang.z.zhang@intel.com>
Wed, 21 Mar 2012 09:42:15 +0000 (17:42 +0800)
committerZhang Qiang <qiang.z.zhang@intel.com>
Wed, 21 Mar 2012 09:42:15 +0000 (17:42 +0800)
README.rst
gitbuildsys/cmd_import_orig.py
gitbuildsys/errors.py
gitbuildsys/utils.py

index 97ae4d3..691fcb5 100644 (file)
@@ -327,8 +327,10 @@ Running 'gbs import-orig'
 -------------------------
 
 Subcommand `import-orig` is used to import original upstream tar ball to current
-git  repository. This subcommand is mostlly used for upgrade packages. usage of
-subcommand `import-orig` can be available from `gbs import-orig --help`
+git  repository. This subcommand is mostlly used for upgrade packages. upstream
+tar ball format can be tar.gz, tar.bz2, tar.xz, tar.lzma or .zip.
+
+Usage of subcommand `import-orig` can be available from `gbs import-orig --help`
 ::
 
   root@test-virtual-machine:~/gbs# gbs import-orig -h
@@ -339,7 +341,7 @@ subcommand `import-orig` can be available from `gbs import-orig --help`
 
 
   Examples:
-    $ gbs import original-tar-ball
+    $ gbs import-orig original-tar-ball
   Options:
       -h, --help          show this help message and exit
       --tag               Create tag while import new version of upstream tar
index 36c65cb..535636c 100644 (file)
@@ -56,7 +56,12 @@ def do(opts, args):
     msger.info('unpack upstream tar ball ...')
     upstream = utils.UpstreamTarball(tarball)
     (pkgname, pkgversion) = upstream.guess_version() or ('', '')
-    upstream.unpack(tardir)
+
+    try:
+        import pdb;pdb.set_trace()
+        upstream.unpack(tardir)
+    except errors.UnpackError:
+        msger.error('Unpacking %s fail' % tarball)
 
     tag = repo.version_to_tag("%(version)s", pkgversion)
     msg = "Upstream version %s" % (pkgversion)
index f41fe41..6dab015 100644 (file)
@@ -46,5 +46,8 @@ class GitInvalid(GitError):
 class ObsError(CmdError):
     keyword = '<obs>'
 
+class UnpackError(CmdError):
+    keyword = '<unpack>'
+
 class Abort(CmdError):
     keyword = ''
index da7b77d..ad18bb6 100644 (file)
@@ -24,6 +24,7 @@ import re
 
 import msger
 import runner
+import errors
 
 compressor_opts = { 'gzip'  : [ '-n', 'gz' ],
                     'bzip2' : [ '', 'bz2' ],
@@ -164,7 +165,9 @@ class UnpackTarArchive(object):
             compression = '-a'
 
         cmd = ' '.join(['tar']+ exclude + ['-C', dir, compression, '-xf', archive ])
-        runner.quiet(cmd)
+        ret = runner.quiet(cmd)
+        if ret != 0:
+            raise errors.UnpackError("Unpacking of %s failed" % archive)
 
 class UnpackZipArchive(object):
     """Wrap zip to Unpack a zip file"""
@@ -173,8 +176,9 @@ class UnpackZipArchive(object):
         self.dir = dir
 
         cmd = ' '.join(['unzip'] + [ "-q", archive, '-d', dir ])
-        msger.info(cmd)
-        runner.quiet(cmd)
+        ret = runner.quiet(cmd)
+        if ret != 0:
+            raise errors.UnpackError("Unpacking of %s failed" % archive)
 
 class UpstreamTarball(object):
     def __init__(self, name, unpacked=None):
@@ -195,7 +199,7 @@ class UpstreamTarball(object):
             filters = []
 
         if type(filters) != type([]):
-            raise GbpError, "Filters must be a list"
+            raise errors.UnpackError ('Filters must be a list')
 
         self._unpack_archive(dir, filters)
         self.unpacked = self._unpacked_toplevel(dir)
@@ -211,10 +215,7 @@ class UpstreamTarball(object):
             self._unpack_tar(dir, filters)
 
     def _unpack_zip(self, dir):
-        try:
-            UnpackZipArchive(self.path, dir)
-        except CmdError:
-            raise CmdError, "Unpacking of %s failed" % self.path
+        UnpackZipArchive(self.path, dir)
 
     def _unpacked_toplevel(self, dir):
         """unpacked archives can contain a leading directory or not"""
@@ -231,10 +232,7 @@ class UpstreamTarball(object):
         """
         Unpack a tarball to dir applying a list of filters.
         """
-        try:
-            unpackArchive = UnpackTarArchive(self.path, dir, filters)
-        except gbpc.CommandExecFailed:
-            raise GbpError
+        UnpackTarArchive(self.path, dir, filters)
 
     def guess_version(self, extra_regex=r''):
         """