diff mbox

[Branch,~linaro-image-tools/linaro-image-tools/trunk] Rev 447: Support the new path for the rootfs dir within the tarball.

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

Commit Message

James Westby Oct. 13, 2011, 7:46 p.m. UTC
Merge authors:
  Mattias Backman (mabac)
Related merge proposals:
  https://code.launchpad.net/~mabac/linaro-image-tools/bug-872007-rootfsdir/+merge/79092
  proposed by: Mattias Backman (mabac)
  review: Approve - James Westby (james-w)
------------------------------------------------------------
revno: 447 [merge]
committer: James Westby <james.westby@linaro.org>
branch nick: trunk
timestamp: Thu 2011-10-13 15:43:59 -0400
message:
  Support the new path for the rootfs dir within the tarball.
  
  live-build has changed the path that it puts the rootfs at
  within the tarball, so we have to support both the old and
  new locations.
modified:
  linaro-media-create
  linaro_image_tools/tests/test_pyflakes.py
  linaro_image_tools/tests/test_utils.py
  linaro_image_tools/utils.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-media-create'
--- linaro-media-create	2011-09-22 20:11:46 +0000
+++ linaro-media-create	2011-10-12 09:54:29 +0000
@@ -47,6 +47,7 @@ 
     ensure_command,
     is_arm_host,
     check_file_integrity_and_log_errors,
+    path_in_tarfile_exists,
     )
 
 # Just define the global variables
@@ -106,8 +107,12 @@ 
 
     # If --help was specified this won't execute.
     # Create temp dir and initialize rest of path vars.
+    filesystem_dir = 'binary'
+    if not path_in_tarfile_exists('binary/etc', args.binary):
+        # The binary image is in the new live format.
+        filesystem_dir = 'binary/boot/filesystem.dir'
     TMP_DIR = tempfile.mkdtemp()
-    ROOTFS_DIR = os.path.join(TMP_DIR, 'binary')
+    ROOTFS_DIR = os.path.join(TMP_DIR, filesystem_dir)
     BOOT_DISK = os.path.join(TMP_DIR, 'boot-disc')
     ROOT_DISK = os.path.join(TMP_DIR, 'root-disc')
 

=== modified file 'linaro_image_tools/tests/test_pyflakes.py'
--- linaro_image_tools/tests/test_pyflakes.py	2011-08-18 16:00:26 +0000
+++ linaro_image_tools/tests/test_pyflakes.py	2011-10-12 09:54:29 +0000
@@ -29,8 +29,8 @@ 
         (stdout, stderr) = proc.communicate()
         stdout = stdout.splitlines()
         stdout.sort()
-        expected = ["./linaro_image_tools/utils.py:30: redefinition of "
-                        "unused 'CommandNotFound' from line 28" ]
+        expected = ["./linaro_image_tools/utils.py:31: redefinition of "
+                        "unused 'CommandNotFound' from line 29" ]
         self.assertEquals(expected, stdout)
         self.assertEquals('', stderr)
 

=== modified file 'linaro_image_tools/tests/test_utils.py'
--- linaro_image_tools/tests/test_utils.py	2011-08-18 16:00:26 +0000
+++ linaro_image_tools/tests/test_utils.py	2011-10-12 09:54:29 +0000
@@ -23,6 +23,7 @@ 
 import sys
 import logging
 import tempfile
+import tarfile
 
 from linaro_image_tools import cmd_runner, utils
 from linaro_image_tools.testing import TestCaseWithFixtures
@@ -39,12 +40,32 @@ 
     UnableToFindPackageProvidingCommand,
     verify_file_integrity,
     check_file_integrity_and_log_errors,
+    path_in_tarfile_exists,
     )
 
 
 sudo_args = " ".join(cmd_runner.SUDO_ARGS)
 
 
+class TestPathInTarfile(TestCaseWithFixtures):
+    def setUp(self):
+        super(TestPathInTarfile, self).setUp()
+        tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
+        self.tarfile_name = os.path.join(tempdir, 'test_tarfile.tar.gz')
+        self.tempfile_added = self.createTempFileAsFixture()
+        self.tempfile_unused = self.createTempFileAsFixture()
+        with tarfile.open(self.tarfile_name, 'w:gz') as tar:
+            tar.add(self.tempfile_added)
+
+    def test_file_exists(self):
+        self.assertTrue(path_in_tarfile_exists(self.tempfile_added[1:],
+                                               self.tarfile_name))
+
+    def test_file_does_not_exist(self):
+        self.assertFalse(path_in_tarfile_exists(self.tempfile_unused[1:],
+                                                self.tarfile_name))
+
+
 class TestVerifyFileIntegrity(TestCaseWithFixtures):
 
     filenames_in_shafile = ['verified-file1', 'verified-file2']

=== modified file 'linaro_image_tools/utils.py'
--- linaro_image_tools/utils.py	2011-08-15 16:57:07 +0000
+++ linaro_image_tools/utils.py	2011-10-13 14:49:05 +0000
@@ -23,6 +23,7 @@ 
 import re
 import logging
 import tempfile
+import tarfile
 
 try:
     from CommandNotFound import CommandNotFound
@@ -32,6 +33,15 @@ 
 from linaro_image_tools import cmd_runner
 
 
+def path_in_tarfile_exists(path, tar_file):
+    tarinfo = tarfile.open(tar_file, 'r:gz')
+    try:
+        tarinfo.getmember(path)
+        return True
+    except KeyError:
+        return False
+    tarinfo.close()
+
 def verify_file_integrity(sig_file_list):
     """Verify a list of signature files.