]> code.ossystems Code Review - openembedded-core.git/commitdiff
wic: add Disk._prop helper
authorEd Bartosh <ed.bartosh@linux.intel.com>
Tue, 13 Jun 2017 11:22:01 +0000 (14:22 +0300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 14 Jun 2017 09:18:20 +0000 (10:18 +0100)
Added generic helper to use in property methods to
access commands in a lazy manner.

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/lib/wic/engine.py

index f8f2844cf6c470e855a75bfb51cf07d639acddef..e3701c442e231fabe6682cfd6cabf67432ecfa3c 100644 (file)
@@ -267,13 +267,18 @@ class Disk:
 
         return self._partitions
 
+    def _prop(self, name):
+        """Get path to the executable in a lazy way."""
+        aname = "_%s" % name
+        if getattr(self, aname) is None:
+            setattr(self, aname, find_executable(name, self.paths))
+            if not getattr(self, aname):
+                raise WicError("Can't find executable {}".format(name))
+        return getattr(self, aname)
+
     @property
     def mdir(self):
-        if self._mdir is None:
-            self._mdir = find_executable("mdir", self.paths)
-            if not self._mdir:
-                raise WicError("Can't find executable mdir")
-        return self._mdir
+        return self._prop('mdir')
 
     def _get_part_image(self, pnum):
         if pnum not in self.partitions: