]>
Commit | Line | Data |
---|---|---|
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 | # Sends all queued messages | |
18 | "process-message-queue" : self.backend.messages.process_queue, | |
19 | } | |
20 | ||
21 | def __call__(self, *args): | |
22 | if not len(args) >= 2: | |
23 | print >>sys.stderr, "Insufficient number of arguments" | |
24 | return 2 | |
25 | ||
26 | args = list(args) | |
27 | basename = args.pop(0) | |
28 | command = args.pop(0) | |
29 | ||
30 | # Get called command | |
31 | try: | |
32 | command = self._commands[command] | |
33 | except KeyError: | |
34 | print >>sys.stderr, "Command not found: %s" % command | |
35 | return 2 | |
36 | ||
37 | # Execute command | |
38 | r = command(*args) | |
39 | ||
40 | # Exit with error code | |
41 | sys.exit(r or 0) | |
42 | ||
43 | # main | |
44 | ||
45 | cli = Cli() | |
46 | cli(*sys.argv) |