Merge lp:~mabac/linaro-image-tools/bug-872007-rootfsdir into lp:linaro-image-tools/11.11

Proposed by Mattias Backman
Status: Merged
Merged at revision: 447
Proposed branch: lp:~mabac/linaro-image-tools/bug-872007-rootfsdir
Merge into: lp:linaro-image-tools/11.11
Diff against target: 112 lines (+39/-3)
4 files modified
linaro-media-create (+6/-1)
linaro_image_tools/tests/test_pyflakes.py (+2/-2)
linaro_image_tools/tests/test_utils.py (+21/-0)
linaro_image_tools/utils.py (+10/-0)
To merge this branch: bzr merge lp:~mabac/linaro-image-tools/bug-872007-rootfsdir
Reviewer Review Type Date Requested Status
Tom Gall (community) Approve
James Westby (community) Approve
Review via email: mp+79092@code.launchpad.net

Description of the change

Hi,

This branch changes linaro-media-create to look for binary/etc in the binary image and set ROOTFS_DIR based on the existance of that path.

The purpose is to support the next Live build format where the root file system is contained in binary/boot/filesystem.dir.

Thanks,

Mattias

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

17 + if not path_in_tarfile_exists('binary/etc', args.binary):
18 + # The binary image is in the new live format.
19 + filesystem_dir = 'binary/boot/filesystem.dir'

I think it's generally better to test for the new location and fallback
to the old, but either way works, so it's your preference.

Thanks,

James

review: Approve
447. By Mattias Backman

Don't use Tarfile as a context manager.

Revision history for this message
Mattias Backman (mabac) wrote :

> 17 + if not path_in_tarfile_exists('binary/etc', args.binary):
> 18 + # The binary image is in the new live format.
> 19 + filesystem_dir = 'binary/boot/filesystem.dir'
>
> I think it's generally better to test for the new location and fallback
> to the old, but either way works, so it's your preference.

Ok thanks. No strong preference. I can change it if merging isn't too urgent.

Revision history for this message
Mattias Backman (mabac) wrote :

I caught something about python 2.6 on IRC and have changed the bit that uses Tarfile as a context manager. Please try the latest revision.

Revision history for this message
James Westby (james-w) wrote :

On Thu, 13 Oct 2011 14:55:27 -0000, Mattias Backman <email address hidden> wrote:
> > 17 + if not path_in_tarfile_exists('binary/etc', args.binary):
> > 18 + # The binary image is in the new live format.
> > 19 + filesystem_dir = 'binary/boot/filesystem.dir'
> >
> > I think it's generally better to test for the new location and fallback
> > to the old, but either way works, so it's your preference.
>
> Ok thanks. No strong preference. I can change it if merging isn't too urgent.

Let's wait for Tom's testing before merging.

Thanks,

James

Revision history for this message
Tom Gall (tom-gall) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro-media-create'
2--- linaro-media-create 2011-09-22 20:11:46 +0000
3+++ linaro-media-create 2011-10-13 14:54:25 +0000
4@@ -47,6 +47,7 @@
5 ensure_command,
6 is_arm_host,
7 check_file_integrity_and_log_errors,
8+ path_in_tarfile_exists,
9 )
10
11 # Just define the global variables
12@@ -106,8 +107,12 @@
13
14 # If --help was specified this won't execute.
15 # Create temp dir and initialize rest of path vars.
16+ filesystem_dir = 'binary'
17+ if not path_in_tarfile_exists('binary/etc', args.binary):
18+ # The binary image is in the new live format.
19+ filesystem_dir = 'binary/boot/filesystem.dir'
20 TMP_DIR = tempfile.mkdtemp()
21- ROOTFS_DIR = os.path.join(TMP_DIR, 'binary')
22+ ROOTFS_DIR = os.path.join(TMP_DIR, filesystem_dir)
23 BOOT_DISK = os.path.join(TMP_DIR, 'boot-disc')
24 ROOT_DISK = os.path.join(TMP_DIR, 'root-disc')
25
26
27=== modified file 'linaro_image_tools/tests/test_pyflakes.py'
28--- linaro_image_tools/tests/test_pyflakes.py 2011-08-18 16:00:26 +0000
29+++ linaro_image_tools/tests/test_pyflakes.py 2011-10-13 14:54:25 +0000
30@@ -29,8 +29,8 @@
31 (stdout, stderr) = proc.communicate()
32 stdout = stdout.splitlines()
33 stdout.sort()
34- expected = ["./linaro_image_tools/utils.py:30: redefinition of "
35- "unused 'CommandNotFound' from line 28" ]
36+ expected = ["./linaro_image_tools/utils.py:31: redefinition of "
37+ "unused 'CommandNotFound' from line 29" ]
38 self.assertEquals(expected, stdout)
39 self.assertEquals('', stderr)
40
41
42=== modified file 'linaro_image_tools/tests/test_utils.py'
43--- linaro_image_tools/tests/test_utils.py 2011-08-18 16:00:26 +0000
44+++ linaro_image_tools/tests/test_utils.py 2011-10-13 14:54:25 +0000
45@@ -23,6 +23,7 @@
46 import sys
47 import logging
48 import tempfile
49+import tarfile
50
51 from linaro_image_tools import cmd_runner, utils
52 from linaro_image_tools.testing import TestCaseWithFixtures
53@@ -39,12 +40,32 @@
54 UnableToFindPackageProvidingCommand,
55 verify_file_integrity,
56 check_file_integrity_and_log_errors,
57+ path_in_tarfile_exists,
58 )
59
60
61 sudo_args = " ".join(cmd_runner.SUDO_ARGS)
62
63
64+class TestPathInTarfile(TestCaseWithFixtures):
65+ def setUp(self):
66+ super(TestPathInTarfile, self).setUp()
67+ tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir()
68+ self.tarfile_name = os.path.join(tempdir, 'test_tarfile.tar.gz')
69+ self.tempfile_added = self.createTempFileAsFixture()
70+ self.tempfile_unused = self.createTempFileAsFixture()
71+ with tarfile.open(self.tarfile_name, 'w:gz') as tar:
72+ tar.add(self.tempfile_added)
73+
74+ def test_file_exists(self):
75+ self.assertTrue(path_in_tarfile_exists(self.tempfile_added[1:],
76+ self.tarfile_name))
77+
78+ def test_file_does_not_exist(self):
79+ self.assertFalse(path_in_tarfile_exists(self.tempfile_unused[1:],
80+ self.tarfile_name))
81+
82+
83 class TestVerifyFileIntegrity(TestCaseWithFixtures):
84
85 filenames_in_shafile = ['verified-file1', 'verified-file2']
86
87=== modified file 'linaro_image_tools/utils.py'
88--- linaro_image_tools/utils.py 2011-08-15 16:57:07 +0000
89+++ linaro_image_tools/utils.py 2011-10-13 14:54:25 +0000
90@@ -23,6 +23,7 @@
91 import re
92 import logging
93 import tempfile
94+import tarfile
95
96 try:
97 from CommandNotFound import CommandNotFound
98@@ -32,6 +33,15 @@
99 from linaro_image_tools import cmd_runner
100
101
102+def path_in_tarfile_exists(path, tar_file):
103+ tarinfo = tarfile.open(tar_file, 'r:gz')
104+ try:
105+ tarinfo.getmember(path)
106+ return True
107+ except KeyError:
108+ return False
109+ tarinfo.close()
110+
111 def verify_file_integrity(sig_file_list):
112 """Verify a list of signature files.
113

Subscribers

People subscribed via source and target branches