diff options
Diffstat (limited to 'bitbake/lib/prserv/serv.py')
-rw-r--r-- | bitbake/lib/prserv/serv.py | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/bitbake/lib/prserv/serv.py b/bitbake/lib/prserv/serv.py index 28af636966..49f5ae36db 100644 --- a/bitbake/lib/prserv/serv.py +++ b/bitbake/lib/prserv/serv.py | |||
@@ -21,14 +21,14 @@ singleton = None | |||
21 | 21 | ||
22 | class PRServerClient(bb.asyncrpc.AsyncServerConnection): | 22 | class PRServerClient(bb.asyncrpc.AsyncServerConnection): |
23 | def __init__(self, socket, server): | 23 | def __init__(self, socket, server): |
24 | super().__init__(socket, 'PRSERVICE', server.logger) | 24 | super().__init__(socket, "PRSERVICE", server.logger) |
25 | self.server = server | 25 | self.server = server |
26 | 26 | ||
27 | self.handlers.update({ | 27 | self.handlers.update({ |
28 | 'get-pr': self.handle_get_pr, | 28 | "get-pr": self.handle_get_pr, |
29 | 'import-one': self.handle_import_one, | 29 | "import-one": self.handle_import_one, |
30 | 'export': self.handle_export, | 30 | "export": self.handle_export, |
31 | 'is-readonly': self.handle_is_readonly, | 31 | "is-readonly": self.handle_is_readonly, |
32 | }) | 32 | }) |
33 | 33 | ||
34 | def validate_proto_version(self): | 34 | def validate_proto_version(self): |
@@ -44,14 +44,14 @@ class PRServerClient(bb.asyncrpc.AsyncServerConnection): | |||
44 | self.server.table.sync_if_dirty() | 44 | self.server.table.sync_if_dirty() |
45 | 45 | ||
46 | async def handle_get_pr(self, request): | 46 | async def handle_get_pr(self, request): |
47 | version = request['version'] | 47 | version = request["version"] |
48 | pkgarch = request['pkgarch'] | 48 | pkgarch = request["pkgarch"] |
49 | checksum = request['checksum'] | 49 | checksum = request["checksum"] |
50 | 50 | ||
51 | response = None | 51 | response = None |
52 | try: | 52 | try: |
53 | value = self.server.table.getValue(version, pkgarch, checksum) | 53 | value = self.server.table.getValue(version, pkgarch, checksum) |
54 | response = {'value': value} | 54 | response = {"value": value} |
55 | except prserv.NotFoundError: | 55 | except prserv.NotFoundError: |
56 | logger.error("can not find value for (%s, %s)",version, checksum) | 56 | logger.error("can not find value for (%s, %s)",version, checksum) |
57 | except sqlite3.Error as exc: | 57 | except sqlite3.Error as exc: |
@@ -62,22 +62,22 @@ class PRServerClient(bb.asyncrpc.AsyncServerConnection): | |||
62 | async def handle_import_one(self, request): | 62 | async def handle_import_one(self, request): |
63 | response = None | 63 | response = None |
64 | if not self.server.read_only: | 64 | if not self.server.read_only: |
65 | version = request['version'] | 65 | version = request["version"] |
66 | pkgarch = request['pkgarch'] | 66 | pkgarch = request["pkgarch"] |
67 | checksum = request['checksum'] | 67 | checksum = request["checksum"] |
68 | value = request['value'] | 68 | value = request["value"] |
69 | 69 | ||
70 | value = self.server.table.importone(version, pkgarch, checksum, value) | 70 | value = self.server.table.importone(version, pkgarch, checksum, value) |
71 | if value is not None: | 71 | if value is not None: |
72 | response = {'value': value} | 72 | response = {"value": value} |
73 | 73 | ||
74 | return response | 74 | return response |
75 | 75 | ||
76 | async def handle_export(self, request): | 76 | async def handle_export(self, request): |
77 | version = request['version'] | 77 | version = request["version"] |
78 | pkgarch = request['pkgarch'] | 78 | pkgarch = request["pkgarch"] |
79 | checksum = request['checksum'] | 79 | checksum = request["checksum"] |
80 | colinfo = request['colinfo'] | 80 | colinfo = request["colinfo"] |
81 | 81 | ||
82 | try: | 82 | try: |
83 | (metainfo, datainfo) = self.server.table.export(version, pkgarch, checksum, colinfo) | 83 | (metainfo, datainfo) = self.server.table.export(version, pkgarch, checksum, colinfo) |
@@ -85,10 +85,10 @@ class PRServerClient(bb.asyncrpc.AsyncServerConnection): | |||
85 | logger.error(str(exc)) | 85 | logger.error(str(exc)) |
86 | metainfo = datainfo = None | 86 | metainfo = datainfo = None |
87 | 87 | ||
88 | return {'metainfo': metainfo, 'datainfo': datainfo} | 88 | return {"metainfo": metainfo, "datainfo": datainfo} |
89 | 89 | ||
90 | async def handle_is_readonly(self, request): | 90 | async def handle_is_readonly(self, request): |
91 | return {'readonly': self.server.read_only} | 91 | return {"readonly": self.server.read_only} |
92 | 92 | ||
93 | class PRServer(bb.asyncrpc.AsyncServer): | 93 | class PRServer(bb.asyncrpc.AsyncServer): |
94 | def __init__(self, dbfile, read_only=False): | 94 | def __init__(self, dbfile, read_only=False): |
@@ -135,7 +135,7 @@ class PRServSingleton(object): | |||
135 | if not self.prserv.address: | 135 | if not self.prserv.address: |
136 | raise PRServiceConfigError | 136 | raise PRServiceConfigError |
137 | if not self.port: | 137 | if not self.port: |
138 | self.port = int(self.prserv.address.rsplit(':', 1)[1]) | 138 | self.port = int(self.prserv.address.rsplit(":", 1)[1]) |
139 | 139 | ||
140 | def run_as_daemon(func, pidfile, logfile): | 140 | def run_as_daemon(func, pidfile, logfile): |
141 | """ | 141 | """ |
@@ -171,12 +171,12 @@ def run_as_daemon(func, pidfile, logfile): | |||
171 | # stdout/stderr or it could be 'real' unix fd forking where we need | 171 | # stdout/stderr or it could be 'real' unix fd forking where we need |
172 | # to physically close the fds to prevent the program launching us from | 172 | # to physically close the fds to prevent the program launching us from |
173 | # potentially hanging on a pipe. Handle both cases. | 173 | # potentially hanging on a pipe. Handle both cases. |
174 | si = open('/dev/null', 'r') | 174 | si = open("/dev/null", "r") |
175 | try: | 175 | try: |
176 | os.dup2(si.fileno(),sys.stdin.fileno()) | 176 | os.dup2(si.fileno(),sys.stdin.fileno()) |
177 | except (AttributeError, io.UnsupportedOperation): | 177 | except (AttributeError, io.UnsupportedOperation): |
178 | sys.stdin = si | 178 | sys.stdin = si |
179 | so = open(logfile, 'a+') | 179 | so = open(logfile, "a+") |
180 | try: | 180 | try: |
181 | os.dup2(so.fileno(),sys.stdout.fileno()) | 181 | os.dup2(so.fileno(),sys.stdout.fileno()) |
182 | except (AttributeError, io.UnsupportedOperation): | 182 | except (AttributeError, io.UnsupportedOperation): |
@@ -200,7 +200,7 @@ def run_as_daemon(func, pidfile, logfile): | |||
200 | 200 | ||
201 | # write pidfile | 201 | # write pidfile |
202 | pid = str(os.getpid()) | 202 | pid = str(os.getpid()) |
203 | with open(pidfile, 'w') as pf: | 203 | with open(pidfile, "w") as pf: |
204 | pf.write("%s\n" % pid) | 204 | pf.write("%s\n" % pid) |
205 | 205 | ||
206 | func() | 206 | func() |
@@ -245,12 +245,12 @@ def stop_daemon(host, port): | |||
245 | # so at least advise the user which ports the corresponding server is listening | 245 | # so at least advise the user which ports the corresponding server is listening |
246 | ports = [] | 246 | ports = [] |
247 | portstr = "" | 247 | portstr = "" |
248 | for pf in glob.glob(PIDPREFIX % (ip,'*')): | 248 | for pf in glob.glob(PIDPREFIX % (ip, "*")): |
249 | bn = os.path.basename(pf) | 249 | bn = os.path.basename(pf) |
250 | root, _ = os.path.splitext(bn) | 250 | root, _ = os.path.splitext(bn) |
251 | ports.append(root.split('_')[-1]) | 251 | ports.append(root.split("_")[-1]) |
252 | if len(ports): | 252 | if len(ports): |
253 | portstr = "Wrong port? Other ports listening at %s: %s" % (host, ' '.join(ports)) | 253 | portstr = "Wrong port? Other ports listening at %s: %s" % (host, " ".join(ports)) |
254 | 254 | ||
255 | sys.stderr.write("pidfile %s does not exist. Daemon not running? %s\n" | 255 | sys.stderr.write("pidfile %s does not exist. Daemon not running? %s\n" |
256 | % (pidfile,portstr)) | 256 | % (pidfile,portstr)) |
@@ -284,7 +284,7 @@ def is_running(pid): | |||
284 | return True | 284 | return True |
285 | 285 | ||
286 | def is_local_special(host, port): | 286 | def is_local_special(host, port): |
287 | if (host == 'localhost' or host == '127.0.0.1') and not port: | 287 | if (host == "localhost" or host == "127.0.0.1") and not port: |
288 | return True | 288 | return True |
289 | else: | 289 | else: |
290 | return False | 290 | return False |
@@ -295,7 +295,7 @@ class PRServiceConfigError(Exception): | |||
295 | def auto_start(d): | 295 | def auto_start(d): |
296 | global singleton | 296 | global singleton |
297 | 297 | ||
298 | host_params = list(filter(None, (d.getVar('PRSERV_HOST') or '').split(':'))) | 298 | host_params = list(filter(None, (d.getVar("PRSERV_HOST") or "").split(":"))) |
299 | if not host_params: | 299 | if not host_params: |
300 | # Shutdown any existing PR Server | 300 | # Shutdown any existing PR Server |
301 | auto_shutdown() | 301 | auto_shutdown() |
@@ -304,7 +304,7 @@ def auto_start(d): | |||
304 | if len(host_params) != 2: | 304 | if len(host_params) != 2: |
305 | # Shutdown any existing PR Server | 305 | # Shutdown any existing PR Server |
306 | auto_shutdown() | 306 | auto_shutdown() |
307 | logger.critical('\n'.join(['PRSERV_HOST: incorrect format', | 307 | logger.critical("\n".join(["PRSERV_HOST: incorrect format", |
308 | 'Usage: PRSERV_HOST = "<hostname>:<port>"'])) | 308 | 'Usage: PRSERV_HOST = "<hostname>:<port>"'])) |
309 | raise PRServiceConfigError | 309 | raise PRServiceConfigError |
310 | 310 | ||
@@ -357,8 +357,8 @@ def connect(host, port): | |||
357 | 357 | ||
358 | global singleton | 358 | global singleton |
359 | 359 | ||
360 | if host.strip().lower() == 'localhost' and not port: | 360 | if host.strip().lower() == "localhost" and not port: |
361 | host = 'localhost' | 361 | host = "localhost" |
362 | port = singleton.port | 362 | port = singleton.port |
363 | 363 | ||
364 | conn = client.PRClient() | 364 | conn = client.PRClient() |