1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-31 12:49:46 +00:00

wic: reimplement getting paths of used tools

So far every used tool have to have separate property and
private attribute in the Disk class. This is too verbose,
considering that there will be much more tools used.

Reimplemented getting tools paths using custom __getattr__
method. This is much more compact and readable.

(From OE-Core rev: d1a831a9870bc31e936eb480485b28f1ffc13080)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh
2017-08-25 23:12:22 +03:00
committed by Richard Purdie
parent 051a3a61d8
commit ff0bbdafa4
+9 -27
View File
@@ -236,10 +236,6 @@ class Disk:
self.imagepath = imagepath self.imagepath = imagepath
self.native_sysroot = native_sysroot self.native_sysroot = native_sysroot
self._partitions = None self._partitions = None
self._mdir = None
self._mcopy = None
self._mdel = None
self._mdeltree = None
self._partimages = {} self._partimages = {}
# find parted # find parted
@@ -270,30 +266,16 @@ class Disk:
return self._partitions return self._partitions
def _prop(self, name): def __getattr__(self, name):
"""Get path to the executable in a lazy way.""" """Get path to the executable in a lazy way."""
aname = "_%s" % name if name in ("mdir", "mcopy", "mdel", "mdeltree"):
if getattr(self, aname) is None: aname = "_%s" % name
setattr(self, aname, find_executable(name, self.paths)) if aname not in self.__dict__:
if not getattr(self, aname): setattr(self, aname, find_executable(name, self.paths))
raise WicError("Can't find executable {}".format(name)) if aname not in self.__dict__:
return getattr(self, aname) raise WicError("Can't find executable {}".format(name))
return self.__dict__[aname]
@property return self.__dict__[name]
def mdir(self):
return self._prop('mdir')
@property
def mcopy(self):
return self._prop("mcopy")
@property
def mdel(self):
return self._prop("mdel")
@property
def mdeltree(self):
return self._prop("mdeltree")
def _get_part_image(self, pnum): def _get_part_image(self, pnum):
if pnum not in self.partitions: if pnum not in self.partitions: