""" A buildroot based on smart """ # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Library General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Copyright 2004 Dries Verachtert import getopt, os, sys, Queue, posix, posixpath, string, re, os.path, shutil, commands from log4py import Logger from buildroot import BuildRoot from buildrootresult import BuildRootResult import config #from specfile import SpecFile # import stuff: # -odata-dir=/var/lib/pydar2/smart/ / / # -orpm-root=/var/lib/pydar2/roots/ / -smart / # todo: how to change the dir /etc/smart/channels ? # still not finished, todo class SmartBasedBuildRoot(BuildRoot): def __init__(self,buildRootTag): self._cat = Logger().get_instance(self) brr = BuildRootResult(self) self.__config = config.Config.getInstance() self._setBuildRootTag( buildRootTag) self.__setVars(brr) self._cat.debug("initialized") self.__useCacheOnly = False #return brr def __setVars(self,brr): self.smartChannelsDir = "/etc/pydar2/smart/" + self.__config.getBuildMachineId() + "/" + self.getBuildRootTag() + "" if os.path.exists(self.smartChannelsDir): self._cat.debug("using userdefined smart channels dir: " + self.smartChannelsDir) else: self.smartChannelsDir = "/etc/pydar2/smart/" + self.getBuildRootTag() + "" self._cat.debug("using normal smart channels dir: " + self.smartChannelsDir) self.smartCacheDir = "/var/lib/pydar2/smart/cache/" + self.getBuildRootTag() self.rootdir = "/var/lib/pydar2/roots/smart-" + self.getBuildRootTag() self._setGeneralVars() brr.logDebugLine("rootdir:" + self.rootdir) def installRpms(self,builddepsarr): brr = BuildRootResult(self) # todo auto remove all deps which are already installed , not only perl if len(builddepsarr) > 0 and not (len(builddepsarr) == 1 and builddepsarr[0] == "perl"): commandpart = "" for b in builddepsarr: commandpart = commandpart + " " + b cacheParam = "" if self.__useCacheOnly: cacheParam = " -C " cmd = "sudo smart " + cacheParam + " --data-dir=" + self.smartCacheDir + " -orpm-root=" + self.rootdir + " install " + commandpart self.logCommand(cmd,brr) return brr # makes a new root def prepareRoot(self): brr = BuildRootResult(self) cmd = [] # create some directories first cmd.append("sudo mkdir -p " + self.rootdir + "/var/lib/rpm " + self.rootdir + "/var/log " + self.rootdir + "/var/cache " + self.rootdir + "/etc " + self.rootdir + "/proc " + self.rootdir + "/sys " + self.rootdir + "/usr/src/redhat/BUILD " + self.rootdir + "/usr/src/redhat/RPMS " + self.rootdir + "/usr/src/redhat/SOURCES " + self.rootdir + "/usr/src/redhat/SPECS " + self.rootdir + "/usr/src/redhat/SRPMS " + self.rootdir + "/dev/ " + self.rootdir + "/var/lib ") # copy fstab cmd.append("sudo cp /etc/fstab " + self.rootdir + "/etc") # mount proc cmd.append("sudo mount -t proc none " + self.rootdir + "/proc") # mount sys cmd.append("sudo mount -t sysfs none " + self.rootdir + "/sys") # create /dev/null cmd.append("sudo mknod " + self.rootdir + "/dev/null c 1 3") # rpm initdb cmd.append("sudo rpm --root=" + self.rootdir + " --initdb") # use a central yum cache cmd.append("sudo ln -s " + self.smartCacheDir + " " + self.rootdir + "/var/lib/smart") # install the rpms cacheParam = "" if self.__useCacheOnly: cacheParam = " -C " if self.minimalRpmsPart1 != "": cmd.append("sudo smart " + cacheParam + " --data-dir=" + self.smartCacheDir + " -orpm-root=" + self.rootdir + " install " + self.minimalRpmsPart1) if self.minimalRpmsPart2 != "": cmd.append("sudo smart " + cacheParam + " --data-dir=" + self.smartCacheDir + " -orpm-root=" + self.rootdir + " install " + self.minimalRpmsPart2) if self.minimalRpmsPart3 != "": cmd.append("sudo smart " + cacheParam + " --data-dir=" + self.smartCacheDir + " -orpm-root=" + self.rootdir + " install " + self.minimalRpmsPart3) if self.minimalRpmsPart4 != "": cmd.append("sudo smart " + cacheParam + " --data-dir=" + self.smartCacheDir + " -orpm-root=" + self.rootdir + " install " + self.minimalRpmsPart4) cmd.append("sudo chmod -R a+rwx " + self.rootdir + "/usr/src/redhat/ " + self.rootdir + "/home/pydar2slave ") self.logCommands(cmd,brr) return brr