""" Update info about spec files (from the svn repository) in a db """ # 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 # OLD CLASS, should not be used anymore.. moved partially to postgresqlstorage # Normally this runs on the master server. It checks the subversion # repository. # Probably implemented as: # every hour a cronjob starts which tries to do a svn update and checks which # files are changed. The information about those specfiles are updated in the # database. Information like 'exclusive archs' and 'authority' is also stored # so it's possible to check which specfile should be build for which # architecture. import re, os, commands, posix, posixpath, string, pgdb from log4py import Logger from svnwrapper import SvnWrapper from specfile import SpecFile class SvnCheck: def __init__(self): self.cat = Logger().get_instance(self) self.cat.debug("start") # not used anymore # the list of modified files is now checked with a checksum # only if the file is changed, the tags are updated in the database def check(self, svnSpecsDir,dbconnectstring): self.cat.debug("start, svnSpecsDir=" + svnSpecsDir) self.dbconnectstring = dbconnectstring self.dbconnection = pgdb.connect(self.dbconnectstring) # let's check every spec file we can find in the repository specsDirList = posix.listdir(svnSpecsDir) for specDir in specsDirList: fullRpmDir = posixpath.join(svnSpecsDir,specDir) if posixpath.isdir(fullRpmDir): fileList = posix.listdir(fullRpmDir) for file in fileList: rindex = string.rfind(file,'.spec') index2 = string.rfind(file,'rpmforge-') if index2 < 0 and rindex > 0 and rindex == len(file) - len('.spec'): self.cat.debug("spec match, file=" + file) self.checkSpecFile(specDir,fullRpmDir,file) # moved to __saveSpecRepositorySpecFileTags in postgresql storage def checkSpecFile(self,specDir,fullRpmDir,fileName): self.cat.debug("start,specDir="+specDir+",fullRpmDir="+fullRpmDir+",fileName="+fileName) # we're going to insert information about this spec file in the # database now # first get the current or a new specfileid specfileid = self.getCurrentOrNewDbSpecFileId(specDir,fullRpmDir,fileName) self.cat.debug("specfileid will be " + specfileid) currentcommitrevision = self.getCurrentCommitRevision(specDir,fullRpmDir,fileName) self.cat.debug("current commit revision is " + currentcommitrevision) alreadyImported = self.isRevInfoPresent(specfileid,currentcommitrevision) if alreadyImported: self.cat.debug("already imported in db") else: self.cat.debug("need to import all the variables..") self.insertSpecfileVersion(specfileid,currentcommitrevision) self.insertTags(specfileid, currentcommitrevision, 'fc3', specDir,fullRpmDir,fileName, ' --define "fc3 1"') self.insertTags(specfileid, currentcommitrevision, 'fc2', specDir,fullRpmDir,fileName, ' --define "fc2 1"') self.insertTags(specfileid, currentcommitrevision, 'fc1', specDir,fullRpmDir,fileName, ' --define "fc1 1"') self.insertTags(specfileid, currentcommitrevision, 'rh9', specDir,fullRpmDir,fileName, ' --define "rh9 1"') self.insertTags(specfileid, currentcommitrevision, 'rh8', specDir,fullRpmDir,fileName, ' --define "rh8 1"') self.insertTags(specfileid, currentcommitrevision, 'rh7', specDir,fullRpmDir,fileName, ' --define "rh7 1"') self.insertTags(specfileid, currentcommitrevision, 'rh6', specDir,fullRpmDir,fileName, ' --define "rh6 1"') self.insertTags(specfileid, currentcommitrevision, 'el3', specDir,fullRpmDir,fileName, ' --define "el3 1"') self.insertTags(specfileid, currentcommitrevision, 'el2', specDir,fullRpmDir,fileName, ' --define "el2 1"') # moved to __insertSpecRepositorySpecfileVersion in PostgresqlStorage def insertSpecfileVersion(self,specfileid,currentcommitrevision): cursor = self.dbconnection.cursor() cursor.execute("insert into pydar2_specfile_version (specfileid,svncmtrev) values (" + specfileid + "," + currentcommitrevision + ")") self.dbconnection.commit() cursor.close() # moved to __isSpecRepositorySpecFileVersionInfoPresent in PostgresqlStorage def isRevInfoPresent(self,specfileid,currentcommitrevision): cursor = self.dbconnection.cursor() cursor.execute("select * from pydar2_specfile_version where specfileid=" + specfileid + " and svncmtrev=" + currentcommitrevision) retval = 0 if cursor.rowcount > 0: retval = 1 cursor.close() return retval # moved to __insertSpecRepositorySpecFileTagsPerDistro in PostgresqlStorage def insertTags(self,specfileid,svncmtrev,distrocode,specDir,fullRpmDir,fileName,deftags): self.cat.debug("start,specfileid=" + specfileid + ",svncmtrev=" + svncmtrev + ",distrocode=" + distrocode) sf = SpecFile(fullRpmDir+"/"+fileName,deftags) cursor = self.dbconnection.cursor() for tag in sf.rpmforgetags: print 'rpmforge tag: ' + tag name = tag #print 'value: ' + sf.rpmforgetags[tag] value = string.replace(sf.rpmforgetags[tag],"'","''") value = string.rstrip(value,"\\") cursor.execute("insert into pydar2_specfile_tags (specfileid,svncmtrev,distroid,name,value) values (" + specfileid + "," + svncmtrev + ",(select id from pydar2_distro where code='" + distrocode + "'),'"+ name + "','" + value + "')") for tag in sf.standardtags: print 'standard tag: ' + tag name = tag # print 'value: ' + string.replace(sf.standardtags[tag],"'","''") value = string.replace(sf.standardtags[tag],"'","''") value = string.rstrip(value,"\\") cursor.execute("insert into pydar2_specfile_tags (specfileid,svncmtrev,distroid,name,value) values (" + specfileid + "," + svncmtrev + ",(select id from pydar2_distro where code='" + distrocode + "'),'"+ name + "','" + value + "')") self.dbconnection.commit() cursor.close() # ??? same function? def insertSpecFileVersion(self,specfileid,svncmtrev): cursor = self.dbconnection.cursor() cursor.execute("insert into pydar2_specfile_version (specfile,svncmtrev) values (" + specfileid + "," + svncmtrev + ")") self.dbconnection.commit() cursor.close() # moved to getSpecFileVersion in SvnBasedSpecRepository def getCurrentCommitRevision(self,specDir,fullRpmDir,fileName): self.cat.debug("start,specDir="+specDir+",fullRpmDir="+fullRpmDir+",fileName="+fileName) sw = SvnWrapper() sw.startTransaction() retval = sw.getLastCommitRev(fullRpmDir,fullRpmDir+"/"+fileName) sw.stopTransaction() return str(retval) # not used anymore def getCurrentOrNewDbSpecFileId(self,specDir,fullRpmDir,fileName): self.cat.debug("start,specDir="+specDir+",fullRpmDir="+fullRpmDir+",fileName="+fileName) cursor = self.dbconnection.cursor() cursor.execute("select id from pydar2_specfile where name='" + fileName + "'") if cursor.rowcount > 0: self.cat.debug("rowcount > 0") rs = cursor.fetchone() retval = rs[0] cursor.close() return str(retval) else: self.cat.debug("rowcount = 0") cursor.execute("insert into pydar2_specfile (name,path) values ('" + fileName + "','" + specDir + "/" + fileName + "')") self.dbconnection.commit() cursor.close() return self.getCurrentOrNewDbSpecFileId(specDir,fullRpmDir,fileName)