Iso prepare

From SME Server
Revision as of 10:50, 28 December 2014 by Stephdl (talk | contribs) (Created page with "{{Level|Developer}} # vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=python:textwidth=0: # python library imports import os import stat import glob # our i...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
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.


# 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()