Skip to content

Commit

Permalink
fixed PEP8 violations
Browse files Browse the repository at this point in the history
  • Loading branch information
Elmir Jagudin committed Jun 3, 2013
1 parent 9c1f9bf commit 18f62a5
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 56 deletions.
14 changes: 9 additions & 5 deletions master/buildbot/scripts/base.py
Expand Up @@ -20,6 +20,7 @@
import stat
from twisted.python import usage, runtime


def isBuildmasterDir(dir):
def print_error(error_message):
print "%s\ninvalid buildmaster directory '%s'" % (error_message, dir)
Expand All @@ -28,7 +29,7 @@ def print_error(error_message):
try:
contents = open(buildbot_tac).read()
except IOError, exception:
print_error("error reading '%s': %s" % \
print_error("error reading '%s': %s" %
(buildbot_tac, exception.strerror))
return False

Expand All @@ -38,6 +39,7 @@ def print_error(error_message):

return True


def getConfigFileWithFallback(basedir, defaultName='master.cfg'):
configFile = os.path.abspath(os.path.join(basedir, defaultName))
if os.path.exists(configFile):
Expand All @@ -52,6 +54,7 @@ def getConfigFileWithFallback(basedir, defaultName='master.cfg'):
# No config file found; return default location and fail elsewhere
return configFile


class SubcommandOptions(usage.Options):
# subclasses should set this to a list-of-lists in order to source the
# .buildbot/options file. Note that this *only* works with optParameters,
Expand Down Expand Up @@ -112,9 +115,9 @@ def loadOptionsFile(self, _here=None):
searchpath.append(os.path.join(here, ".buildbot"))
next = os.path.dirname(here)
if next == here:
break # we've hit the root
break # we've hit the root
here = next
toomany -= 1 # just in case
toomany -= 1 # just in case
if toomany == 0:
print ("I seem to have wandered up into the infinite glories "
"of the heavens. Oops.")
Expand All @@ -129,7 +132,7 @@ def loadOptionsFile(self, _here=None):
if runtime.platformType != 'win32':
if os.stat(d)[stat.ST_UID] != os.getuid():
print "skipping %s because you don't own it" % d
continue # security, skip other people's directories
continue # security, skip other people's directories
optfile = os.path.join(d, "options")
if os.path.exists(optfile):
try:
Expand All @@ -147,14 +150,15 @@ def loadOptionsFile(self, _here=None):
return localDict

def postOptions(self):
missing = [ k for k in self.requiredOptions if self[k] is None ]
missing = [k for k in self.requiredOptions if self[k] is None]
if missing:
if len(missing) > 1:
msg = 'Required arguments missing: ' + ', '.join(missing)
else:
msg = 'Required argument missing: ' + missing[0]
raise usage.UsageError(msg)


class BasedirMixin(object):

"""SubcommandOptions Mixin to handle subcommands that take a basedir
Expand Down
97 changes: 54 additions & 43 deletions master/buildbot/scripts/runner.py
Expand Up @@ -30,6 +30,7 @@
# Note that the terms 'options' and 'config' are used interchangeably here - in
# fact, they are interchanged several times. Caveat legator.


def validate_master_option(master):
"""Validate master (-m, --master) command line option.
Expand Down Expand Up @@ -106,6 +107,7 @@ class CreateMasterOptions(base.BasedirMixin, base.SubcommandOptions):
["db", None, "sqlite:///state.sqlite",
"which DB to use for scheduler/status state. See below for syntax."],
]

def getSynopsis(self):
return "Usage: buildbot create-master [options] [<basedir>]"

Expand Down Expand Up @@ -144,7 +146,7 @@ def postOptions(self):
raise usage.UsageError("log-size parameter needs to be an int")
if not re.match('^\d+$', self['log-count']) and \
self['log-count'] != 'None':
raise usage.UsageError("log-count parameter needs to be an int "+
raise usage.UsageError("log-count parameter needs to be an int " +
" or None")


Expand All @@ -154,6 +156,7 @@ class StopOptions(base.BasedirMixin, base.SubcommandOptions):
["quiet", "q", "Do not emit the commands being run"],
["clean", "c", "Clean shutdown master"],
]

