]>
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 | ||
764b87d2 MT |
29 | # List repository |
30 | "list-repository" : self._list_repository, | |
31 | ||
c06ce6d1 MT |
32 | # Sends all queued messages |
33 | "process-message-queue" : self.backend.messages.process_queue, | |
76353712 | 34 | |
6cd8afe7 MT |
35 | # Pull sources |
36 | "pull-sources" : self.backend.sources.pull, | |
37 | ||
9729c5b3 MT |
38 | # Remaster Repositories |
39 | "remaster-repositories" : self.backend.repositories.remaster, | |
40 | ||
76353712 MT |
41 | # Send bug updates to Bugzilla |
42 | "send-bug-updates" : self.backend.bugzilla.send_all, | |
c06ce6d1 | 43 | } |
43025dca MT |
44 | |
45 | def __call__(self, *args): | |
46 | if not len(args) >= 2: | |
47 | print >>sys.stderr, "Insufficient number of arguments" | |
48 | return 2 | |
49 | ||
50 | args = list(args) | |
51 | basename = args.pop(0) | |
52 | command = args.pop(0) | |
53 | ||
54 | # Get called command | |
55 | try: | |
56 | command = self._commands[command] | |
57 | except KeyError: | |
58 | print >>sys.stderr, "Command not found: %s" % command | |
59 | return 2 | |
60 | ||
61 | # Execute command | |
62 | r = command(*args) | |
63 | ||
64 | # Exit with error code | |
65 | sys.exit(r or 0) | |
66 | ||
764b87d2 MT |
67 | def _list_repository(self, distro_name, repo_name, arch): |
68 | # Get distribution | |
69 | distro = self.backend.distros.get_by_name(distro_name) | |
70 | if not distro: | |
71 | print >>sys.stderr, "Could not find distribution: %s" % distro_name | |
72 | return 2 | |
73 | ||
74 | # Get repository | |
75 | repo = distro.get_repo(repo_name) | |
76 | if not repo: | |
77 | print >>sys.stderr, "Could not find repository: %s" % repo_name | |
78 | return 2 | |
79 | ||
80 | # Iterate through all of it | |
81 | for build in repo: | |
82 | for job in build: | |
83 | if not job.type == "build": | |
84 | continue | |
85 | ||
86 | if not job.arch in (arch, "noarch"): | |
87 | continue | |
88 | ||
89 | for pkg in job: | |
90 | print pkg | |
91 | ||
43025dca MT |
92 | # main |
93 | ||
94 | cli = Cli() | |
95 | cli(*sys.argv) |