diff options
Diffstat (limited to 'lib/bb/persist_data.py')
-rw-r--r-- | lib/bb/persist_data.py | 80 |
1 files changed, 25 insertions, 55 deletions
diff --git a/lib/bb/persist_data.py b/lib/bb/persist_data.py index 5f4fbe350..bcca791ed 100644 --- a/lib/bb/persist_data.py +++ b/lib/bb/persist_data.py @@ -12,14 +12,14 @@ currently, providing a key/value store accessed by 'domain'. # import collections +import collections.abc import contextlib import functools import logging import os.path import sqlite3 import sys -import warnings -from collections import Mapping +from collections.abc import Mapping sqlversion = sqlite3.sqlite_version_info 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): logger = logging.getLogger("BitBake.PersistData") @functools.total_ordering -class SQLTable(collections.MutableMapping): +class SQLTable(collections.abc.MutableMapping): class _Decorators(object): @staticmethod def retry(*, reconnect=True): @@ -63,7 +63,7 @@ class SQLTable(collections.MutableMapping): """ Decorator that starts a database transaction and creates a database cursor for performing queries. If no exception is thrown, the - database results are commited. If an exception occurs, the database + database results are committed. If an exception occurs, the database is rolled back. In all cases, the cursor is closed after the function ends. @@ -208,7 +208,7 @@ class SQLTable(collections.MutableMapping): def __lt__(self, other): if not isinstance(other, Mapping): - raise NotImplemented + raise NotImplementedError() return len(self) < len(other) @@ -238,55 +238,6 @@ class SQLTable(collections.MutableMapping): def has_key(self, key): return key in self - -class PersistData(object): - """Deprecated representation of the bitbake persistent data store""" - def __init__(self, d): - warnings.warn("Use of PersistData is deprecated. Please use " - "persist(domain, d) instead.", - category=DeprecationWarning, - stacklevel=2) - - self.data = persist(d) - logger.debug(1, "Using '%s' as the persistent data cache", - self.data.filename) - - def addDomain(self, domain): - """ - Add a domain (pending deprecation) - """ - return self.data[domain] - - def delDomain(self, domain): - """ - Removes a domain and all the data it contains - """ - del self.data[domain] - - def getKeyValues(self, domain): - """ - Return a list of key + value pairs for a domain - """ - return list(self.data[domain].items()) - - def getValue(self, domain, key): - """ - Return the value of a key for a domain - """ - return self.data[domain][key] - - def setValue(self, domain, key, value): - """ - Sets the value of a key for a domain - """ - self.data[domain][key] = value - - def delValue(self, domain, key): - """ - Deletes a key/value pair - """ - del self.data[domain][key] - def persist(domain, d): """Convenience factory for SQLTable objects based upon metadata""" import bb.utils @@ -298,4 +249,23 @@ def persist(domain, d): bb.utils.mkdirhier(cachedir) cachefile = os.path.join(cachedir, "bb_persist_data.sqlite3") - return SQLTable(cachefile, domain) + + try: + return SQLTable(cachefile, domain) + except sqlite3.OperationalError: + # Sqlite fails to open database when its path is too long. + # After testing, 504 is the biggest path length that can be opened by + # sqlite. + # Note: This code is called before sanity.bbclass and its path length + # check + max_len = 504 + if len(cachefile) > max_len: + logger.critical("The path of the cache file is too long " + "({0} chars > {1}) to be opened by sqlite! " + "Your cache file is \"{2}\"".format( + len(cachefile), + max_len, + cachefile)) + sys.exit(1) + else: + raise |