Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.

Commit

Permalink
nobug: PEP8! r=bitrotallthethings
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris AtLee committed Jan 22, 2013
1 parent 2f333c2 commit 62ff0b1
Show file tree
Hide file tree
Showing 50 changed files with 4,621 additions and 3,615 deletions.
47 changes: 30 additions & 17 deletions bin/hgpoller.py
@@ -1,16 +1,22 @@
#!/usr/bin/env python #!/usr/bin/env python
import urlparse, urllib, time import urlparse
import urllib
import time
try: try:
import json import json
except: except:
import simplejson as json import simplejson as json


import httplib, urllib2, socket, ssl import httplib
import urllib2
import socket
import ssl


import subprocess import subprocess
from buildbotcustom.changes.hgpoller import _parse_changes from buildbotcustom.changes.hgpoller import _parse_changes
import logging as log import logging as log



def buildValidatingOpener(ca_certs): def buildValidatingOpener(ca_certs):
class VerifiedHTTPSConnection(httplib.HTTPSConnection): class VerifiedHTTPSConnection(httplib.HTTPSConnection):
def connect(self): def connect(self):
Expand Down Expand Up @@ -45,6 +51,7 @@ def https_open(self, req):


return url_opener return url_opener



def validating_https_open(url, ca_certs, username=None, password=None): def validating_https_open(url, ca_certs, username=None, password=None):
url_opener = buildValidatingOpener(ca_certs) url_opener = buildValidatingOpener(ca_certs)
req = urllib2.Request(url) req = urllib2.Request(url)
Expand All @@ -55,17 +62,18 @@ def validating_https_open(url, ca_certs, username=None, password=None):
req.add_header("Authorization", "Basic %s" % pw) req.add_header("Authorization", "Basic %s" % pw)
return url_opener.open(req) return url_opener.open(req)



def getChanges(base_url, last_changeset=None, tips_only=False, ca_certs=None, def getChanges(base_url, last_changeset=None, tips_only=False, ca_certs=None,
username=None, password=None): username=None, password=None):
bits = urlparse.urlparse(base_url) bits = urlparse.urlparse(base_url)
if bits.scheme == 'https': if bits.scheme == 'https':
assert ca_certs, "you must specify ca_certs" assert ca_certs, "you must specify ca_certs"


params = [('full', '1')] params = [('full', '1')]
if last_changeset: if last_changeset:
params.append( ('fromchange', last_changeset) ) params.append(('fromchange', last_changeset))
if tips_only: if tips_only:
params.append( ('tipsonly', '1') ) params.append(('tipsonly', '1'))
url = "%s/json-pushes?%s" % (base_url, urllib.urlencode(params)) url = "%s/json-pushes?%s" % (base_url, urllib.urlencode(params))


log.debug("Fetching %s", url) log.debug("Fetching %s", url)
Expand All @@ -78,22 +86,25 @@ def getChanges(base_url, last_changeset=None, tips_only=False, ca_certs=None,
data = handle.read() data = handle.read()
return _parse_changes(data) return _parse_changes(data)



def sendchange(master, branch, change): def sendchange(master, branch, change):
log.info("Sendchange %s to %s on branch %s", change['changeset'], master, branch) log.info("Sendchange %s to %s on branch %s", change['changeset'],
master, branch)
cmd = ['retry.py', '-r', '5', '-s', '5', '-t', '30', cmd = ['retry.py', '-r', '5', '-s', '5', '-t', '30',
'--stdout-regexp', 'change sent successfully'] '--stdout-regexp', 'change sent successfully']
cmd.extend( cmd.extend(
['buildbot', 'sendchange', ['buildbot', 'sendchange',
'--master', master, '--master', master,
'--branch', branch, '--branch', branch,
'--comments', change['comments'].encode('ascii', 'replace'), '--comments', change['comments'].encode('ascii', 'replace'),
'--revision', change['changeset'], '--revision', change['changeset'],
'--user', change['author'].encode('ascii', 'replace'), '--user', change['author'].encode('ascii', 'replace'),
'--when', str(change['updated']), '--when', str(change['updated']),
]) ])
cmd.extend(change['files']) cmd.extend(change['files'])
subprocess.check_call(cmd) subprocess.check_call(cmd)



def processBranch(branch, state, config): def processBranch(branch, state, config):
log.debug("Processing %s", branch) log.debug("Processing %s", branch)
master = config.get('main', 'master') master = config.get('main', 'master')
Expand All @@ -116,13 +127,14 @@ def processBranch(branch, state, config):


try: try:
changes = getChanges(url, tips_only=tips_only, changes = getChanges(url, tips_only=tips_only,
last_changeset=last_changeset, ca_certs=ca_certs, last_changeset=last_changeset, ca_certs=ca_certs,
username=username, password=password) username=username, password=password)
# Do sendchanges! # Do sendchanges!
for c in changes: for c in changes:
# Ignore off-default branches # Ignore off-default branches
if c['branch'] != 'default' and config.getboolean(branch, 'default_branch_only'): if c['branch'] != 'default' and config.getboolean(branch, 'default_branch_only'):
log.info("Skipping %s on branch %s", c['changeset'], c['branch']) log.info(
"Skipping %s on branch %s", c['changeset'], c['branch'])
continue continue
# Change the comments to include the url to the revision # Change the comments to include the url to the revision
c['comments'] += ' %s/rev/%s' % (url, c['changeset']) c['comments'] += ' %s/rev/%s' % (url, c['changeset'])
Expand Down Expand Up @@ -150,11 +162,12 @@ def processBranch(branch, state, config):


parser = OptionParser() parser = OptionParser()
parser.set_defaults( parser.set_defaults(
config_file="hgpoller.ini", config_file="hgpoller.ini",
verbosity=log.INFO, verbosity=log.INFO,
) )
parser.add_option("-f", "--config-file", dest="config_file") parser.add_option("-f", "--config-file", dest="config_file")
parser.add_option("-v", "--verbose", dest="verbosity", action="store_const", const=log.DEBUG) parser.add_option("-v", "--verbose", dest="verbosity",
action="store_const", const=log.DEBUG)


options, args = parser.parse_args() options, args = parser.parse_args()


Expand All @@ -168,7 +181,7 @@ def processBranch(branch, state, config):
'interval': 300, 'interval': 300,
'state_file': 'state.json', 'state_file': 'state.json',
'default_branch_only': "yes", 'default_branch_only': "yes",
}) })
config.read(options.config_file) config.read(options.config_file)


try: try:
Expand Down

0 comments on commit 62ff0b1

Please sign in to comment.