[Buildbot-commits] buildbot/buildbot/status words.py,1.49,1.50

Brian Warner warner at users.sourceforge.net
Sun Jun 17 21:10:35 UTC 2007


Update of /cvsroot/buildbot/buildbot/buildbot/status
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv21038/buildbot/status

Modified Files:
	words.py 
Log Message:
[project @ words.py: refactor into Contact/IChannel classes, to add more IM protocols in the future]

Original author: warner at lothar.com
Date: 2007-05-18 00:56:48+00:00

Index: words.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/status/words.py,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- words.py	17 Jun 2007 21:10:27 -0000	1.49
+++ words.py	17 Jun 2007 21:10:32 -0000	1.50
@@ -65,9 +65,8 @@
     'broadcast contact' (chat rooms, IRC channels as a whole).
     """
 
-    def __init__(self, channel, username):
+    def __init__(self, channel):
         self.channel = channel
-        self.username = username
 
     silly = {
         "What happen ?": "Somebody set up us the bomb.",
@@ -102,7 +101,7 @@
         """
         @rtype: list of L{buildbot.process.builder.Builder}
         """
-        names = self.channel.status.getBuilderNames(categories=self.categories)
+        names = self.channel.status.getBuilderNames(categories=self.channel.categories)
         names.sort()
         builders = [self.channel.status.getBuilder(n) for n in names]
         return builders
@@ -127,13 +126,13 @@
             reactor.callLater(when, self.send, r)
             when += 2.5
 
-    def command_HELLO(self, args):
+    def command_HELLO(self, args, who):
         self.send("yes?")
 
-    def command_VERSION(self, args):
+    def command_VERSION(self, args, who):
         self.send("buildbot-%s at your service" % version)
 
-    def command_LIST(self, args):
+    def command_LIST(self, args, who):
         args = args.split()
         if len(args) == 0:
             raise UsageError, "try 'list builders'"
@@ -151,7 +150,7 @@
             return
     command_LIST.usage = "list builders - List configured builders"
 
-    def command_STATUS(self, args):
+    def command_STATUS(self, args, who):
         args = args.split()
         if len(args) == 0:
             which = "all"
@@ -167,7 +166,7 @@
         self.emit_status(which)
     command_STATUS.usage = "status [<which>] - List status of a builder (or all builders)"
 
-    def command_WATCH(self, args):
+    def command_WATCH(self, args, who):
         args = args.split()
         if len(args) != 1:
             raise UsageError("try 'watch <builder>'")
@@ -201,8 +200,8 @@
         builder = b.getBuilder()
         log.msg('builder %r in category %s finished' % (builder,
                                                         builder.category))
-        if (self.categories != None and
-            builder.category not in self.categories):
+        if (self.channel.categories != None and
+            builder.category not in self.channel.categories):
             return
 
         r = "Hey! build %s #%d is complete: %s" % \
@@ -215,9 +214,12 @@
         if buildurl:
             self.send("Build details are at %s" % buildurl)
 
-    def command_FORCE(self, args):
+    def command_FORCE(self, args, who):
         args = shlex.split(args) # TODO: this requires python2.3 or newer
-        if args.pop(0) != "build":
+        if not args:
+            raise UsageError("try 'force build WHICH <REASON>'")
+        what = args.pop(0)
+        if what != "build":
             raise UsageError("try 'force build WHICH <REASON>'")
         opts = ForceOptions()
         opts.parseOptions(args)
@@ -227,6 +229,10 @@
         revision = opts['revision']
         reason = opts['reason']
 
+        if which is None:
+            raise UsageError("you must provide a Builder, "
+                             "try 'force build WHICH <REASON>'")
+
         # keep weird stuff out of the branch and revision strings. TODO:
         # centralize this somewhere.
         if branch and not re.match(r'^[\w\.\-\/]*$', branch):
@@ -240,11 +246,7 @@
 
         bc = self.getControl(which)
 
-        who = None # TODO: if we can authenticate that a particular User
-                   # asked for this, use User Name instead of None so they'll
-                   # be informed of the results.
-        # TODO: or, monitor this build and announce the results
-        r = "forced: by IRC user <%s>: %s" % (self.username, reason)
+        r = "forced: by %s: %s" % (self.describeUser(who), reason)
         # TODO: maybe give certain users the ability to request builds of
         # certain branches
         s = SourceStamp(branch=branch, revision=revision)
@@ -260,7 +262,7 @@
 
     command_FORCE.usage = "force build <which> <reason> - Force a build"
 
-    def command_STOP(self, args):
+    def command_STOP(self, args, who):
         args = args.split(None, 2)
         if len(args) < 3 or args[0] != 'build':
             raise UsageError, "try 'stop build WHICH <REASON>'"
@@ -269,8 +271,7 @@
 
         buildercontrol = self.getControl(which)
 
-        who = None
-        r = "stopped: by IRC user <%s>: %s" % (self.username, reason)
+        r = "stopped: by %s: %s" % (self.describeUser(who), reason)
 
         # find an in-progress build
         builderstatus = self.getBuilder(which)
@@ -324,7 +325,7 @@
             str += " ".join(last.getText())
         self.send("last build [%s]: %s" % (which, str))
 
-    def command_LAST(self, args):
+    def command_LAST(self, args, who):
         args = args.split()
         if len(args) == 0:
             which = "all"
@@ -342,13 +343,13 @@
 
     def build_commands(self):
         commands = []
-        for k in self.__class__.__dict__.keys():
+        for k in dir(self):
             if k.startswith('command_'):
                 commands.append(k[8:].lower())
         commands.sort()
         return commands
 
-    def command_HELP(self, args):
+    def command_HELP(self, args, who):
         args = args.split()
         if len(args) == 0:
             self.send("Get help on what? (try 'help <foo>', or 'commands' for a command list)")
@@ -364,25 +365,25 @@
             self.send("No usage info for '%s'" % command)
     command_HELP.usage = "help <command> - Give help for <command>"
 
-    def command_SOURCE(self, args):
-        banner = "My source can be found at http://buildbot.sourceforge.net/"
+    def command_SOURCE(self, args, who):
+        banner = "My source can be found at http://buildbot.net/"
         self.send(banner)
 
-    def command_COMMANDS(self, args):
+    def command_COMMANDS(self, args, who):
         commands = self.build_commands()
         str = "buildbot commands: " + ", ".join(commands)
         self.send(str)
     command_COMMANDS.usage = "commands - List available commands"
 
-    def command_DESTROY(self, args):
+    def command_DESTROY(self, args, who):
         self.act("readies phasers")
 
-    def command_DANCE(self, args):
+    def command_DANCE(self, args, who):
         reactor.callLater(1.0, self.send, "0-<")
         reactor.callLater(3.0, self.send, "0-/")
         reactor.callLater(3.5, self.send, "0-\\")
 
-    def command_EXCITED(self, args):
+    def command_EXCITED(self, args, who):
         # like 'buildbot: destroy the sun!'
         self.send("What you say!")
 
@@ -408,8 +409,17 @@
 
     def __init__(self, channel, dest):
         Contact.__init__(self, channel)
+        # when people send us public messages ("buildbot: command"),
+        # self.dest is the name of the channel ("#twisted"). When they send
+        # us private messages (/msg buildbot command), self.dest is their
+        # username.
         self.dest = dest
 
+    def describeUser(self, user):
+        if self.dest[0] == "#":
+            return "IRC user <%s> on channel %s" % (user, self.dest)
+        return "IRC user <%s> (privmsg)" % user
+
     # userJoined(self, user, channel)
 
     def send(self, message):
@@ -418,7 +428,14 @@
         self.channel.me(self.dest, action)
 
 
-    def handleMessage(self, message):
+    def handleMessage(self, message, who):
+        # a message has arrived from 'who'. For broadcast contacts (i.e. when
+        # people do an irc 'buildbot: command'), this will be a string
+        # describing the sender of the message in some useful-to-log way, and
+        # a single Contact may see messages from a variety of users. For
+        # unicast contacts (i.e. when people do an irc '/msg buildbot
+        # command'), a single Contact will only ever see messages from a
+        # single user.
         message = message.lstrip()
         if self.silly.has_key(message):
             return self.doSilly(message)
@@ -436,7 +453,7 @@
         error = None
         try:
             if meth:
-                meth(args.strip())
+                meth(args.strip(), who)
         except UsageError, e:
             self.send(str(e))
         except:
@@ -517,14 +534,14 @@
         if channel == self.nickname:
             # private message
             contact = self.getContact(user)
-            contact.handleMessage(message)
+            contact.handleMessage(message, user)
             return
         # else it's a broadcast message, maybe for us, maybe not. 'channel'
         # is '#twisted' or the like.
         contact = self.getContact(channel)
         if message.startswith("%s:" % self.nickname):
             message = message[len("%s:" % self.nickname):]
-            contact.handleMessage(message)
+            contact.handleMessage(message, user)
         # to track users comings and goings, add code here
 
     def action(self, user, channel, data):





More information about the Commits mailing list