Start of command line buildbot status client.
[tpot/bbremote.git] / bbc
1 #!/usr/bin/python
2 #
3 # Command line buildbot status client
4 #
5
6 import sys
7
8 from twisted.python import usage
9 from twisted.internet import reactor
10
11 OPT_LIST_BUILDERS = 'list-builders'
12
13 class Options(usage.Options):
14
15     optFlags = [
16         [OPT_LIST_BUILDERS, 'b', 'List available builders'],
17     ]
18
19 def list_builders(connect_result, client):
20     """List builders by name."""
21
22     d = client.getBuilderNames()
23
24     d.addCallback(
25         lambda names: [sys.stdout.write('%s\n' % name) for name in names])
26
27     d.addBoth(lambda arg: reactor.stop())
28
29 if __name__ == '__main__':
30
31     # Command line options
32
33     options = Options()
34
35     try:
36         options.parseOptions()
37     except usage.UsageError, errortext:
38         print '%s: %s' % (sys.argv[0], errortext)
39         print '%s: Try --help for usage details.' % (sys.argv[0])
40         sys.exit(1)
41
42     # Make buildbot connection
43
44     from bbclient import BuildbotClient
45
46     client = BuildbotClient()
47     
48     d = client.connect('ldl.fc.hp.com', 8019, 'statusClient', 'clientpw')
49
50     # Execute commands
51
52     if options[OPT_LIST_BUILDERS] == 1:
53         d.addCallback(list_builders, client)
54     else:
55         print '%s: Must specify an operation to perform!' % sys.argv[0]
56         print options
57         sys.exit(1)
58
59     reactor.run()