from twisted.spread import pb
import sys, gtk, gnomeapplet, pynotify
-from bbclient import BuildbotClient
-
-HOST = 'localhost'
-PORT = 1234
-USER = 'statusClient'
-PASS = 'clientpw'
+from bbclient import BuildbotClient, CommandLineOptions
class BuildbotApplet(pb.Referenceable):
self.applet.add(icon)
self.applet.show_all()
- client = BuildbotClient()
+ self.client = BuildbotClient()
- d = client.connect(HOST, PORT, USER, PASS)
+ def connect(self, host, port, user, password):
- d.addCallback(lambda arg: client.subscribe('builds', 5, self))
+ d = self.client.connect(host, port, user, password)
+ d.addCallback(lambda arg: self.client.subscribe('builds', 5, self))
# Callbacks for subscription mode >= MODE_BUILDERS
n.attach_to_widget(self.applet)
n.show()
-def BuildbotApplet_factory(applet, iid):
+def BuildbotApplet_factory(applet, iid, host, port, user, password):
pynotify.init("bbapplet")
icon = gtk.image_new_from_stock(gtk.STOCK_NEW, gtk.ICON_SIZE_MENU)
- BuildbotApplet(applet, icon)
+ app = BuildbotApplet(applet, icon)
+ app.connect(host, port, user, password)
return gtk.TRUE
if __name__ == "__main__":
- if len(sys.argv) == 2 and sys.argv[1] == "run-in-window":
+ if sys.argv[1] == "run-in-window":
+
+ del(sys.argv[1])
+
+ host, port, user, password = CommandLineOptions()
# Run in a window, for debugging
main_window.connect('destroy', gtk.main_quit)
app = gnomeapplet.Applet()
-
- BuildbotApplet_factory(app, None)
+
+ BuildbotApplet_factory(app, None, host, port, user, password)
app.reparent(main_window)
+import sys, string
+from optparse import OptionParser
+
from twisted.internet import reactor
from twisted.cred import credentials
from twisted.spread import pb
def subscribe(self, mode, interval, target):
return self.remote.callRemote('subscribe', mode, interval, target)
+
+def CommandLineOptions():
+ """Return hostname, port, user and password command line options."""
+
+ optparser = OptionParser(
+ usage = '%prog HOSTNAME:PORT -u USER -p PASS')
+
+ optparser.add_option('-u', '--user', dest = 'user',
+ action = 'store', type = 'string',
+ help = 'user to connect as')
+
+ optparser.add_option('-p', '--password', dest = 'password',
+ action = 'store', type = 'string',
+ help = 'password to connect user as')
+
+ (opts, argv) = optparser.parse_args()
+
+ if len(argv) != 1:
+ optparser.print_usage()
+ sys.exit(1)
+
+ if opts.user is None:
+ print 'Username required'
+ optparser.print_usage()
+ sys.exit(1)
+
+ if opts.password is None:
+ print 'Password required'
+ optparser.print_usage()
+ sys.exit(1)
+
+ host, port = string.split(argv[0], ':')
+
+ return (host, int(port), opts.user, opts.password)
from twisted.spread import pb
from twisted.cred import credentials
from twisted.python import log
-from bbclient import BuildbotClient
+from bbclient import BuildbotClient, CommandLineOptions
# Application class
# Command line parsing
- from optparse import OptionParser
-
- optparser = OptionParser(
- usage = '%prog HOSTNAME:PORT -u USER -p PASS')
-
- optparser.add_option('-u', '--user', dest = 'user',
- action = 'store', type = 'string',
- help = 'user to connect as')
-
- optparser.add_option('-p', '--password', dest = 'password',
- action = 'store', type = 'string',
- help = 'password to connect user as')
-
- (opts, argv) = optparser.parse_args()
-
- if len(argv) != 1:
- optparser.print_usage()
- sys.exit(1)
-
- if opts.user is None:
- print 'Username required'
- optparser.print_usage()
- sys.exit(1)
-
- if opts.password is None:
- print 'Password required'
- optparser.print_usage()
- sys.exit(1)
-
- host, port = string.split(argv[0], ':')
+ host, port, user, password = CommandLineOptions()
# Start application
log.startLogging(sys.stdout)
- app = App(host, int(port), opts.user, opts.password)
+ app = App(host, port, user, password)
reactor.run()