Skip to content

Commit

Permalink
General code cleanup for Pyflakes warnings.
Browse files Browse the repository at this point in the history
All .py files in master/buildbot/ now pass pyflakes.
  • Loading branch information
Amber Yust committed Oct 26, 2010
1 parent a6e626f commit afb4a14
Show file tree
Hide file tree
Showing 34 changed files with 69 additions and 89 deletions.
5 changes: 2 additions & 3 deletions master/buildbot/buildslave.py
Expand Up @@ -15,8 +15,6 @@
from buildbot.process.properties import Properties
from buildbot.locks import LockAccess

import sys

class AbstractBuildSlave(pb.Avatar, service.MultiService):
"""This is the master-side representative for a remote buildbot slave.
There is exactly one for each slave described in the config file (the
Expand Down Expand Up @@ -696,7 +694,8 @@ def _soft_disconnect(self, fast=False):
return d

def disconnect(self):
d = self._soft_disconnect()
# This returns a Deferred but we don't use it
self._soft_disconnect()
# this removes the slave from all builders. It won't come back
# without a restart (or maybe a sighup)
self.botmaster.slaveLost(self)
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/changes/changes.py
@@ -1,4 +1,4 @@
import sys, os, time
import os, time
from cPickle import dump

from zope.interface import implements
Expand Down
1 change: 0 additions & 1 deletion master/buildbot/changes/gitpoller.py
Expand Up @@ -9,7 +9,6 @@
from twisted.python import log, failure
from twisted.internet import reactor, utils
from twisted.internet.task import LoopingCall
from twisted.web.client import getPage

from buildbot.changes import base, changes

Expand Down
10 changes: 6 additions & 4 deletions master/buildbot/changes/mail.py
Expand Up @@ -319,7 +319,8 @@ def parse(self, m, prefix=None):
if module and file:
path = "%s/%s" % (module, file)
files.append(path)
sticky = items[7]
# For reference, we don't use this field
#sticky = items[7]
branch = items[8]

# if no files changed, return nothing
Expand Down Expand Up @@ -424,7 +425,8 @@ def parse(self, m, prefix=None):
continue
m = modRE.match(line)
if m:
module = m.group(1)
# We don't actually use this
#module = m.group(1)
continue
m = pathRE.match(line)
if m:
Expand All @@ -440,7 +442,8 @@ def parse(self, m, prefix=None):
continue
m = updateRE.match(line)
if m:
updateof = m.group(1)
# We don't actually use this
#updateof = m.group(1)
continue
if line == "Log Message:\n":
break
Expand Down Expand Up @@ -576,7 +579,6 @@ def parse(self, m, prefix=None):

files = []
comments = ""
isdir = 0
lines = list(body_line_iterator(m))
rev = None
while lines:
Expand Down
4 changes: 1 addition & 3 deletions master/buildbot/db/connector.py
Expand Up @@ -271,11 +271,9 @@ def subscribe_to(self, category, observer):
def runQuery(self, *args, **kwargs):
assert self._started
self._pending_operation_count += 1
start = self._getCurrentTime()
#t = self._start_operation() # why is this commented out? -warner
d = self._pool.runQuery(*args, **kwargs)
#d.addBoth(self._runQuery_done, start, t)
return d

def _runQuery_done(self, res, start, t):
self._end_operation(t)
self._add_query_time(start)
Expand Down
2 changes: 2 additions & 0 deletions master/buildbot/db/dbspec.py
Expand Up @@ -220,11 +220,13 @@ def _get_sqlite_dbapi_name(self):
sqlite_dbapi_name = None
try:
from pysqlite2 import dbapi2 as sqlite3
assert sqlite3
sqlite_dbapi_name = "pysqlite2.dbapi2"
except ImportError:
# don't use built-in sqlite3 on 2.5 -- it has *bad* bugs
if sys.version_info >= (2,6):
import sqlite3
assert sqlite3
sqlite_dbapi_name = "sqlite3"
else:
raise
Expand Down
31 changes: 17 additions & 14 deletions master/buildbot/db/schema/v4.py
Expand Up @@ -19,13 +19,16 @@ def makeAutoincColumn(self, name):
raise ValueError("Unsupported dbapi: %s" % self.dbapiName)

def migrate_table(self, table_name, schema):
old_name = "%s_old" % table_name
names = {
'old_name': "%s_old" % table_name,
'table_name': table_name,
}
cursor = self.conn.cursor()
# If this fails, there's no cleaning up to do
cursor.execute("""
ALTER TABLE %(table_name)s
RENAME TO %(old_name)s
""" % locals())
""" % names)

