Difference between revisions of "Iso prepare"

From SME Server
Jump to navigationJump to search
m (Protected "Iso prepare" (‎[edit=sysop] (indefinite) ‎[move=sysop] (indefinite)) [cascading])

Revision as of 10:54, 28 December 2014

PythonIcon.png Skill level: Developer
Risk of inconsistencies with Koozali SME Server methodology, upgrades & functionality is high. One must be knowledgeable about how changes impact their Koozali SME Server. Significant risk of irreversible harm.


iso_prepare the mock plugin needed for build an offical Iso see http://bugs.contribs.org/attachment.cgi?id=4059 and bugzilla:7675

# vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:textwidth=0:

# python library imports
import os
import stat
import glob

# our imports
from mockbuild.trace_decorator import decorate, traceLog, getLog

import mockbuild.util
from mockbuild.mounts import BindMountPoint

requires_api_version = "1.0"

# plugin entry point
decorate(traceLog())
def init(rootObj, conf):
   IsoPrepare(rootObj, conf)

# classes
class IsoPrepare(object):
   """fixes chroot do be able to build ISO's"""
   decorate(traceLog())
   def __init__(self, rootObj, conf):
       self.rootObj = rootObj
       self.isoPrepare_opts = conf
       rootObj.isoPrepareObj = self
       rootObj.addHook("postinit", self._isoPreparePostInitHook)
       for l in glob.glob("/dev/loop*"):
           rootObj.mounts.add(BindMountPoint(srcpath=l, bindpath=rootObj.makeChrootPath(l)))

   decorate(traceLog())
   def _isoPreparePostInitHook(self):
       # remove incorrect rpm db files
       if os.path.exists(self.rootObj.makeChrootPath('/usr/lib/rpm/rpmi')):
           for (dirpath, dirnames, filenames) in os.walk(self.rootObj.makeChrootPath('/var/lib/rpm')):
               for filename in filenames:
                   fullPath = os.path.join(dirpath, filename)
                   os.unlink(fullPath)

       # update sudoers file
       sudoers_out = self.rootObj.makeChrootPath('/etc/sudoers')
       sudoers = open(sudoers_out, 'a')
       sudoers.write( "%s ALL=(ALL) NOPASSWD: ALL\n" % self.rootObj.chrootuser )
       sudoers.write( "Defaults:mockbuild !requiretty\n" )
       sudoers.close()