]> git.ipfire.org Git - people/jschlag/pbs.git/blob - src/scripts/pakfire-build-service
83aceb674ebdeaee8e585be12302caca26c54609
[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 # Check build dependencies
18 "check-build-dependencies" : self.backend.jobqueue.check_build_dependencies,
19
20 # Run mirror check
21 "check-mirrors" : self.backend.mirrors.check,
22
23 # Cleanup files
24 "cleanup-files" : self.backend.cleanup_files,
25
26 # Cleanup repositories
27 "cleanup-repositories" : self.backend.repos.cleanup,
28
29 # Cleanup sessions
30 "cleanup-sessions" : self.backend.sessions.cleanup,
31
32 # Cleanup uploads
33 "cleanup-uploads" : self.backend.uploads.cleanup,
34
35 # Create test jobs
36 "create-test-jobs" : self.backend.jobqueue.create_test_jobs,
37
38 # Dist
39 "dist" : self.backend.sources.dist,
40
41 # List repository
42 "list-repository" : self._list_repository,
43
44 # Sends all queued messages
45 "process-message-queue" : self.backend.messages.process_queue,
46
47 # Pull sources
48 "pull-sources" : self.backend.sources.pull,
49
50 # Remaster Repositories
51 "remaster-repositories" : self.backend.repos.remaster,
52
53 # Restart failed jobs
54 "restart-failed-jobs" : self.backend.jobs.restart_failed,
55
56 # Send bug updates to Bugzilla
57 "send-bug-updates" : self.backend.bugzilla.send_all,
58 }
59
60 def __call__(self, *args):
61 # Parse tornado settings
62 args = tornado.options.parse_command_line(args)
63
64 if not len(args) >= 1:
65 print >>sys.stderr, "Insufficient number of arguments"
66 return 2
67
68 args = list(args)
69 command = args.pop(0)
70
71 # Get called command
72 try:
73 command = self._commands[command]
74 except KeyError:
75 print >>sys.stderr, "Command not found: %s" % command
76 return 2
77
78 # Execute command
79 r = command(*args)
80
81 # Exit with error code
82 sys.exit(r or 0)
83
84 def _list_repository(self, distro_name, repo_name, arch):
85 # Get distribution
86 distro = self.backend.distros.get_by_name(distro_name)
87 if not distro:
88 print >>sys.stderr, "Could not find distribution: %s" % distro_name
89 return 2
90
91 # Get repository
92 repo = distro.get_repo(repo_name)
93 if not repo:
94 print >>sys.stderr, "Could not find repository: %s" % repo_name
95 return 2
96
97 # Iterate through all of it
98 for build in repo:
99 for job in build:
100 # Skip all test jobs
101 if job.test:
102 continue
103
104 if not job.arch in (arch, "noarch"):
105 continue
106
107 for pkg in job:
108 print pkg
109
110 # main
111
112 cli = Cli()
113 cli(*sys.argv)