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