Merge lp:~milo/linaro-image-tools/bug1081747 into lp:linaro-image-tools/11.11

Proposed by Milo Casagrande
Status: Merged
Approved by: James Tunnicliffe
Approved revision: 626
Merged at revision: 625
Proposed branch: lp:~milo/linaro-image-tools/bug1081747
Merge into: lp:linaro-image-tools/11.11
Diff against target: 164 lines (+69/-41)
4 files modified
linaro_image_tools/hwpack/builder.py (+1/-39)
linaro_image_tools/hwpack/handler.py (+1/-1)
linaro_image_tools/hwpack/package_unpacker.py (+66/-0)
linaro_image_tools/hwpack/tests/test_builder.py (+1/-1)
To merge this branch: bzr merge lp:~milo/linaro-image-tools/bug1081747
Reviewer Review Type Date Requested Status
James Tunnicliffe (community) Approve
Review via email: mp+167265@code.launchpad.net

Description of the change

Refactored out the PackageUnpacker class in order to avoid unrelated imports
so that linaro-android-media-create can be run (from source) also under non
Debian-based system.

To post a comment you must log in.
Revision history for this message
James Tunnicliffe (dooferlad) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'linaro_image_tools/hwpack/builder.py'
2--- linaro_image_tools/hwpack/builder.py 2013-02-18 13:05:58 +0000
3+++ linaro_image_tools/hwpack/builder.py 2013-06-04 13:05:38 +0000
4@@ -22,7 +22,6 @@
5 import logging
6 import errno
7 import subprocess
8-import tempfile
9 import os
10 import shutil
11 from glob import iglob
12@@ -39,6 +38,7 @@
13 LocalArchiveMaker,
14 PackageFetcher,
15 )
16+from linaro_image_tools.hwpack.package_unpacker import PackageUnpacker
17
18 from linaro_image_tools.hwpack.hwpack_fields import (
19 PACKAGE_FIELD,
20@@ -59,44 +59,6 @@
21 "No such config file: '%s'" % self.filename)
22
23
24-class PackageUnpacker(object):
25- def __enter__(self):
26- self.tempdir = tempfile.mkdtemp()
27- return self
28-
29- def __exit__(self, type, value, traceback):
30- if self.tempdir is not None and os.path.exists(self.tempdir):
31- shutil.rmtree(self.tempdir)
32-
33- def get_path(self, package_file_name, file_name=''):
34- """Get package or file path in unpacker tmp dir."""
35- package_dir = os.path.basename(package_file_name)
36- return os.path.join(self.tempdir, package_dir, file_name)
37-
38- def unpack_package(self, package_file_name):
39- # We could extract only a single file, but since dpkg will pipe
40- # the entire package through tar anyway we might as well extract all.
41- unpack_dir = self.get_path(package_file_name)
42- if not os.path.isdir(unpack_dir):
43- os.mkdir(unpack_dir)
44- p = cmd_runner.run(["tar", "-C", unpack_dir, "-xf", "-"],
45- stdin=subprocess.PIPE)
46- cmd_runner.run(["dpkg", "--fsys-tarfile", package_file_name],
47- stdout=p.stdin).communicate()
48- p.communicate()
49-
50- def get_file(self, package, file):
51- # File path passed here must not be absolute, or file from
52- # real filesystem will be referenced.
53- assert file and file[0] != '/'
54- self.unpack_package(package)
55- logger.debug("Unpacked package %s." % package)
56- temp_file = self.get_path(package, file)
57- assert os.path.exists(temp_file), "The file '%s' was " \
58- "not found in the package '%s'." % (file, package)
59- return temp_file
60-
61-
62 class HardwarePackBuilder(object):
63
64 def __init__(self, config_path, version, local_debs, out_name=None):
65
66=== modified file 'linaro_image_tools/hwpack/handler.py'
67--- linaro_image_tools/hwpack/handler.py 2013-02-18 13:05:58 +0000
68+++ linaro_image_tools/hwpack/handler.py 2013-06-04 13:05:38 +0000
69@@ -27,7 +27,7 @@
70 import tempfile
71
72 from linaro_image_tools.hwpack.config import Config
73-from linaro_image_tools.hwpack.builder import PackageUnpacker
74+from linaro_image_tools.hwpack.package_unpacker import PackageUnpacker
75 from linaro_image_tools.utils import DEFAULT_LOGGER_NAME
76
77
78
79=== added file 'linaro_image_tools/hwpack/package_unpacker.py'
80--- linaro_image_tools/hwpack/package_unpacker.py 1970-01-01 00:00:00 +0000
81+++ linaro_image_tools/hwpack/package_unpacker.py 2013-06-04 13:05:38 +0000
82@@ -0,0 +1,66 @@
83+# Copyright (C) 2010, 2011, 2013 Linaro
84+#
85+# This file is part of Linaro Image Tools.
86+#
87+# Linaro Image Tools is free software; you can redistribute it and/or
88+# modify it under the terms of the GNU General Public License
89+# as published by the Free Software Foundation; either version 2
90+# of the License, or (at your option) any later version.
91+#
92+# Linaro Image Tools is distributed in the hope that it will be useful,
93+# but WITHOUT ANY WARRANTY; without even the implied warranty of
94+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95+# GNU General Public License for more details.
96+#
97+# You should have received a copy of the GNU General Public License
98+# along with Linaro Image Tools; if not, write to the Free Software
99+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
100+# USA.
101+
102+import logging
103+import os
104+import tempfile
105+
106+from subprocess import PIPE
107+from shutil import rmtree
108+
109+from linaro_image_tools import cmd_runner
110+
111+logger = logging.getLogger(__name__)
112+
113+
114+class PackageUnpacker(object):
115+ def __enter__(self):
116+ self.tempdir = tempfile.mkdtemp()
117+ return self
118+
119+ def __exit__(self, type, value, traceback):
120+ if self.tempdir is not None and os.path.exists(self.tempdir):
121+ rmtree(self.tempdir)
122+
123+ def get_path(self, package_file_name, file_name=''):
124+ """Get package or file path in unpacker tmp dir."""
125+ package_dir = os.path.basename(package_file_name)
126+ return os.path.join(self.tempdir, package_dir, file_name)
127+
128+ def unpack_package(self, package_file_name):
129+ # We could extract only a single file, but since dpkg will pipe
130+ # the entire package through tar anyway we might as well extract all.
131+ unpack_dir = self.get_path(package_file_name)
132+ if not os.path.isdir(unpack_dir):
133+ os.mkdir(unpack_dir)
134+ p = cmd_runner.run(["tar", "-C", unpack_dir, "-xf", "-"], stdin=PIPE)
135+ cmd_runner.run(["dpkg", "--fsys-tarfile", package_file_name],
136+ stdout=p.stdin).communicate()
137+ p.communicate()
138+
139+ def get_file(self, package, file):
140+ # File path passed here must not be absolute, or file from
141+ # real filesystem will be referenced.
142+ assert file and file[0] != '/'
143+ self.unpack_package(package)
144+ logger.debug("Unpacked package %s." % package)
145+ temp_file = self.get_path(package, file)
146+ assert os.path.exists(temp_file), "The file '%s' was " \
147+ "not found in the package '%s'." % (file, package)
148+ return temp_file
149
150=== modified file 'linaro_image_tools/hwpack/tests/test_builder.py'
151--- linaro_image_tools/hwpack/tests/test_builder.py 2013-02-17 13:53:41 +0000
152+++ linaro_image_tools/hwpack/tests/test_builder.py 2013-06-04 13:05:38 +0000
153@@ -27,10 +27,10 @@
154
155 from linaro_image_tools.hwpack.builder import (
156 ConfigFileMissing,
157- PackageUnpacker,
158 HardwarePackBuilder,
159 logger as builder_logger,
160 )
161+from linaro_image_tools.hwpack.package_unpacker import PackageUnpacker
162 from linaro_image_tools.hwpack.config import HwpackConfigError
163 from linaro_image_tools.hwpack.hardwarepack import Metadata
164 from linaro_image_tools.hwpack.packages import (

Subscribers

People subscribed via source and target branches