On Mon, Jul 13, 2009 at 07:09:35PM +0200, Guido Günther wrote:
> Hi Muayyad,

It's Ahmed actually, Muayyad is someone who helped me with Python, since 
I'm not a Python coder (this is only my second time to try to hack 
Python code)

> > +    # TODO: do not create this dir ? remove the dir if something wrong 
> > goes with tar ?
> > +    os.mkdir(dest_dir)
> This should be handled similar to the --export option.

Ok, used move_old_export(dest_dir) instead !

> > +    r=os.system('tar -zxf "%s" -C "%s"' % (orig_tarball, dest_dir))
> Please use UnpackTarArchive or better unpack_orig.

Done !

> > +    if r!=0:
> > +        raise "Could not extract orig tarball"
> Please raise a proper exception here - see GbpError.

No need for this anymore, since I've used unpack_orig.

> > +    # Check if tarball extracts into a single folder or not:
> > +    r=glob("%s/*" % dest_dir)
> Coding Style is a = b.

Ok, fixed !

> > +    r.extend(glob("%s/.*" % dest_dir)) # include hidden files and folders
> This looks like tar_toblevel (although your version is more accurate).

Ok, I am using tar_toplevel, also I modified tar_toplevel to make it 
more accurate.

Please check the attached patch.

-- 
 ‎أحمد المحمودي (Ahmed El-Mahmoudy)
  Digital design engineer
 GPG KeyID: 0xEDDDA1B7 (@ subkeys.pgp.net)
 GPG Fingerprint: 8206 A196 2084 7E6D 0DF8  B176 BC19 6A94 EDDD A1B7
diff --git a/gbp/config.py b/gbp/config.py
index 0ffcc32..9aec395 100644
--- a/gbp/config.py
+++ b/gbp/config.py
@@ -43,6 +43,7 @@ class GbpOptionParser(OptionParser):
                  'git-log'         : '--no-merges',
                  'export'          : 'HEAD',
                  'export-dir'      : '',
+                 'overlay'         : 'False',
                  'tarball-dir'     : '',
                  'ignore-new'      : 'False',
                  'meta'            : 'False',
@@ -79,6 +80,8 @@ class GbpOptionParser(OptionParser):
                   "parse meta tags in commit messages, default is '%(meta)s'",
              'ignore-new':
                   "build with uncommited changes in the source tree, default is '%(ignore-new)s'",
+             'overlay':
+                  "extract orig tarball when using export-dir option, default is '%(overlay)s'",
            }
     config_files = [ '/etc/git-buildpackage/gbp.conf',
                      os.path.expanduser('~/.gbp.conf'),
diff --git a/gbp/deb_utils.py b/gbp/deb_utils.py
index d701eb4..2af2fdf 100644
--- a/gbp/deb_utils.py
+++ b/gbp/deb_utils.py
@@ -214,7 +214,9 @@ def repack_orig(archive, tmpdir, dest):
 def tar_toplevel(dir):
     """tar archives can contain a leading directory not"""
     unpacked = glob.glob('%s/*' % dir)
-    if len(unpacked) == 1:
+    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
diff --git a/git-buildpackage b/git-buildpackage
index 2e9ebdd..effdfbf 100755
--- a/git-buildpackage
+++ b/git-buildpackage
@@ -29,6 +29,7 @@ from gbp.command_wrappers import (GitTag, Command, RunAtCommand, CommandExecFail
                                   PristineTar, RemoveTree, GitAdd)
 from gbp.config import (GbpOptionParser, GbpOptionGroup)
 from gbp.errors import GbpError
+from glob import glob
 
 # when we want to reference the index in a treeish context we call it:
 index_name = "INDEX"
@@ -136,6 +137,25 @@ def write_wc(repo):
     return tree
 
 
+def extract_orig(orig_tarball, dest_dir):
+    """extract orig tarball to export dir before exporting from git"""
+    print "Extracting %s to '%s'" % (os.path.basename(orig_tarball), dest_dir)
+
+    move_old_export(dest_dir)
+    du.unpack_orig(orig_tarball, 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 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
+        for f in r:
+            os.rename(f, os.path.join(dest_dir, os.path.basename(f)))
+
+        # Remove that single folder:
+        os.rmdir(tar_topdir)
+
 def main(argv):
     changelog = 'debian/changelog'
     retval = 0
@@ -192,6 +212,7 @@ def main(argv):
                       help="export treeish object TREEISH, default is '%(export)s'", metavar="TREEISH")
     export_group.add_option("--git-dont-purge", action="store_false", dest="purge", default=True,
                       help="retain exported package build directory")
+    export_group.add_boolean_config_file_option(option_name="overlay", dest="overlay")
     (options, args) = parser.parse_args(args)
 
     if options.verbose:
@@ -242,6 +263,20 @@ def main(argv):
             else:
                 tarball_dir = output_dir
 
+            # Get/build the orig.tar.gz if necessary:
+            if not du.is_native(cp):
+                # look in tarball_dir first, if found force a symlink to it
+                if options.tarball_dir:
+                    print "Looking for orig tarball '%s' at '%s'" % (du.orig_file(cp), tarball_dir)
+                    if not du.symlink_orig(cp, tarball_dir, output_dir, force=True):
+                        print "Orig tarball '%s' not found at '%s'" % (du.orig_file(cp), tarball_dir)
+                    else:
+                        print "Orig tarball '%s' found at '%s'" % (du.orig_file(cp), tarball_dir)
+                # build an orig unless the user forbidds it
+                if not options.no_create_orig and not du.has_orig(cp, output_dir):
+                    if not pristine_tar_build_orig(repo, cp, output_dir, options):
+                        git_archive_build_orig(repo, cp, output_dir, options)
+
             # Export to another build dir if requested:
             if options.export_dir:
                 # write a tree of the index if necessary:
@@ -254,6 +289,11 @@ def main(argv):
                 if not repo.has_treeish(tree):
                     raise GbpError # git-ls-tree printed an error message already
                 tmp_dir = os.path.join(output_dir, "%s-tmp" % cp['Source'])
+
+                # Extract orig tarball if git-overlay option is selected:
+                if options.overlay:
+                    extract_orig(os.path.join(output_dir, du.orig_file(cp)) , tmp_dir)
+
                 print "Exporting '%s' to '%s'" % (options.export, tmp_dir)
                 dump_tree(tmp_dir, tree)
                 cp = du.parse_changelog(os.path.join(tmp_dir, 'debian', 'changelog'))
@@ -262,20 +302,6 @@ def main(argv):
                 move_old_export(export_dir)
                 os.rename(tmp_dir, export_dir)
 
-            # Get/build the orig.tar.gz if necessary:
-            if not du.is_native(cp):
-                # look in tarball_dir first, if found force a symlink to it
-                if options.tarball_dir:
-                    print "Looking for orig tarball '%s' at '%s'" % (du.orig_file(cp), tarball_dir)
-                    if not du.symlink_orig(cp, tarball_dir, output_dir, force=True):
-                        print "Orig tarball '%s' not found at '%s'" % (du.orig_file(cp), tarball_dir)
-                    else:
-                        print "Orig tarball '%s' found at '%s'" % (du.orig_file(cp), tarball_dir)
-                # build an orig unless the user forbidds it
-                if not options.no_create_orig and not du.has_orig(cp, output_dir):
-                    if not pristine_tar_build_orig(repo, cp, output_dir, options):
-                        git_archive_build_orig(repo, cp, output_dir, options)
-
             if options.export_dir:
                 build_dir = export_dir
             else:

Reply via email to