diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 572: Add Build-Info support.

Message ID 20121004165714.32145.49341.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Fathi Boudra Oct. 4, 2012, 4:57 p.m. UTC
Merge authors:
  Fathi Boudra (fboudra)
Related merge proposals:
  https://code.launchpad.net/~fboudra/linaro-image-tools/add-build-info-support/+merge/127799
  proposed by: Fathi Boudra (fboudra)
  review: Needs Fixing - Milo Casagrande (milo)
------------------------------------------------------------
revno: 572 [merge]
committer: fboudra@gmail.com
branch nick: linaro-image-tools
timestamp: Thu 2012-10-04 19:56:35 +0300
message:
  Add Build-Info support.
modified:
  linaro_image_tools/hwpack/builder.py


--
lp:linaro-image-tools
https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk

You are subscribed to branch lp:linaro-image-tools.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-image-tools/linaro-image-tools/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'linaro_image_tools/hwpack/builder.py'
--- linaro_image_tools/hwpack/builder.py	2012-09-11 14:28:20 +0000
+++ linaro_image_tools/hwpack/builder.py	2012-10-04 16:54:48 +0000
@@ -25,6 +25,9 @@ 
 import tempfile
 import os
 import shutil
+from glob import iglob
+
+from debian.debfile import DebFile
 
 from linaro_image_tools import cmd_runner
 
@@ -65,7 +68,7 @@ 
             shutil.rmtree(self.tempdir)
 
     def get_path(self, package_file_name, file_name=''):
-        "Get package or file path in unpacker tmp dir."
+        """Get package or file path in unpacker tmp dir."""
         package_dir = os.path.basename(package_file_name)
         return os.path.join(self.tempdir, package_dir, file_name)
 
@@ -214,7 +217,7 @@ 
         self.foreach_boards_and_bootloaders(
             self.do_find_copy_files_packages)
         packages = self.copy_files_packages
-        del(self.copy_files_packages)
+        del self.copy_files_packages
         return packages
 
     def build(self):
@@ -328,3 +331,45 @@ 
                         manifest_name += '.manifest.txt'
                         with open(manifest_name, 'w') as f:
                             f.write(self.hwpack.manifest_text())
+
+                        logger.debug("Extracting build-info")
+                        build_info_dir = os.path.join(fetcher.cache.tempdir,
+                                                      'build-info')
+                        build_info_available = 0
+                        for deb_pkg in self.packages:
+                            # Extract Build-Info attribute from debian control
+                            deb_pkg_file_path = deb_pkg.filepath
+                            deb_control = \
+                                DebFile(deb_pkg_file_path).control.debcontrol()
+                            build_info = deb_control.get('Build-Info')
+                            if build_info is not None:
+                                build_info_available += 1
+                                # Extract debian packages with build
+                                # information
+                                env = os.environ
+                                env['LC_ALL'] = 'C'
+                                env['NO_PKG_MANGLE'] = '1'
+                                proc = cmd_runner.Popen(['dpkg-deb', '-x',
+                                       deb_pkg_file_path, build_info_dir],
+                                       env=env, stdout=subprocess.PIPE,
+                                       stderr=subprocess.PIPE)
+                                (stdoutdata, stderrdata) = proc.communicate()
+                                if proc.returncode:
+                                    raise ValueError('dpkg-deb extract failed!'
+                                        '\n%s' % stderrdata)
+                                if stderrdata:
+                                    raise ValueError('dpkg-deb extract had '
+                                        'warnings:\n%s' % stderrdata)
+
+                        # Concatenate BUILD-INFO.txt files
+                        if build_info_available > 0:
+                            dst_file = open('BUILD-INFO.txt', 'wb')
+                            build_info_path = \
+                                r'%s/usr/share/doc/*/BUILD-INFO.txt' % \
+                                build_info_dir
+                            for src_file in iglob(build_info_path):
+                                with open(src_file, 'rb') as f:
+                                    dst_file.write('Files-Pattern: %s\n' % \
+                                                   out_name)
+                                    shutil.copyfileobj(f, dst_file)
+                            dst_file.close()