try:
cursor.execute(schema)
Expand All @@ -34,26 +37,26 @@ def migrate_table(self, table_name, schema):
cursor.execute("""
ALTER TABLE %(old_name)s
RENAME TO %(table_name)s
""" % locals())
""" % names)
raise

try:
cursor.execute("""
INSERT INTO %(table_name)s
SELECT * FROM %(old_name)s
""" % locals())
""" % names)
cursor.execute("""
DROP TABLE %(old_name)s
""" % locals())
""" % names)
except:
# Clean up the new table, and restore the original
cursor.execute("""
DROP TABLE %(table_name)s
""" % locals())
""" % names)
cursor.execute("""
ALTER TABLE %(old_name)s
RENAME TO %(table_name)s
""" % locals())
""" % names)
raise

def set_version(self):
Expand All @@ -69,7 +72,7 @@ def migrate_schedulers(self):
`class_name` VARCHAR(100) NOT NULL, -- the scheduler's class
`state` VARCHAR(1024) NOT NULL -- JSON-encoded state dictionary
);
""" % locals()
""" % {'schedulerid_col': schedulerid_col}
self.migrate_table('schedulers', schema)

# Fix up indices
Expand All @@ -90,7 +93,7 @@ def migrate_builds(self):
`start_time` INTEGER NOT NULL,
`finish_time` INTEGER
);
""" % locals()
""" % {'buildid_col': buildid_col}
self.migrate_table('builds', schema)

def migrate_changes(self):
Expand All @@ -115,7 +118,7 @@ def migrate_changes(self):
-- later to filter changes
`project` TEXT NOT NULL default ''
);
""" % locals()
""" % {'changeid_col': changeid_col}
self.migrate_table('changes', schema)

# Drop changes_nextid columnt
Expand Down Expand Up @@ -159,7 +162,7 @@ def migrate_buildrequests(self):
`complete_at` INTEGER
);
""" % locals()
""" % {'buildrequestid_col': buildrequestid_col}
self.migrate_table('buildrequests', schema)

def migrate_buildsets(self):
Expand All @@ -176,7 +179,7 @@ def migrate_buildsets(self):
`results` SMALLINT -- 0=SUCCESS,2=FAILURE, from status/builder.py
-- results is NULL until complete==1
);
""" % locals()
""" % {'buildsetsid_col': buildsetsid_col}
self.migrate_table("buildsets", schema)

def migrate_patches(self):
Expand All @@ -188,7 +191,7 @@ def migrate_patches(self):
`patch_base64` TEXT NOT NULL, -- encoded bytestring
`subdir` TEXT -- usually NULL
);
""" % locals()
""" % {'patchesid_col': patchesid_col}
self.migrate_table("patches", schema)

def migrate_sourcestamps(self):
Expand All @@ -202,5 +205,5 @@ def migrate_sourcestamps(self):
`repository` TEXT not null default '',
`project` TEXT not null default ''
);
""" % locals()
""" % {'sourcestampsid_col': sourcestampsid_col}
self.migrate_table("sourcestamps", schema)
2 changes: 1 addition & 1 deletion master/buildbot/db/schema/v5.py
Expand Up @@ -47,7 +47,7 @@ def add_index(self, table, column, length=None):
lengthstr = " (%i)" % length
q = "CREATE INDEX `%(table)s_%(column)s` ON `%(table)s` (`%(column)s`%(lengthstr)s)"
cursor = self.conn.cursor()
cursor.execute(q % locals())
cursor.execute(q % {'table': table, 'column': column, 'lengthstr': lengthstr})

def set_version(self):
c = self.conn.cursor()
Expand Down
3 changes: 3 additions & 0 deletions master/buildbot/ec2buildslave.py
Expand Up @@ -104,6 +104,7 @@ def __init__(self, name, password, instance_type, ami=None,
# usage requirement.
try:
key_pair = self.conn.get_all_key_pairs(keypair_name)[0]
assert key_pair
# key_pair.delete() # would be used to recreate
except boto.exception.EC2ResponseError, e:
if 'InvalidKeyPair.NotFound' not in e.body:
Expand All @@ -122,6 +123,7 @@ def __init__(self, name, password, instance_type, ami=None,
# create security group
try:
group = self.conn.get_all_security_groups(security_name)[0]
assert group
except boto.exception.EC2ResponseError, e:
if 'InvalidGroup.NotFound' in e.body:
self.security_group = self.conn.create_security_group(
Expand All @@ -143,6 +145,7 @@ def __init__(self, name, password, instance_type, ami=None,
else:
# verify we have access to at least one acceptable image
discard = self.get_image()
assert discard

# get the specified elastic IP, if any
if elastic_ip is not None:
Expand Down
2 changes: 1 addition & 1 deletion master/buildbot/master.py
Expand Up @@ -341,7 +341,7 @@ def getPerspective(self, mind, slavename):

# ping the old slave. If this kills it, then the new slave will connect
# again and everyone will be happy.
d = sl.slave.callRemote("print", "master got a duplicate connection; keeping this one")
sl.slave.callRemote("print", "master got a duplicate connection; keeping this one")

# now return a dummy avatar and kill the new connection in 5
# seconds, thereby giving the ping a bit of time to kill the old
Expand Down
5 changes: 3 additions & 2 deletions master/buildbot/scripts/runner.py
Expand Up @@ -458,7 +458,7 @@ def upgradeMaster(config):
m.move_if_present(os.path.join(basedir, "public_html/index.html"),
os.path.join(basedir, "templates/root.html"))

from buildbot.db import connector, dbspec
from buildbot.db import dbspec
spec = dbspec.DBSpec.from_url(config["db"], basedir)
# TODO: check that TAC file specifies the right spec

Expand Down Expand Up @@ -634,7 +634,7 @@ def restart(config):
basedir = config['basedir']
quiet = config['quiet']

if not isBuildmasterDir(config['basedir']):
if not isBuildmasterDir(basedir):
print "not a buildmaster directory"
sys.exit(1)

Expand Down Expand Up @@ -987,6 +987,7 @@ def getSynopsis(self):
def doTryServer(config):
try:
from hashlib import md5
assert md5
except ImportError:
# For Python 2.4 compatibility
import md5
Expand Down
6 changes: 1 addition & 5 deletions master/buildbot/status/builder.py
Expand Up @@ -1001,11 +1001,7 @@ def addHTMLLog(self, name, html):
log = HTMLLogFile(self, name, logfilename, html)
self.logs.append(log)
for w in self.watchers:
receiver = w.logStarted(self.build, self, log)
# TODO: think about this: there isn't much point in letting
# them subscribe
#if receiver:
# log.subscribe(receiver, True)
w.logStarted(self.build, self, log)
w.logFinished(self.build, self, log)

def logFinished(self, log):
Expand Down
1 change: 1 addition & 0 deletions master/buildbot/status/persistent_queue.py
Expand Up @@ -3,6 +3,7 @@
try:
# Python 2.4+
from collections import deque
assert deque
except ImportError:
deque = None
import os
Expand Down
1 change: 1 addition & 0 deletions master/buildbot/status/status_push.py
Expand Up @@ -12,6 +12,7 @@

try:
import simplejson as json
assert json
except ImportError:
import json

Expand Down
1 change: 0 additions & 1 deletion master/buildbot/status/web/builder.py
Expand Up @@ -11,7 +11,6 @@
map_branches, path_to_authfail
from buildbot.sourcestamp import SourceStamp

from buildbot.status.builder import BuildRequestStatus
from buildbot.status.web.build import BuildsResource, StatusResourceBuild
from buildbot import util

Expand Down
8 changes: 1 addition & 7 deletions master/buildbot/status/web/change_hook.py
Expand Up @@ -4,15 +4,9 @@

# but "the rest" is pretty minimal
from twisted.web import resource
from buildbot.status.builder import FAILURE
import re
from buildbot import util, interfaces
import traceback
import sys
from buildbot.process.properties import Properties
from buildbot.changes.changes import Change
from twisted.python.reflect import namedModule
from twisted.python.log import msg,err
from twisted.python.log import msg
from buildbot.util import json

class ChangeHookResource(resource.Resource):
Expand Down
10 changes: 0 additions & 10 deletions master/buildbot/status/web/hooks/base.py
Expand Up @@ -3,18 +3,8 @@
# otherwise, Andrew Melo <andrew.melo@gmail.com> wrote the rest

# but "the rest" is pretty minimal
from twisted.web import resource
from buildbot.status.builder import FAILURE
import re
from buildbot import util, interfaces
import logging
import traceback
import sys
from buildbot.process.properties import Properties
from buildbot.changes.changes import Change
from twisted.python.reflect import namedModule
from buildbot.util import json
from twisted.python.log import msg,err

def getChanges(request, options=None):
"""
Expand Down
15 changes: 3 additions & 12 deletions master/buildbot/status/web/hooks/github.py
Expand Up @@ -9,28 +9,18 @@
"""

import tempfile
import logging
import re
import sys
import traceback
from twisted.web import server, resource
from twisted.internet import reactor
from twisted.spread import pb
from twisted.cred import credentials
from optparse import OptionParser
from buildbot.changes.changes import Change
import datetime
import time
from twisted.python import log
import calendar
import time
import calendar
import datetime
import re

try:
import json
assert json
except ImportError:
import simplejson as json

Expand Down Expand Up @@ -86,7 +76,8 @@ def getChanges(request, options = None):
user = payload['repository']['owner']['name']
repo = payload['repository']['name']
repo_url = payload['repository']['url']
private = payload['repository']['private']
# This field is unused:
#private = payload['repository']['private']
changes = process_change(payload, user, repo, repo_url)
log.msg("Received %s changes from github" % len(changes))
return changes
Expand Down

0 comments on commit afb4a14

Please sign in to comment.