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