]>
Commit | Line | Data |
---|---|---|
43025dca MT |
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 | ||
c06ce6d1 | 16 | self._commands = { |
c660ff59 | 17 | # Run mirror check |
cda268cc | 18 | "check-mirrors" : self.backend.mirrors.check, |
c660ff59 | 19 | |
0f302058 MT |
20 | # Cleanup files |
21 | "cleanup-files" : self.backend.cleanup_files, | |
22 | ||
ca4f2d92 MT |
23 | # Cleanup sessions |
24 | "cleanup-sessions" : self.backend.sessions.cleanup, | |
25 | ||
be8d5956 MT |
26 | # Cleanup uploads |
27 | "cleanup-uploads" : self.backend.uploads.cleanup, | |
28 | ||
c06ce6d1 MT |
29 | # Sends all queued messages |
30 | "process-message-queue" : self.backend.messages.process_queue, | |
76353712 | 31 | |
6cd8afe7 MT |
32 | # Pull sources |
33 | "pull-sources" : self.backend.sources.pull, | |
34 | ||
76353712 MT |
35 | # Send bug updates to Bugzilla |
36 | "send-bug-updates" : self.backend.bugzilla.send_all, | |
c06ce6d1 | 37 | } |
43025dca MT |
38 | |
39 | def __call__(self, *args): | |
40 | if not len(args) >= 2: | |
41 | print >>sys.stderr, "Insufficient number of arguments" | |
42 | return 2 | |
43 | ||
44 | args = list(args) | |
45 | basename = args.pop(0) | |
46 | command = args.pop(0) | |
47 | ||
48 | # Get called command | |
49 | try: | |
50 | command = self._commands[command] | |
51 | except KeyError: | |
52 | print >>sys.stderr, "Command not found: %s" % command | |
53 | return 2 | |
54 | ||
55 | # Execute command | |
56 | r = command(*args) | |
57 | ||
58 | # Exit with error code | |
59 | sys.exit(r or 0) | |
60 | ||
61 | # main | |
62 | ||
63 | cli = Cli() | |
64 | cli(*sys.argv) |