""" Represents one spec file within a SpecRepository """ # 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 # a place holder for some values/information about 1 spec file in one of the SpecRepository objects # also calculates the SHA1 checksum so it is easy to check if a file is changed or not from log4py import Logger from specfiletags import SpecFileTags import sha, os import config class SpecRepositorySpecFile: def __init__(self, specRepository,subDir,fileName): self.__cat = Logger().get_instance(self) self.__specRepository = specRepository self.__subDir = subDir self.__fileName = fileName self.__checksum = self.__calculateCheckSum() self.__id = None self.rpmfilenames = [] self.srpmfilenames = [] self.binaryrpms = [] self.sourcerpms = [] #self.cat.debug("start, specRepositoryName=" + self.specRepositoryName + ",specRepositoryRootDir=" + self.specRepositoryRootDir + ",subDir=" + self.subDir + ",fileName=" + self.fileName) def getCheckSum(self): return self.__checksum # each version of a spec file should have a unique version # the version is defined by the SpecRepository def getVersion(self): return self.__specRepository.getSpecFileVersion(self) # construct an object which contains all the tags within this spec file # definetags is something like --define el4 1 or --define fc2 1 --define au1.92 1 def getSpecFileTags(self, definetags): return SpecFileTags(self.getFullPath(), definetags) def __calculateCheckSum(self): fullFileName = self.getFullPath() type = config.Config.getInstance().getCheckSumType() if type == "SHA": s = sha.new() f = open(fullFileName, 'r') line = f.readline() while line != '': s.update(line) line = f.readline() f.close() return s.hexdigest() else: return str(os.path.getmtime(fullFileName)) + "-" + str(os.path.getsize(fullFileName)) def getSpecRepository(self): return self.__specRepository def getSubDir(self): return self.__subDir def getFileName(self): return self.__fileName # the following should be unique within one specrepository!! def getPathFromRoot(self): return self.__subDir + '/' + self.__fileName def getFullPath(self): return self.__specRepository.getRootDirectory() + "/" + self.getPathFromRoot() def setId(self, newId): self.__id = newId def getId(self): return self.__id def toString(self): return "SpecRepositorySpecFile: subDir=" + str(self.getSubDir()) + ",fileName=" + str(self.getFileName()) + ",specRepository.name=" + str(self.getSpecRepository().getName())