summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/hashserv/__init__.py
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2019-07-24 09:13:55 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-08-06 11:21:31 +0100
commitca04aaf7b51e3ee2bb04da970d5f20f2c9982cb8 (patch)
treeee5fe5d5e780cd965bbe7f9a0d25d91d280b1834 /bitbake/lib/hashserv/__init__.py
parentd9aafb85072bef3b5baa54408969d54a8425a111 (diff)
downloadpoky-ca04aaf7b51e3ee2bb04da970d5f20f2c9982cb8.tar.gz
bitbake: cooker/hashserv: Allow autostarting of a local hash server using BB_HASHSERVE
Its useful, particularly in the local developer model of usage, for bitbake to start and stop a hash equivalence server on local port, rather than relying on one being started by the user before the build. The new BB_HASHSERVE variable supports this. The database handling is moved internally into the hashserv code so that different threads/processes can be used for the server without errors. (Bitbake rev: a4fa8f1bd88995ae60e10430316fbed63d478587) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/hashserv/__init__.py')
-rw-r--r--bitbake/lib/hashserv/__init__.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/bitbake/lib/hashserv/__init__.py b/bitbake/lib/hashserv/__init__.py
index 768c5504cf..7ec9b64419 100644
--- a/bitbake/lib/hashserv/__init__.py
+++ b/bitbake/lib/hashserv/__init__.py
@@ -18,8 +18,15 @@ class HashEquivalenceServer(BaseHTTPRequestHandler):
18 def log_message(self, f, *args): 18 def log_message(self, f, *args):
19 logger.debug(f, *args) 19 logger.debug(f, *args)
20 20
21 def opendb(self):
22 self.db = sqlite3.connect(self.dbname)
23 self.db.row_factory = sqlite3.Row
24
21 def do_GET(self): 25 def do_GET(self):
22 try: 26 try:
27 if not self.db:
28 self.opendb()
29
23 p = urllib.parse.urlparse(self.path) 30 p = urllib.parse.urlparse(self.path)
24 31
25 if p.path != self.prefix + '/v1/equivalent': 32 if p.path != self.prefix + '/v1/equivalent':
@@ -52,6 +59,9 @@ class HashEquivalenceServer(BaseHTTPRequestHandler):
52 59
53 def do_POST(self): 60 def do_POST(self):
54 try: 61 try:
62 if not self.db:
63 self.opendb()
64
55 p = urllib.parse.urlparse(self.path) 65 p = urllib.parse.urlparse(self.path)
56 66
57 if p.path != self.prefix + '/v1/equivalent': 67 if p.path != self.prefix + '/v1/equivalent':
@@ -123,14 +133,17 @@ class HashEquivalenceServer(BaseHTTPRequestHandler):
123 self.send_error(400, explain=traceback.format_exc()) 133 self.send_error(400, explain=traceback.format_exc())
124 return 134 return
125 135
126def create_server(addr, db, prefix=''): 136def create_server(addr, dbname, prefix=''):
127 class Handler(HashEquivalenceServer): 137 class Handler(HashEquivalenceServer):
128 pass 138 pass
129 139
130 Handler.prefix = prefix 140 db = sqlite3.connect(dbname)
131 Handler.db = db
132 db.row_factory = sqlite3.Row 141 db.row_factory = sqlite3.Row
133 142
143 Handler.prefix = prefix
144 Handler.db = None
145 Handler.dbname = dbname
146
134 with contextlib.closing(db.cursor()) as cursor: 147 with contextlib.closing(db.cursor()) as cursor:
135 cursor.execute(''' 148 cursor.execute('''
136 CREATE TABLE IF NOT EXISTS tasks_v2 ( 149 CREATE TABLE IF NOT EXISTS tasks_v2 (