]> git.ipfire.org Git - people/jschlag/pbs.git/blob - src/scripts/pakfire-build-service
Cleanup expired sessions once a day
[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 sessions
18 "cleanup-sessions" : self.backend.sessions.cleanup,
19
20 # Cleanup uploads
21 "cleanup-uploads" : self.backend.uploads.cleanup,
22
23 # Sends all queued messages
24 "process-message-queue" : self.backend.messages.process_queue,
25 }
26
27 def __call__(self, *args):
28 if not len(args) >= 2:
29 print >>sys.stderr, "Insufficient number of arguments"
30 return 2
31
32 args = list(args)
33 basename = args.pop(0)
34 command = args.pop(0)
35
36 # Get called command
37 try:
38 command = self._commands[command]
39 except KeyError:
40 print >>sys.stderr, "Command not found: %s" % command
41 return 2
42
43 # Execute command
44 r = command(*args)
45
46 # Exit with error code
47 sys.exit(r or 0)
48
49 # main
50
51 cli = Cli()
52 cli(*sys.argv)