""" This class contains all the functions for storing stuff in memory """ # 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 from command import Command from log4py import Logger import pgdb, posixpath, posix, string from storage import Storage # needs to be rewritten so it uses only arrays/hashes class MemoryStorage(Storage): def __init__(self): self.__cat = Logger().get_instance(self) self.__cat.debug("initialized") self.specrepos = [] # an array of the real specrepository objects self.targets = [] # an array of the real target objects self.userIdToRightsArr = {} self.accounts = {} # for each acc: # name => [ # 'name' => name # 'type' => type like USER or BUILDMACHINE # 'fullname' => fullname # 'passw' => password # 'rights'] => array of abbreviations from class Rights self.specfiles = {} # for each specfile # id => [ # 'id' => a unique id # 'subdir' => subdir # 'filename' => filename # 'specrepoid' => id of the specrepo # 'checksum'=> the checksum of the spec file # ] self.buildmachineregistrations = {} # id => { # 'id' => unique buildmachineid # 'distroarchtags' => array of distroarchtags # ] self.commands = {} # id => [ # 'id'] => a unique id (commandId) # 'specfileid'=> # 'specrepoid'=> # 'toemail' # 'distroarchtag' # 'targetid' # 'commandname' # 'userid' # 'priority' # 'version' # 'inprogress' = 0 of 1 # 'handled'= 0 of 1 # ] def saveSpecRepository(self,specRepo): self.specrepos.append(specRepo) def createCommand(self,aCommand): cmdobj = {} cmdobj['id'] = len(self.commands) + 1 cmdobj['commandname'] = aCommand.getCommandName() cmdobj['userid'] = aCommand.getUserId() cmdobj['specrepoid'] = aCommand.getSpecRepoId() cmdobj['specfileid'] = aCommand.getSpecFileId() cmdobj['toemail'] = aCommand.getToEmail() cmdobj['distroarchtag'] = aCommand.getDistroArchTag() cmdobj['priority'] = aCommand.getPriority() cmdobj['targetid'] = aCommand.getTargetId() cmdobj['version'] = 0 cmdobj['handled'] = 0 cmdobj['inprogress'] = 0 self.commands[cmdobj['id']] = cmdobj aCommand.setId(cmdobj['id']) return aCommand def checkIfValidUserId(self, userId, password, right): for i in self.accounts.values(): self.__cat.debug("acc value: " + str(i)) if i['name'] == userId and i['type'] == 'USER' and i['passw'] == password: self.__cat.debug("type and password ok") if right in i['rights']: self.__cat.debug("right also ok") return 1 self.__cat.debug("not found..") return 0 def checkIfValidBuildMachineId(self, buildmachineid, password, right): for i in self.accounts.values(): self.__cat.debug("acc value: " + str(i)) if i['name'] == buildmachineid and i['type'] == 'BUILDMACHINE' and i['passw'] == password: self.__cat.debug("type and password ok") if right in i['rights']: self.__cat.debug("right also ok") return 1 self.__cat.debug("not found..") return 0 def updateTarget(self, newTarget): self.targets.append(newTarget) def registerSlave(self, buildmachineid): bmobj = {} bmobj['id'] = buildmachineid bmobj['distroarchtags'] = [] self.buildmachineregistrations[buildmachineid] = bmobj def addDistroArchTag(self, buildmachineid, distroArchTag): obj = self.buildmachineregistrations[buildmachineid] obj['distroarchtags'].append(distroArchTag) def reserveCommand(self, buildmachineid): for i in self.commands.values(): if i['inprogress'] == 0 and i['handled'] == 0 and i['distroarchtag'] in self.buildmachineregistrations[buildmachineid]['distroarchtags']: aCommand = MasterCommand(i['commandname'], i['userid'], i['specrepoid'], i['specfileid'], i['toemail'], i['distroarchtag'], i['priority'], i['targetid']) aCommand.setVersion(i['version']) aCommand.setCommandId(i['id']) i['inprogress'] = 1 return aCommand return "" def clearAssignedRights(self): self.userIdToRightsArr = {} def saveSpecRepositorySpecFile(self, specRepo, specRepoSpecFile): specobj = {} specobj['id'] = specRepoSpecFile.getId() specobj['subdir'] = specRepoSpecFile.getSubDir() specobj['filename'] = specRepoSpecFile.getFileName() specobj['specrepoid'] = specRepo.getId() specobj['checksum'] = specRepoSpecFile.getCheckSum() self.specfiles[specRepoSpecFile.getId()] = specobj def addAccount(self,name,type,fullname,passw,rights): acc = {} acc['name'] = name acc['type'] = type acc['fullname'] = fullname acc['passw'] = passw acc['rights'] = rights self.accounts[name] = acc self.userIdToRightsArr[name] = rights def getSpecRepositoryFileListToIds(self,specRepo): retval = {} for i in self.specfiles.values(): if i['specrepoid'] == specRepo.getId(): retval[i['subdir'] + '/' + i['filename']] = i['id'] return retval def getSpecRepositoryFileListToChecksum(self,specRepo): retval = {} for i in self.specfiles.values(): if i['specrepoid'] == specRepo.getId(): retval[i['subdir'] + '/' + i['filename']] = i['checksum'] return retval