import os,sys import string from mod_python import apache, util import subprocess import time from syslog import * # baughj, 2007.07.06 - add logging, usage of subprocess # baughj, 2007.07.16 - make sure to chgrp/chmod checked out directory so that # it can be updated by wwwcvs user later - why doesn't everything (cron job, # etc) run as one user? # add new 'translation' type for translation team webspace, see RT #348523. # ward, 2008-08-18 CHECKOUT = "/var/www/savannah-checkouts/" LOGFILE = "/var/log/wwwcvs/new-savannah-project.log" def updatewww (): os.chdir ('/var/www/') os.environ["CVS_RSH"] = 'ssh' syslog(LOG_INFO,"Working...") try: cvs = subprocess.Popen(['/usr/bin/sudo','-u','wwwcvs','/usr/bin/cvs',"update", "-Pd", '.'], stdout=subprocess.PIPE, close_fds=True) except Exception, e: syslog(LOG_ERR,"Unknown exception occured in CVS update of /var/www") syslog(LOG_ERR,"Exception was: %s" % e) req.content_type = 'text/html' req.send_http_header() req.write("CVS update failed: %s" % e) return apache.OK # This is a blocking read syslog(LOG_INFO, cvs.stdout.read()) def handler (req): openlog('savannah-cvs-commit', 0, LOG_LOCAL6) syslog(LOG_INFO, "Request received...") form = util.FieldStorage (req) req.content_type = 'text/html' req.send_http_header () type = None project = None if form.has_key('type'): type = form['type'] if form.has_key('project'): project = form['project'] syslog(LOG_INFO, "type: %s" % type) syslog(LOG_INFO, "project: %s" % project) if (type == 'www'): syslog(LOG_INFO, "/var/www: Beginning checkout") updatewww() req.content_type = 'text/html' req.send_http_header () syslog(LOG_INFO, "/var/www: checkout done") return apache.OK if not (type and project): syslog(LOG_ERR, 'Error: missing type or project. Aborting.') return apache.HTTP_NOT_FOUND if (type != 'gnu') and (type != 'non-gnu') and (type != 'translations'): syslog(LOG_ERR, "Error: Type unknown, was %s. Aborting." % type) return apache.HTTP_NOT_FOUND if string.find (project, "/") != -1: syslog(LOG_ERR, "Error: / found in project name %s" % project) return apache.HTTP_NOT_FOUND syslog(LOG_INFO, "New/update project request: %s (%s)" % (type,project)) os.chdir (CHECKOUT + type) os.environ["CVS_RSH"] = 'ssh' try: syslog(LOG_INFO, "%s: Beginning checkout" % project) cvs = subprocess.Popen(['/usr/bin/sudo','-u','wwwcvs','/usr/bin/cvs',"-d",":pserver:address@hidden:/webcvs/%s" % project, "checkout", "-P", project], stdout=subprocess.PIPE, close_fds=True) except Exception, msg: syslog(LOG_ERR, "%s: Unknown exception occured in CVS subprocess (%s)" % (project,msg)) req.content_type = 'text/html' req.send_http_header() req.write("CVS checkout failed: %s" % msg) return apache.OK # This is a blocking read syslog(LOG_INFO, cvs.stdout.read()) syslog(LOG_INFO, "%s: CVS checkout completed." % project) #syslog(LOG_INFO, "%s: CVS checkout completed. Fixing permissions..." % project) #try: # retcode = subprocess.call(["/bin/chgrp", "-R", "wwwcvs", # "%s%s/%s" % (CHECKOUT, type, project)]) # retcode2 = subprocess.call(["/bin/chmod", "-R", "g+rw", # "%s%s/%s" % (CHECKOUT, type, project)]) # if (retcode, retcode2) != (0,0): # syslog(LOG_ERR, "%s: ERROR: chgrp returned %s" % (project,retcode)) # syslog(LOG_ERR, "%s: ERROR: chmod returned %s" % (project,retcode2)) #except Exception, e: # syslog(LOG_INFO, "error") # syslog(LOG_INFO, "%s: ERROR: %s" % (project,e)) #syslog(LOG_INFO, "%s: Permissions updated." % project) syslog(LOG_INFO, "%s: Complete." % project) req.content_type = 'text/html' req.send_http_header () #req.write ("cvs checkout complete") return apache.OK