Skip to content

Commit

Permalink
Repeated code was replaced.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Mayorov committed Feb 13, 2013
1 parent d8ba788 commit aa50e12
Showing 1 changed file with 16 additions and 29 deletions.
45 changes: 16 additions & 29 deletions master/buildbot/status/words.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,22 @@ def reportBuild(self, builder, buildnum):
# and return True, since this is a new one
return True

def validate_shlex_args(self, args):
"""Returns list of arguments parsed by shlex.split() or
raise UsageError if failed"""
try:
return shlex.split(args)
except ValueError as e:
raise UsageError(e)

def command_HELLO(self, args, who):
self.send("yes?")

def command_VERSION(self, args, who):
self.send("buildbot-%s at your service" % version)

def command_LIST(self, args, who):
try:
args = shlex.split(args)
except ValueError as e:
raise UsageError(e)
args = self.validate_shlex_args(args)
if len(args) == 0:
raise UsageError, "try 'list builders'"
if args[0] == 'builders':
Expand All @@ -248,10 +253,7 @@ def command_LIST(self, args, who):
command_LIST.usage = "list builders - List configured builders"

def command_STATUS(self, args, who):
try:
args = shlex.split(args)
except ValueError as e:
raise UsageError(e)
args = self.validate_shlex_args(args)
if len(args) == 0:
which = "all"
elif len(args) == 1:
Expand Down Expand Up @@ -310,10 +312,7 @@ def remove_all_notification_events(self):
self.unsubscribe_from_build_events()

def command_NOTIFY(self, args, who):
try:
args = shlex.split(args)
except ValueError as e:
raise UsageError(e)
args = self.validate_shlex_args(args)

if not args:
raise UsageError("try 'notify on|off|list <EVENT>'")
Expand Down Expand Up @@ -344,10 +343,7 @@ def command_NOTIFY(self, args, who):
command_NOTIFY.usage = "notify on|off|list [<EVENT>] ... - Notify me about build events. event should be one or more of: 'started', 'finished', 'failure', 'success', 'exception' or 'xToY' (where x and Y are one of success, warnings, failure, exception, but Y is capitalized)"

def command_WATCH(self, args, who):
try:
args = shlex.split(args)
except ValueError as e:
raise UsageError(e)
args = self.validate_shlex_args(args)
if len(args) != 1:
raise UsageError("try 'watch <builder>'")
which = args[0]
Expand Down Expand Up @@ -507,7 +503,7 @@ def watchedBuildFinished(self, b):
def command_FORCE(self, args, who):
errReply = "try 'force build [--branch=BRANCH] [--revision=REVISION] [--props=PROP1=VAL1,PROP2=VAL2...] <WHICH> <REASON>'"
try:
args = shlex.split(args)
args = self.validate_shlex_args(args)
except ValueError as e:
raise UsageError(e)
if not args:
Expand Down Expand Up @@ -577,10 +573,7 @@ def subscribe(buildreq):
command_FORCE.usage = "force build [--branch=branch] [--revision=revision] [--props=prop1=val1,prop2=val2...] <which> <reason> - Force a build"

def command_STOP(self, args, who):
try:
args = shlex.split(args)
except ValueError as e:
raise UsageError(e)
args = self.validate_shlex_args(args)
if len(args) < 3 or args[0] != 'build':
raise UsageError, "try 'stop build WHICH <REASON>'"
which = args[1]
Expand Down Expand Up @@ -641,10 +634,7 @@ def emit_status(self, which):
self.send(str)

def command_LAST(self, args, who):
try:
args = shlex.split(args)
except ValueError as e:
raise UsageError(e)
args = self.validate_shlex_args(args)

if len(args) == 0:
which = "all"
Expand Down Expand Up @@ -702,10 +692,7 @@ def command_UNMUTE(self, args, who):
command_UNMUTE.usage = "unmute - disable a previous 'mute'"

def command_HELP(self, args, who):
try:
args = shlex.split(args)
except ValueError as e:
raise UsageError(e)
args = self.validate_shlex_args(args)
if len(args) == 0:
self.send("Get help on what? (try 'help <foo>', 'help <foo> <bar>, "
"or 'commands' for a command list)")
Expand Down

0 comments on commit aa50e12

Please sign in to comment.