def getSynopsis(self):
return "Usage: buildbot stop [<basedir>]"

Expand All @@ -165,6 +168,7 @@ class RestartOptions(base.BasedirMixin, base.SubcommandOptions):
['nodaemon', None, "Don't daemonize (stay in foreground)"],
["clean", "c", "Clean shutdown master"],
]

def getSynopsis(self):
return "Usage: buildbot restart [<basedir>]"

Expand All @@ -175,6 +179,7 @@ class StartOptions(base.BasedirMixin, base.SubcommandOptions):
['quiet', 'q', "Don't display startup log messages"],
['nodaemon', None, "Don't daemonize (stay in foreground)"],
]

def getSynopsis(self):
return "Usage: buildbot start [<basedir>]"

Expand All @@ -184,6 +189,7 @@ class ReconfigOptions(base.BasedirMixin, base.SubcommandOptions):
optFlags = [
['quiet', 'q', "Don't display log messages about reconfiguration"],
]

def getSynopsis(self):
return "Usage: buildbot reconfig [<basedir>]"

Expand All @@ -196,10 +202,10 @@ class DebugClientOptions(base.SubcommandOptions):
["passwd", "p", None, "Debug password to use"],
]
buildbotOptions = [
[ 'master', 'master' ],
[ 'debugMaster', 'master' ],
['master', 'master'],
['debugMaster', 'master'],
]
requiredOptions = [ 'master', 'passwd' ]
requiredOptions = ['master', 'passwd']

def getSynopsis(self):
return "Usage: buildbot debugclient [options]"
Expand All @@ -224,14 +230,15 @@ class BaseStatusClientOptions(base.SubcommandOptions):
optParameters = [
["master", "m", None,
"Location of the buildmaster's status port (host:port)"],
["username", "u", "statusClient", "Username performing the trial build"],
["username", "u", "statusClient",
"Username performing the trial build"],
["passwd", 'p', "clientpw", "password for PB authentication"],
]
buildbotOptions = [
[ 'master', 'master' ],
[ 'masterstatus', 'master' ],
['master', 'master'],
['masterstatus', 'master'],
]
requiredOptions = [ 'master' ]
requiredOptions = ['master']

def parseArgs(self, *args):
if len(args) > 0:
Expand All @@ -244,21 +251,23 @@ def postOptions(self):
validate_master_option(self.get('master'))



class StatusLogOptions(BaseStatusClientOptions):
subcommandFunction = "buildbot.scripts.statuslog.statuslog"

def getSynopsis(self):
return "Usage: buildbot statuslog [options]"


class StatusGuiOptions(BaseStatusClientOptions):
subcommandFunction = "buildbot.scripts.statusgui.statusgui"

def getSynopsis(self):
return "Usage: buildbot statusgui [options]"


class SendChangeOptions(base.SubcommandOptions):
subcommandFunction = "buildbot.scripts.sendchange.sendchange"

def __init__(self):
base.SubcommandOptions.__init__(self)
self['properties'] = {}
Expand Down Expand Up @@ -292,14 +301,14 @@ def __init__(self):
]

buildbotOptions = [
[ 'master', 'master' ],
[ 'who', 'who' ],
[ 'branch', 'branch' ],
[ 'category', 'category' ],
[ 'vc', 'vc' ],
['master', 'master'],
['who', 'who'],
['branch', 'branch'],
['category', 'category'],
['vc', 'vc'],
]

requiredOptions = [ 'who', 'master' ]
requiredOptions = ['who', 'master']

def getSynopsis(self):
return "Usage: buildbot sendchange [options] filenames.."
Expand All @@ -308,14 +317,14 @@ def parseArgs(self, *args):
self['files'] = args

def opt_property(self, property):
name,value = property.split(':', 1)
name, value = property.split(':', 1)
self['properties'][name] = value

def postOptions(self):
base.SubcommandOptions.postOptions(self)

