#!/usr/bin/python # kate: tab-width 4; indent-width 4; space-indent on; """ Contains some settings for pydar """ # 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 ConfigParser, os, posixpath, sys sys.path.append("pydar") sys.path.append(".") from specrepository import SpecRepository from specrepositoryfactory import SpecRepositoryFactory from specrepositorylist import SpecRepositoryList from commandlist import CommandList from filter import Filter from log4py import Logger from targetlist import TargetList from target import Target from preparespecfilescript import PrepareSpecFileScript from acceptcommandscript import AcceptCommandScript from updatesitescript import UpdateSiteScript from movecommandresultsscript import MoveCommandResultsScript from buildrootlist import BuildRootList from filepathscript import FilePathScript import yumbasedbuildroot import rsyncyumbasedbuildroot import storagefactory import smartbasedbuildroot class Config: __myInstance = None __fullInitMasterDone = False __withinFullInitMaster = False __fullInitSlaveDone = False __withinFullInitSlave = False __fullInitMasterUpdateDone = False __withinFullInitMasterUpdate = False __fullInitClientDone = False __withinFullInitClient = False def specifyGetOptOptions(self,options): self.__getOptOptions = options def __init__(self): if Config.__myInstance != None: raise Exception("use Config.getInstance()") self.__cat = Logger().get_instance(self) Config.__myInstance = self def getInstance(cls): if cls.__myInstance == None: unused = Config() return cls.__myInstance getInstance = classmethod(getInstance) # only used in master def getSpecReposRootDir(self): self.__fullInitMaster() return self.__specreposrootdir # only used in master def getPostgresqlConnectString(self): self.__fullInitMaster() # @todo return self.__dbconnectstring def __fullInitMasterUpdate(self): if Config.__fullInitMasterUpdateDone or Config.__withinFullInitMasterUpdate: return Config.__withinFullInitMasterUpdate = True self.__cat.debug("start") # only used by the MasterUpdate program # the userid which is used by the pydar-master-update.py program self.__cat.warn("todo parse config file") self.__updateUserId = 0 __withinFullInitMasterUpdate = False __fullInitMasterUpdateDone = True self.__cat.debug('end') def getBuildMasterHostname(self): self.__fullInitMaster() return self.__buildmasterhostname def getBuildMasterPort(self): self.__fullInitMaster() return self.__buildmasterport def getMaxAutoQueueCount(self): self.__fullInitMaster() return self.__maxautoqueuecount def getCheckSumType(self): self.__fullInitMaster() return self.__checksumtype def doCheckMissingTagsPerDistro(self): self.__fullInitMaster() return self.__doCheckMissingTagsPerDistro def __fullInitMaster(self): if Config.__fullInitMasterDone or Config.__withinFullInitMaster: return Config.__withinFullInitMaster = True self.__cat.debug("start") myParser = ConfigParser.ConfigParser() # start with default values that can be overridden in config files myParser.add_section('master') myParser.set('master', 'smtpserver','127.0.0.1') myParser.set('master', 'mailfrom','pydar2master@localhost.localdomain') myParser.set('master', 'specreposrootdir','/var/lib/pydar2/specrepos') myParser.readfp(open('/etc/pydar2/master.conf')) myParser.read([ os.path.expanduser('~/.pydar2/master.conf')]) if self.__getOptOptions.masterconfig != None: self.__cat.debug("options.masterconfig is " + self.__getOptOptions.masterconfig) myParser.read([ self.__getOptOptions.masterconfig]) self.__buildmasterhostname = myParser.get('master','buildmasterhostname') self.__buildmasterport = myParser.getint('master','buildmasterport') self.__dbconnectstring = myParser.get('master','dbconnectstring') self.__maxautoqueuecount = 20 if myParser.has_option('master','maxautoqueuecount'): self.__maxautoqueuecount = myParser.get('master','maxautoqueuecount') self.__checksumtype = "SHA" if myParser.has_option('master','checksumtype'): self.__checksumtype = myParser.get('master','checksumtype') if myParser.has_option('master','checkmissingtagsperdistro'): if myParser.get('master','checkmissingtagsperdistro') != "0": self.__doCheckMissingTagsPerDistro = True else: self.__doCheckMissingTagsPerDistro = False else: self.__doCheckMissingTagsPerDistro = False # self.__mailfrom = myParser.get('master','mailfrom') self.__smtpserver = myParser.get('master','smtpserver') self.__specreposrootdir = myParser.get('master','specreposrootdir') self.__specRepositoryList = SpecRepositoryList() self.__commandList = CommandList() self.__targetList = TargetList() # get the specrepositories srf = SpecRepositoryFactory.getInstance() myParser = ConfigParser.ConfigParser() myParser.readfp(open('/etc/pydar2/specrepositories.conf')) for i in myParser.sections(): name=i type=myParser.get(name,'type') fulldir=myParser.get(name,'fulldir') sr = srf.createSpecRepository(name,type,fulldir) if myParser.has_option(name,'filterscript') and myParser.has_option(name,'filterfunction'): sr.appendSpecRepositorySpecFileFilter(Filter(myParser.get(name,'filterscript'),myParser.get(name,'filterfunction'))) if myParser.has_option(name,'preparescript') and myParser.has_option(name,'preparefunction'): sr.appendPrepareSpecFileScript(PrepareSpecFileScript(myParser.get(name,'preparescript'),myParser.get(name,'preparefunction'))) if myParser.has_option(name,'updatesitescript') and myParser.has_option(name,'updatesitefunction'): sr.setUpdateSiteScript(UpdateSiteScript(myParser.get(name,'updatesitescript'),myParser.get(name,'updatesitefunction'))) if myParser.has_option(name,'acceptcommandscript') and myParser.has_option(name,'acceptcommandfunction'): sr.setAcceptCommandScript(AcceptCommandScript(myParser.get(name,'acceptcommandscript'),myParser.get(name,'acceptcommandfunction'))) self.__cat.debug('going to add: ' + name) self.getSpecRepositoryList().add(sr) # should this become options? self.__savespecrepositoryspecfiletags = True self.__masterwebroot = '/var/lib/pydar2/masterwebroot' # get the targets myParser = ConfigParser.ConfigParser() myParser.readfp(open('/etc/pydar2/targets.conf')) for i in myParser.sections(): name=i t = Target(name) if myParser.has_option(name,'rpmsdir'): t.setRpmsDir(myParser.get(name,'rpmsdir')) if myParser.has_option(name,'getrpmdatascript') and myParser.has_option(name,'getrpmdatafunction'): t.setGetRpmDataScript(FilePathScript(myParser.get(name,'getrpmdatascript'),myParser.get(name,'getrpmdatafunction'))) if myParser.has_option(name,'movecommandresultsscript') and myParser.has_option(name,'movecommandresultsfunction'): self.__cat.debug('movecommandresultsscript & function ok') t.setMoveCommandResultsScript(MoveCommandResultsScript(myParser.get(name,'movecommandresultsscript'),myParser.get(name,'movecommandresultsfunction'))) if myParser.has_option(name,'preparescript') and myParser.has_option(name,'preparefunction'): t.appendPrepareSpecFileScript(PrepareSpecFileScript(myParser.get(name,'preparescript'),myParser.get(name,'preparefunction'))) if myParser.has_option(name,'acceptcommandscript') and myParser.has_option(name,'acceptcommandfunction'): t.setAcceptCommandScript(AcceptCommandScript(myParser.get(name,'acceptcommandscript'),myParser.get(name,'acceptcommandfunction'))) self.getTargetList().addTarget(t) # setup the accounts myParser = ConfigParser.ConfigParser() myParser.readfp(open('/etc/pydar2/accounts.conf')) st = storagefactory.StorageFactory.getStorage() st.clearAssignedRights() for i in myParser.sections(): name=i type=myParser.get(name,'type') fullname=myParser.get(name,'fullname') passw=myParser.get(name,'password') cnt = 0 rights=[] while myParser.has_option(name, 'right' + str(cnt)): rights.append(myParser.get(name,'right' + str(cnt))) cnt = cnt + 1 st.addAccount(name,type,fullname,passw,rights) self.__masterBuildResultsDir = '/var/lib/pydar2/masterbuildresults/' #oldstuff #sr = srf.createSpecRepository("rpmforge",SpecRepository.TYPE_SVN,self.__specreposrootdir + "/rpmforge/rpms") # we add a filter so the spec templates used by rpmforge are not stored in the database #sr.appendSpecRepositorySpecFileFilter(Filter("pydar/norpmforgetemplatesfilter","NoRpmforgeTemplatesFilter")) #sr.appendPrepareSpecFileScript(PrepareSpecFileScript("pydar/rpmforgegetsources","RpmforgeGetSources")) #sr = SpecRepository("pld",SpecRepository.TYPE_CVS,self.specreposrootdir + "/pld/SPECS") #sr = srf.createSpecRepository("pld",SpecRepository.TYPE_CVS,self.__specreposrootdir + "/pld/SPECS") #self.getSpecRepositoryList().add(sr) # #sr = SpecRepository("fedoraextrasdevel",SpecRepository.TYPE_CVS,self.specreposrootdir + "/fedoraextrasdevel") # #self.specrepositories.append(sr) #sr = SpecRepository("local",SpecRepositoryFactory.TYPE_FILES,self.specreposrootdir + "/local") #sr = srf.createSpecRepository("local",SpecRepository.TYPE_FILES,self.__specreposrootdir + "/local") #self.getSpecRepositoryList().add(sr) __withinFullInitMaster = False __fullInitMasterDone = True self.__cat.debug('end') def getMasterBuildResultsDir(self): self.__fullInitMaster() return self.__masterBuildResultsDir def getSlaveAttachBuildLog(self): self.__fullInitSlave() return self.__slaveAttachBuildLog def getSlaveFromEmail(self): self.__fullInitSlave() return self.__slaveFromEmail def __fullInitSlave(self): if Config.__fullInitSlaveDone or Config.__withinFullInitSlave: return Config.__withinFullInitSlave = True self.__cat.debug("start") myParser = ConfigParser.ConfigParser() # start with default values that can be overridden in config files myParser.add_section('slave') myParser.set('slave', 'slavedataroot', '/var/lib/pydar2/slavedataroot') myParser.set('slave', 'mastercommandswebsite', 'http://pydarmaster') myParser.set('slave', 'sleeptime', '300') myParser.set('slave', 'smtpserver','127.0.0.1') myParser.set('slave', 'mailfrom','pydar2slave@localhost.localdomain') if self.__getOptOptions.slaveconfig != None: self.__cat.debug("options.slaveconfig is " + self.__getOptOptions.slaveconfig) myParser.read(['/etc/pydar2/slave.conf',os.path.expanduser('~/.pydar2/slave.conf'), self.__getOptOptions.slaveconfig]) else: myParser.read(['/etc/pydar2/slave.conf',os.path.expanduser('~/.pydar2/slave.conf')]) #self.__buildslavehostname = myParser.get('slave','buildslavehostname') #self.__buildslaveport = myParser.getint('slave','buildslaveport') self.__buildmachineid = myParser.get('slave','buildmachineid') self.__buildmasterurlslave = myParser.get('slave','buildmasterurl') self.__slavepassword = myParser.get('slave','password') # TODO: rewrite to use only one of the next too self.__slaveFromEmail = myParser.get('slave','mailfrom') self.__mailfrom = myParser.get('slave','mailfrom') self.__slaveAttachBuildLog = myParser.get('slave','attachbuildlog') # get the supported distro + arch strings like fc3-i386 self.__buildRootList = BuildRootList() # currently allow 2 ways for specifying buildroots: # 1. a section 'distroarchs' with the names of the distroarchs # default will be a RsyncYumBasedBuildRoot # 2. a section for each buildroot so you can add options if myParser.has_section('distroarchs'): for key in myParser.options('distroarchs'): # todo also get a lot of options about each buildroot tmp = rsyncyumbasedbuildroot.RsyncYumBasedBuildRoot(myParser.get('distroarchs',key)) tmp.setUseCacheOnly(False) self.__buildRootList.addBuildRoot(tmp) for sect in myParser.sections(): if sect != "distroarchs" and sect != "slave": type = "RSYNCYUM" onlyusecache = "0" if myParser.has_option(sect, 'type'): type = myParser.get(sect,'type') if myParser.has_option(sect, 'onlyusecache'): onlyusecache = myParser.get(sect,'onlyusecache') tmp = None if type == "RSYNCYUM": tmp = rsyncyumbasedbuildroot.RsyncYumBasedBuildRoot(sect) if type == "YUM": tmp = yumbasedbuildroot.YumBasedBuildRoot(sect) if type == "SMART": tmp = smartbasedbuildroot.SmartBasedBuildRoot(sect) if tmp == None: self.__cat.error("unknown type for buildarch: " + sect) else: tmp.setUseCacheOnly(onlyusecache) self.__buildRootList.addBuildRoot(tmp) self.__slavedataroot = myParser.get('slave','slavedataroot') self.__mastercommandswebsite = myParser.get('slave','mastercommandswebsite') self.__sleeptime = myParser.getint('slave','sleeptime') self.__smtpserver = myParser.get('slave','smtpserver') __withinFullInitSlave = False __fullInitSlaveDone = True self.__cat.debug('end') def __fullInitClient(self): if Config.__fullInitClientDone or Config.__withinFullInitClient: return Config.__withinFullInitClient = True self.__cat.debug("start") myParser = ConfigParser.ConfigParser() # start with default values that can be overridden in config files myParser.add_section('client') myParser.set('client', 'smtpserver','127.0.0.1') myParser.set('client', 'mailfrom','pydar2client@localhost.localdomain') if self.__getOptOptions.clientconfig != None: self.__cat.debug("options.clientconfig is " + self.__getOptOptions.clientconfig) myParser.read(['/etc/pydar2/client.conf',os.path.expanduser('~/.pydar2/client.conf'), self.__getOptOptions.clientconfig]) else: myParser.read(['/etc/pydar2/client.conf',os.path.expanduser('~/.pydar2/client.conf')]) self.__buildmasterurlclient = myParser.get('client','buildmasterurl') self.__clientpassword = myParser.get('client','password') self.__clientuserid = myParser.get('client','userid') self.__smtpserver = myParser.get('client','smtpserver') self.__mailfrom = myParser.get('client','mailfrom') __withinFullInitClient = False __fullInitClientDone = True self.__cat.debug('end') # must be able to respond to this function without a loaded Storage instance! # @TODO def getStorageType(self): #self.__fullInit() return 1; def callUpdateSiteScript(self,userId,specRepoName): self.__fullInitMaster() def getSlavePassword(self): self.__fullInitSlave() return self.__slavepassword def getClientUserId(self): self.__fullInitClient() return self.__clientuserid # FIXME: As I see it thus far the config can be one of # client, slave, or master and it is redundant # to define separate accessors for each since # the determination is made intially by the # calling script, and also I when I needed to make # this change I wasn't 100% sure if I was under a client or master # script, so I am going to gamble that config initalization # has been completed before needing to send mail # I think the best final solution is have the initial daemon # script call an initialization method and eliminate a lot of code # and confusion def getSmtpServer(self): #self.__fullInitSlave() return self.__smtpserver def getFromEmail(self): return self.__mailfrom def getClientPassword(self): self.__fullInitClient() return self.__clientpassword def getSpecRepositoryList(self): self.__fullInitMaster() return self.__specRepositoryList def getCommandList(self): self.__fullInitMaster() return self.__commandList def getTargetList(self): self.__fullInitMaster() return self.__targetList def getSaveSpecRepositorySpecFileTags(self): self.__fullInitMaster() return self.__savespecrepositoryspecfiletags def getBuildMasterUrlSlave(self): self.__fullInitSlave() return self.__buildmasterurlslave def getBuildMasterUrlClient(self): self.__fullInitClient() return self.__buildmasterurlclient def getUpdateUserId(self): self.__fullInitMasterUpdate() return self.__updateUserId def getDistroArchTags(self): self.__fullInitSlave() return self.getBuildRootList().getDistroArchTags() def getBuildRootList(self): self.__fullInitSlave() return self.__buildRootList # only used by the slave def getBuildMachineId(self): self.__fullInitSlave() return self.__buildmachineid # only used by the slave def getSleepTime(self): self.__fullInitSlave() return self.__sleeptime # only used by the master def getMasterWebRoot(self): self.__fullInitMaster() return self.__masterwebroot # only used by the slave (i think) def getSlaveDataRoot(self): self.__fullInitSlave() return self.__slavedataroot # only used by the slave def getMasterCommandsWebSite(self): self.__fullInitSlave() return self.__mastercommandswebsite