diff options
Diffstat (limited to 'bitbake/lib/bb/persist_data.py')
-rw-r--r-- | bitbake/lib/bb/persist_data.py | 80 |
1 files changed, 25 insertions, 55 deletions
diff --git a/bitbake/lib/bb/persist_data.py b/bitbake/lib/bb/persist_data.py index c6a209fb3f..bcca791edf 100644 --- a/bitbake/lib/bb/persist_data.py +++ b/bitbake/lib/bb/persist_data.py | |||
@@ -12,14 +12,14 @@ currently, providing a key/value store accessed by 'domain'. | |||
12 | # | 12 | # |
13 | 13 | ||
14 | import collections | 14 | import collections |
15 | import collections.abc | ||
15 | import contextlib | 16 | import contextlib |
16 | import functools | 17 | import functools |
17 | import logging | 18 | import logging |
18 | import os.path | 19 | import os.path |
19 | import sqlite3 | 20 | import sqlite3 |
20 | import sys | 21 | import sys |
21 | import warnings | 22 | from collections.abc import Mapping |
22 | from collections import Mapping | ||
23 | 23 | ||
24 | sqlversion = sqlite3.sqlite_version_info | 24 | sqlversion = sqlite3.sqlite_version_info |
25 | if sqlversion[0] < 3 or (sqlversion[0] == 3 and sqlversion[1] < 3): | 25 | if sqlversion[0] < 3 or (sqlversion[0] == 3 and sqlversion[1] < 3): |
@@ -29,7 +29,7 @@ if sqlversion[0] < 3 or (sqlversion[0] == 3 and sqlversion[1] < 3): | |||
29 | logger = logging.getLogger("BitBake.PersistData") | 29 | logger = logging.getLogger("BitBake.PersistData") |
30 | 30 | ||
31 | @functools.total_ordering | 31 | @functools.total_ordering |
32 | class SQLTable(collections.MutableMapping): | 32 | class SQLTable(collections.abc.MutableMapping): |
33 | class _Decorators(object): | 33 | class _Decorators(object): |
34 | @staticmethod | 34 | @staticmethod |
35 | def retry(*, reconnect=True): | 35 | def retry(*, reconnect=True): |
@@ -63,7 +63,7 @@ class SQLTable(collections.MutableMapping): | |||
63 | """ | 63 | """ |
64 | Decorator that starts a database transaction and creates a database | 64 | Decorator that starts a database transaction and creates a database |
65 | cursor for performing queries. If no exception is thrown, the | 65 | cursor for performing queries. If no exception is thrown, the |
66 | database results are commited. If an exception occurs, the database | 66 | database results are committed. If an exception occurs, the database |
67 | is rolled back. In all cases, the cursor is closed after the | 67 | is rolled back. In all cases, the cursor is closed after the |
68 | function ends. | 68 | function ends. |
69 | 69 | ||
@@ -208,7 +208,7 @@ class SQLTable(collections.MutableMapping): | |||
208 | 208 | ||
209 | def __lt__(self, other): | 209 | def __lt__(self, other): |
210 | if not isinstance(other, Mapping): | 210 | if not isinstance(other, Mapping): |
211 | raise NotImplemented | 211 | raise NotImplementedError() |
212 | 212 | ||
213 | return len(self) < len(other) | 213 | return len(self) < len(other) |
214 | 214 | ||
@@ -238,55 +238,6 @@ class SQLTable(collections.MutableMapping): | |||
238 | def has_key(self, key): | 238 | def has_key(self, key): |
239 | return key in self | 239 | return key in self |
240 | 240 | ||
241 | |||
242 | class PersistData(object): | ||
243 | """Deprecated representation of the bitbake persistent data store""" | ||
244 | def __init__(self, d): | ||
245 | warnings.warn("Use of PersistData is deprecated. Please use " | ||
246 | "persist(domain, d) instead.", | ||
247 | category=DeprecationWarning, | ||
248 | stacklevel=2) | ||
249 | |||
250 | self.data = persist(d) | ||
251 | logger.debug("Using '%s' as the persistent data cache", | ||
252 | self.data.filename) | ||
253 | |||
254 | def addDomain(self, domain): | ||
255 | """ | ||
256 | Add a domain (pending deprecation) | ||
257 | """ | ||
258 | return self.data[domain] | ||
259 | |||
260 | def delDomain(self, domain): | ||
261 | """ | ||
262 | Removes a domain and all the data it contains | ||
263 | """ | ||
264 | del self.data[domain] | ||
265 | |||
266 | def getKeyValues(self, domain): | ||
267 | """ | ||
268 | Return a list of key + value pairs for a domain | ||
269 | """ | ||
270 | return list(self.data[domain].items()) | ||
271 | |||
272 | def getValue(self, domain, key): | ||
273 | """ | ||
274 | Return the value of a key for a domain | ||
275 | """ | ||
276 | return self.data[domain][key] | ||
277 | |||
278 | def setValue(self, domain, key, value): | ||
279 | """ | ||
280 | Sets the value of a key for a domain | ||
281 | """ | ||
282 | self.data[domain][key] = value | ||
283 | |||
284 | def delValue(self, domain, key): | ||
285 | """ | ||
286 | Deletes a key/value pair | ||
287 | """ | ||
288 | del self.data[domain][key] | ||
289 | |||
290 | def persist(domain, d): | 241 | def persist(domain, d): |
291 | """Convenience factory for SQLTable objects based upon metadata""" | 242 | """Convenience factory for SQLTable objects based upon metadata""" |
292 | import bb.utils | 243 | import bb.utils |
@@ -298,4 +249,23 @@ def persist(domain, d): | |||
298 | 249 | ||
299 | bb.utils.mkdirhier(cachedir) | 250 | bb.utils.mkdirhier(cachedir) |
300 | cachefile = os.path.join(cachedir, "bb_persist_data.sqlite3") | 251 | cachefile = os.path.join(cachedir, "bb_persist_data.sqlite3") |
301 | return SQLTable(cachefile, domain) | 252 | |
253 | try: | ||
254 | return SQLTable(cachefile, domain) | ||
255 | except sqlite3.OperationalError: | ||
256 | # Sqlite fails to open database when its path is too long. | ||
257 | # After testing, 504 is the biggest path length that can be opened by | ||
258 | # sqlite. | ||
259 | # Note: This code is called before sanity.bbclass and its path length | ||
260 | # check | ||
261 | max_len = 504 | ||
262 | if len(cachefile) > max_len: | ||
263 | logger.critical("The path of the cache file is too long " | ||
264 | "({0} chars > {1}) to be opened by sqlite! " | ||
265 | "Your cache file is \"{2}\"".format( | ||
266 | len(cachefile), | ||
267 | max_len, | ||
268 | cachefile)) | ||
269 | sys.exit(1) | ||
270 | else: | ||
271 | raise | ||