summaryrefslogtreecommitdiffstats
path: root/scripts/lib
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-06-13 14:21:56 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-06-14 10:18:29 +0100
commit6f1b89c224f0ea4ecf45cf0ef7a8927c5c88d763 (patch)
treeb37d2a863bd016da6cbdc610795966234f23bc81 /scripts/lib
parent746351100ef860d3438e93683dc2ed4ba8d213e8 (diff)
downloadpoky-6f1b89c224f0ea4ecf45cf0ef7a8927c5c88d763.tar.gz
engine: implement listing wic images
Implemented 'wic ls' functionality: - list image partitions - list directory content of vfat partitions [YOCTO #11283] (From OE-Core rev: 61667fabd5746caf773f73b3aeb2a04db13cba38) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib')
-rw-r--r--scripts/lib/wic/engine.py84
1 files changed, 82 insertions, 2 deletions
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
index e58beb7dce..95c8d1cc22 100644
--- a/scripts/lib/wic/engine.py
+++ b/scripts/lib/wic/engine.py
@@ -30,10 +30,15 @@
30 30
31import logging 31import logging
32import os 32import os
33import tempfile
34
35from collections import namedtuple, OrderedDict
36from distutils.spawn import find_executable
33 37
34from wic import WicError 38from wic import WicError
39from wic.filemap import sparse_copy
35from wic.pluginbase import PluginMgr 40from wic.pluginbase import PluginMgr
36from wic.utils.misc import get_bitbake_var 41from wic.utils.misc import get_bitbake_var, exec_cmd
37 42
38logger = logging.getLogger('wic') 43logger = logging.getLogger('wic')
39 44
@@ -225,9 +230,84 @@ def wic_list(args, scripts_path):
225 230
226 return False 231 return False
227 232
233
234class Disk:
235 def __init__(self, imagepath, native_sysroot):
236 self.imagepath = imagepath
237 self.native_sysroot = native_sysroot
238 self._partitions = None
239 self._mdir = None
240 self._partimages = {}
241
242 # find parted
243 self.paths = "/bin:/usr/bin:/usr/sbin:/sbin/"
244 if native_sysroot:
245 for path in self.paths.split(':'):
246 self.paths = "%s%s:%s" % (native_sysroot, path, self.paths)
247
248 self.parted = find_executable("parted", self.paths)
249 if not self.parted:
250 raise WicError("Can't find executable parted")
251
252 def __del__(self):
253 for path in self._partimages.values():
254 os.unlink(path)
255
256 @property
257 def partitions(self):
258 if self._partitions is None:
259 self._partitions = OrderedDict()
260 out = exec_cmd("%s -sm %s unit B print" % (self.parted, self.imagepath))
261 parttype = namedtuple("Part", "pnum start end size fstype")
262 for line in out.splitlines()[2:]:
263 pnum, start, end, size, fstype = line.split(':')[:5]
264 partition = parttype(pnum, int(start[:-1]), int(end[:-1]),
265 int(size[:-1]), fstype)
266 self._partitions[pnum] = partition
267
268 return self._partitions
269
270 @property
271 def mdir(self):
272 if self._mdir is None:
273 self._mdir = find_executable("mdir", self.paths)
274 if not self._mdir:
275 raise WicError("Can't find executable mdir")
276 return self._mdir
277
278 def _get_part_image(self, pnum):
279 if pnum not in self.partitions:
280 raise WicError("Partition %s is not in the image")
281 part = self.partitions[pnum]
282 if not part.fstype.startswith("fat"):
283 raise WicError("Not supported fstype: {}".format(part.fstype))
284 if pnum not in self._partimages:
285 tmpf = tempfile.NamedTemporaryFile(prefix="wic-part")
286 dst_fname = tmpf.name
287 tmpf.close()
288 sparse_copy(self.imagepath, dst_fname, skip=part.start, length=part.size)
289 self._partimages[pnum] = dst_fname
290
291 return self._partimages[pnum]
292
293 def dir(self, pnum, path):
294 return exec_cmd("{} -i {} ::{}".format(self.mdir,
295 self._get_part_image(pnum),
296 path))
297
228def wic_ls(args, native_sysroot): 298def wic_ls(args, native_sysroot):
229 """List contents of partitioned image or vfat partition.""" 299 """List contents of partitioned image or vfat partition."""
230 pass 300 disk = Disk(args.path.image, native_sysroot)
301 if not args.path.part:
302 if disk.partitions:
303 print('Num Start End Size Fstype')
304 for part in disk.partitions.values():
305 print("{:2s} {:12d} {:12d} {:12d} {}".format(\
306 part.pnum, part.start, part.end,
307 part.size, part.fstype))
308 else:
309 path = args.path.path or '/'
310 print(disk.dir(args.path.part, path))
231 311
232def find_canned(scripts_path, file_name): 312def find_canned(scripts_path, file_name):
233 """ 313 """