def pushtrigger(self, reponame, username):
print "Firing push trigger for repository '%s', due to push by %s" % (reponame, username)
+
+
+import httplib
+
+class varnishpurger(object):
+ """
+ Push trigger that purges repositories from varnish. The idea being that
+ the repositories follow a standard gitweb url structure, and we purge
+ all pages related to that repository.
+
+ Requires the config variable "host" set in the section "varnishpurge".
+ This can be an IP address (typically 127.0.0.1) or IP address + port
+ (typically 127.0.0.1:81). The trigger will always post to the URL
+ "/varnish-purge-url", and will include the URL to purge in the form of
+ a regular expression in the custom header X-Purge-URL.
+ """
+ def __init__(self, cfg):
+ self.host = cfg.get('varnishpurge', 'host')
+
+ def pushtrigger(self, reponame, username):
+ # Make a callback to a local varnish server to purge a repository
+ # from it. Assumes gitweb style URLs.
+ for u in ['^/gitweb$', '^/gitweb/?p=%s.git' % reponame]:
+ if not self._internal_purge(u):
+ print "Varnish purge failed, website may become slightly out of date"
+ return
+
+
+ def _internal_purge(self, url):
+ try:
+ conn = httplib.HTTPConnection(self.host)
+ conn.request("GET", "/varnish-purge-url", '', {'X-Purge-URL': url})
+ resp = conn.getresponse()
+ conn.close()
+ if resp.status == 200:
+ return True
+ return False
+ except Exception, ex:
+ return False