in scripts/cronjobs/pubsubber.py [0:0]
def run(self):
logger.info("Watching %s", watching)
while True:
self.req = None
while not self.req:
try:
if version == 3:
self.req = urllib.request.urlopen(self.url, None, 30)
else:
self.req = urllib2.urlopen(self.url, None, 30)
logger.info("Connected to %s", self.url)
except:
logger.warn("Failed to connect to %s", self.url)
time.sleep(30)
continue
for line in read_chunk(self.req):
if version == 3:
line = str( line, encoding='ascii' ).rstrip('\r\n,').replace('\x00','') # strip away any old pre-0.9 commas from gitpubsub chunks and \0 in svnpubsub chunks
else:
line = str( line ).rstrip('\r\n,').replace('\x00','') # strip away any old pre-0.9 commas from gitpubsub chunks and \0 in svnpubsub chunks
try:
obj = json.loads(line)
if "commit" in obj and "repository" in obj['commit']:
# If it's our public svn repo, then...
if obj['commit']['repository'] == "13f79535-47bb-0310-9956-ffa450edef68":
#Grab some vars
commit = obj['commit']
# e.g. {"committer": "sebb", "log": "Ensure we exit on control+C", "repository": "13f79535-47bb-0310-9956-ffa450edef68", "format": 1,
# "changed": {"comdev/reporter.apache.org/trunk/scandist.py": {"flags": "U "}},
# "date": "2015-07-13 13:38:33 +0000 (Mon, 13 Jul 2015)", "type": "svn", "id": 1690668}
svnuser = commit['committer']
revision = commit['id']
filePaths = set()
# e.g. {"comdev/reporter.apache.org/trunk/scandist.py": {"flags": "U "}}
for path in commit['changed']:
for watchPath in watching:
# Check if the commit is for our part of the repo
match = re.match("^%s" % watchPath, path)
if match:
filePath = str(watching[watchPath])
if debug:
print("Matched '" + path + "' against '" + watchPath + "'; would run 'svn up " + filePath + "'")
filePaths.update(watching[watchPath])
if filePaths:
for filePath in filePaths:
if debug:
print("Matched 'r" + str(revision) + "'; would run 'svn up " + filePath + "'")
else:
time.sleep(3)
logger.info("svn up %s", filePath)
subprocess.call(['svn','up', filePath])
else:
logger.debug("Did not match 'r" + str(revision) + "' against ' " + str(watching.keys()) + "'")
if debug:
print("Did not match 'r" + str(revision) + "' against ' " + str(watching.keys()) + "'")
except ValueError as detail:
continue