]> git.ipfire.org Git - people/jschlag/pbs.git/blob - src/scripts/pakfire-build-service
94aa7f7de3de4a99bfa4c626ce56ea9948b4b7ec
[people/jschlag/pbs.git] / src / scripts / pakfire-build-service
1 #!/usr/bin/python
2
3 import sys
4
5 # Use tornado's logging options
6 import tornado.options
7 tornado.options.parse_command_line()
8
9 import pakfire.buildservice
10
11 class Cli(object):
12 def __init__(self, *args, **kwargs):
13 # Initialise backend
14 self.backend = pakfire.buildservice.Backend(*args, **kwargs)
15
16 self._commands = {
17 # Cleanup uploads
18 "cleanup-uploads" : self.backend.uploads.cleanup,
19
20 # Sends all queued messages
21 "process-message-queue" : self.backend.messages.process_queue,
22 }
23
24 def __call__(self, *args):
25 if not len(args) >= 2:
26 print >>sys.stderr, "Insufficient number of arguments"
27 return 2
28
29 args = list(args)
30 basename = args.pop(0)
31 command = args.pop(0)
32
33 # Get called command
34 try:
35 command = self._commands[command]
36 except KeyError:
37 print >>sys.stderr, "Command not found: %s" % command
38 return 2
39
40 # Execute command
41 r = command(*args)
42
43 # Exit with error code
44 sys.exit(r or 0)
45
46 # main
47
48 cli = Cli()
49 cli(*sys.argv)