summaryrefslogtreecommitdiffstats
path: root/lib/bb/persist_data.py
diff options
context:
space:
mode:
authorChris Larson <chris_larson@mentor.com>2011-02-11 09:42:38 -0700
committerChris Larson <chris_larson@mentor.com>2011-02-11 09:55:11 -0700
commit34c7ff67d7f4c7dde2027e000def1a49f3286829 (patch)
tree3537e0b1d7e65b0a9970f2962b4bca2cd96de3fb /lib/bb/persist_data.py
parentc197043717ce621c345800bde689b1231fe8b679 (diff)
downloadbitbake-contrib-34c7ff67d7f4c7dde2027e000def1a49f3286829.tar.gz
persist_data: drop SQLData indirection
The common case (if not the only case) is to only use a single domain. The only reason SQLData exists is to make it easier to delete a domain. Yet, there's no need for us to delete a domain if SQLTable knows how to clear itself out. So, add clear() to the table and pass the domain to persist(). Signed-off-by: Chris Larson <chris_larson@mentor.com>
Diffstat (limited to 'lib/bb/persist_data.py')
-rw-r--r--lib/bb/persist_data.py39
1 files changed, 9 insertions, 30 deletions
diff --git a/lib/bb/persist_data.py b/lib/bb/persist_data.py
index b3a9e5f22..b5ce371d9 100644
--- a/lib/bb/persist_data.py
+++ b/lib/bb/persist_data.py
@@ -107,33 +107,8 @@ class SQLTable(collections.MutableMapping):
def iteritems(self):
return self._execute("SELECT * FROM %s;" % self.table)
-
-class SQLData(object):
- """Object representing the persistent data"""
- def __init__(self, filename):
- bb.utils.mkdirhier(os.path.dirname(filename))
-
- self.filename = filename
- self.connection = sqlite3.connect(filename, timeout=5,
- isolation_level=None)
- self.cursor = self.connection.cursor()
- self._tables = {}
-
- def __getitem__(self, table):
- if not isinstance(table, basestring):
- raise TypeError("table argument must be a string, not '%s'" %
- type(table))
-
- if table in self._tables:
- return self._tables[table]
- else:
- tableobj = self._tables[table] = SQLTable(self.cursor, table)
- return tableobj
-
- def __delitem__(self, table):
- if table in self._tables:
- del self._tables[table]
- self.cursor.execute("DROP TABLE IF EXISTS %s;" % table)
+ def clear(self):
+ self._execute("DELETE FROM %s;" % self.table)
class PersistData(object):
@@ -183,14 +158,18 @@ class PersistData(object):
"""
del self.data[domain][key]
+def connect(database):
+ return sqlite3.connect(database, timeout=5, isolation_level=None)
-def persist(d):
- """Convenience factory for construction of SQLData based upon metadata"""
+def persist(domain, d):
+ """Convenience factory for SQLTable objects based upon metadata"""
cachedir = (bb.data.getVar("PERSISTENT_DIR", d, True) or
bb.data.getVar("CACHE", d, True))
if not cachedir:
logger.critical("Please set the 'PERSISTENT_DIR' or 'CACHE' variable")
sys.exit(1)
+ bb.utils.mkdirhier(cachedir)
cachefile = os.path.join(cachedir, "bb_persist_data.sqlite3")
- return SQLData(cachefile)
+ connection = connect(cachefile)
+ return SQLTable(connection, domain)