""" Update a subversion checkout """ # 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 # This class can be used for updating a local checkout of a # subversion repository # Using a callback (so you know which files are updated) does not work import svn.wc, svn.client, svn.core import atexit from log4py import Logger # Some notes: # if your svn server uses ssl and the certificate isn't signed # by a trusted CA, then you have to add this certificate # to the list of trusted certificates # If you don't, it doesn't work :) # Get the pem certificate: # openssl s_client -showcerts -connect svn.rpmforge.net:443 # copy the certificate to a file, the certificate consists of some # lines beginning with the line '-----BEGIN CERTIFICATE-----' and # ending with the line '-----END CERTIFICATE-----' # Configure subversion to use this pem file: edit ~/.subversion/servers # and add a line like: # ssl-authority-files = /some/path/svn.rpmforge.net.pem # You need to add it to the section of your server. For example: # [groups] # rpmforge = *.rpmforge.net # # [rpmforge] # ssl-authority-files = /home/dries/.subversion/svn.rpmforge.net.pem # If you need to debug ssl/connection problems: # add the following to the section of your server: # neon-debug-mask = 511 # http-compression = no class SvnWrapper: def __init__(self): self.cat = Logger().get_instance(self) self.cat.debug("start") self.transStarted = 0 def startTransaction(self): self.cat.debug("start") if self.transStarted == 0: svn.core.apr_initialize() self.pool = svn.core.svn_pool_create(None) self.transStarted = 1 atexit.register(svn.core.apr_terminate) else: self.cat.warn("transaction already started") def stopTransaction(self): self.cat.debug("start") if self.transStarted == 1: svn.core.svn_pool_destroy(self.pool) svn.core.apr_terminate() self.transStarted = 0 else: self.cat.warn("transaction not yet started") def updateLocalCopy(self, svndir): self.cat.debug("start") myContext = svn.client.svn_client_ctx_t() self.cat.debug("myContext=" + str(myContext)) myContext.config = svn.core.svn_config_get_config(None, self.pool) #self.cat.debug("result of config: " + str(configResult)) provider = svn.client.svn_client_get_simple_provider(self.pool) myContext.auth_baton = svn.core.svn_auth_open([provider], self.pool) myRevision = svn.core.svn_opt_revision_t() self.cat.debug("myRevision=" + str(myRevision)) myRevision.kind = svn.core.svn_opt_revision_head result = svn.client.svn_client_update(svndir,myRevision, 1,myContext, self.pool) self.cat.debug("result of update=" + str(result)) def update_callback(self): self.cat.debug("start") # changed! # now -1 is returned if it is not within svn def getLastCommitRev(self,dirpath,fullpath): #if dirpath[len(dirpath)-1] == "/": # self.cat.debug("removing last '/'") # dirpath = dirpath[0:len(dirpath)-2] #else: # self.cat.debug("last char:" + dirpath[len(dirpath)-1]) self.cat.debug("start,dirpath=" + dirpath + ",fullpath="+fullpath) try: adm_baton = svn.wc.svn_wc_adm_open(None,dirpath,False,True,self.pool) entry = svn.wc.svn_wc_entry(fullpath,adm_baton,0,self.pool) self.cat.debug("entry: " + str(entry)) self.cat.debug("cmtRev: " + str(entry.cmt_rev)) svn.wc.svn_wc_adm_close(adm_baton) return entry.cmt_rev except: self.cat.debug("problem, probably not in svn") return -1 # tocheck: http://svn.slog.dk/repos/+svn/py/util.py # http://www.contactor.se/~dast/svn/archive-2002-12/0234.shtml # http://www.24svn.org/doc/srcdoc/svncpp/html/functions.html # http://www.endrun.org/xr/svn/source/tools/examples/check-modified.py # http://dan.drydog.com/docs/redhat/subversion-0.17.1/tools/examples/geturl.py # http://dan.drydog.com/docs/redhat/subversion-0.17.1/tools/examples/check-modified.py # http://www.linuxdevcenter.com/pub/a/linux/2003/04/24/libsvn1.html?page=2