]>
Commit | Line | Data |
---|---|---|
677ff42a MT |
1 | #!/usr/bin/python |
2 | ||
3 | import logging | |
4 | import os | |
5 | import socket | |
6 | import xmlrpclib | |
7 | ||
7c8f2953 MT |
8 | import pakfire |
9 | import pakfire.base | |
a52f536c MT |
10 | import pakfire.downloader |
11 | import pakfire.packages | |
12 | ||
13 | from pakfire.errors import * | |
14 | ||
677ff42a | 15 | class Slave(object): |
7c8f2953 MT |
16 | def __init__(self, **pakfire_args): |
17 | self.pakfire = pakfire.base.Pakfire(**pakfire_args) | |
677ff42a MT |
18 | |
19 | server = self.pakfire.config._slave.get("server") | |
20 | ||
21 | logging.info("Establishing RPC connection to: %s" % server) | |
22 | ||
23 | self.conn = xmlrpclib.Server(server) | |
24 | ||
a52f536c MT |
25 | @property |
26 | def hostname(self): | |
27 | """ | |
28 | Return the host's name. | |
29 | """ | |
30 | return socket.gethostname() | |
31 | ||
677ff42a MT |
32 | def keepalive(self): |
33 | """ | |
34 | Send the server a keep-alive to say that we are still there. | |
35 | """ | |
a52f536c | 36 | hostname = self.hostname |
677ff42a MT |
37 | l1, l5, l15 = os.getloadavg() |
38 | ||
39 | logging.info("Sending the server a keepalive: %s" % hostname) | |
40 | ||
a52f536c MT |
41 | # Get all supported architectures and send them to the server. |
42 | arches = [a for a in self.pakfire.supported_arches] | |
43 | arches.sort() | |
44 | ||
45 | self.conn.keepalive(hostname, l5, arches) | |
46 | ||
47 | def update_build_status(self, build_id, status, message=""): | |
48 | self.conn.update_build_state(build_id, status, message) | |
49 | ||
50 | def build_job(self): | |
51 | build = self.conn.build_job(self.hostname) | |
52 | ||
53 | # If the server has got no job for us, we end right here. | |
54 | if not build: | |
55 | return | |
56 | ||
57 | build_id = build["id"] | |
58 | filename = build["source"] | |
59 | ||
60 | # Get a package grabber and add mirror download capabilities to it. | |
61 | grabber = pakfire.downloader.PackageDownloader() | |
62 | ||
63 | # Temporary path to store the source. | |
7c8f2953 | 64 | tempfile = os.path.join("/var/tmp", os.path.basename(filename)) |
a52f536c MT |
65 | |
66 | # Download the source. | |
7c8f2953 | 67 | pkg = grabber.urlgrab(filename, filename=tempfile) |
a52f536c MT |
68 | |
69 | try: | |
70 | self.update_build_status(build_id, "running") | |
71 | ||
7c8f2953 | 72 | pakfire.build(pkg, build_id=build_id) |
a52f536c MT |
73 | |
74 | except DependencyError, e: | |
75 | self.update_build_status(build_id, "dependency_error", e) | |
76 | ||
77 | except: | |
78 | self.update_build_status(build_id, "failed") | |
7c8f2953 | 79 | raise |
a52f536c | 80 | |
7c8f2953 MT |
81 | else: |
82 | self.update_build_status(build_id, "finished") | |
677ff42a | 83 |