[PATCH 1/2] Add installimg command for use in the templates

Brian C. Lane bcl at redhat.com
Wed Nov 5 03:23:31 UTC 2014


installimg SRCDIR DESTFILE
  Create a compressed cpio archive of the contents of SRCDIR and place
  it in DESTFILE.

  If SRCDIR doesn't exist or is empty nothing is created.

Examples:
  installimg ${LORAXDIR}/product/ images/product.img
---
 src/pylorax/ltmpl.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py
index 030b9ca..88d02dd 100644
--- a/src/pylorax/ltmpl.py
+++ b/src/pylorax/ltmpl.py
@@ -31,6 +31,7 @@ from pylorax.sysutils import joinpaths, cpfile, mvfile, replace, remove
 from pylorax.yumhelper import LoraxDownloadCallback, LoraxTransactionCallback, LoraxRpmCallback
 from pylorax.base import DataHolder
 from pylorax.executils import runcmd, runcmd_output
+from pylorax.imgutils import mkcpio
 
 from mako.lookup import TemplateLookup
 from mako.exceptions import text_error_template
@@ -233,6 +234,23 @@ class LoraxTemplateRunner(object):
         for src in rglob(self._in(srcglob), fatal=True):
             cpfile(src, self._out(dest))
 
+    def installimg(self, srcdir, destfile):
+        '''
+        installimg SRCDIR DESTFILE
+          Create a compressed cpio archive of the contents of SRCDIR and place
+          it in DESTFILE.
+
+          If SRCDIR doesn't exist or is empty nothing is created.
+
+          Examples:
+            installimg ${LORAXDIR}/product/ images/product.img
+            installimg ${LORAXDIR}/updates/ images/updates.img
+        '''
+        if not os.path.isdir(self._in(srcdir)) or os.listdir(self._in(srcdir)) == 0:
+            return
+        logger.info("Creating image file %s from contents of %s", self._out(destfile), self._in(srcdir))
+        mkcpio(self._in(srcdir), self._out(destfile))
+
     def mkdir(self, *dirs):
         '''
         mkdir DIR [DIR ...]
-- 
1.9.3



More information about the anaconda-patches mailing list