if self.get("revision_file"):
with open(self["revision_file"],"r") as f:
with open(self["revision_file"], "r") as f:
self['revision'] = f.read()

if self.get('when'):
Expand Down Expand Up @@ -350,6 +359,7 @@ def postOptions(self):

validate_master_option(self.get('master'))


class TryOptions(base.SubcommandOptions):
subcommandFunction = "buildbot.scripts.trycmd.trycmd"
optParameters = [
Expand Down Expand Up @@ -426,28 +436,28 @@ class TryOptions(base.SubcommandOptions):

# Mapping of .buildbot/options names to command-line options
buildbotOptions = [
[ 'try_connect', 'connect' ],
['try_connect', 'connect'],
#[ 'try_builders', 'builders' ], <-- handled in postOptions
[ 'try_vc', 'vc' ],
[ 'try_branch', 'branch' ],
[ 'try_repository', 'repository' ],
[ 'try_topdir', 'topdir' ],
[ 'try_topfile', 'topfile' ],
[ 'try_host', 'host' ],
[ 'try_username', 'username' ],
[ 'try_jobdir', 'jobdir' ],
[ 'try_buildbotbin', 'buildbotbin' ],
[ 'try_passwd', 'passwd' ],
[ 'try_master', 'master' ],
[ 'try_who', 'who' ],
[ 'try_comment', 'comment' ],
['try_vc', 'vc'],
['try_branch', 'branch'],
['try_repository', 'repository'],
['try_topdir', 'topdir'],
['try_topfile', 'topfile'],
['try_host', 'host'],
['try_username', 'username'],
['try_jobdir', 'jobdir'],
['try_buildbotbin', 'buildbotbin'],
['try_passwd', 'passwd'],
['try_master', 'master'],
['try_who', 'who'],
['try_comment', 'comment'],
#[ 'try_wait', 'wait' ], <-- handled in postOptions
#[ 'try_quiet', 'quiet' ], <-- handled in postOptions

# Deprecated command mappings from the quirky old days:
[ 'try_masterstatus', 'master' ],
[ 'try_dir', 'jobdir' ],
[ 'try_password', 'passwd' ],
['try_masterstatus', 'master'],
['try_dir', 'jobdir'],
['try_password', 'passwd'],
]

def __init__(self):
Expand All @@ -459,9 +469,10 @@ def opt_builder(self, option):
self['builders'].append(option)

def opt_properties(self, option):
# We need to split the value of this option into a dictionary of properties
# We need to split the value of this option
# into a dictionary of properties
propertylist = option.split(",")
for i in range(0,len(propertylist)):
for i in range(0, len(propertylist)):
splitproperty = propertylist[i].split("=", 1)
self['properties'][splitproperty[0]] = splitproperty[1]

Expand Down Expand Up @@ -491,7 +502,7 @@ def postOptions(self):

if self['connect'] == 'pb':
if not self['master']:
raise usage.UsageError("master location must be specified" \
raise usage.UsageError("master location must be specified"
"for 'pb' connections")
validate_master_option(self['master'])

Expand All @@ -501,7 +512,7 @@ class TryServerOptions(base.SubcommandOptions):
optParameters = [
["jobdir", None, None, "the jobdir (maildir) for submitting jobs"],
]
requiredOptions = [ 'jobdir' ]
requiredOptions = ['jobdir']

def getSynopsis(self):
return "Usage: buildbot tryserver [options]"
Expand Down Expand Up @@ -554,12 +565,12 @@ class UserOptions(base.SubcommandOptions):
"Note that 'update' requires --info=id:type=value..."]
]
buildbotOptions = [
[ 'master', 'master' ],
[ 'user_master', 'master' ],
[ 'user_username', 'username' ],
[ 'user_passwd', 'passwd' ],
['master', 'master'],
['user_master', 'master'],
['user_username', 'username'],
['user_passwd', 'passwd'],
]
requiredOptions = [ 'master' ]
requiredOptions = ['master']

longdesc = """
Currently implemented types for --info= are:\n
Expand Down

0 comments on commit 18f62a5

Please sign in to comment.