diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2010-06-04 14:04:41 +0200 |
---|---|---|
committer | Richard Purdie <rpurdie@linux.intel.com> | 2010-07-02 15:41:35 +0100 |
commit | 726802b98071f6139c9305be0383a2be20a37f4e (patch) | |
tree | 0864d2a7084f1681c6f14660f4940ca5ddb00672 /bitbake/lib | |
parent | 30216c65e59e7072bed5001598240dcc58017940 (diff) | |
download | poky-726802b98071f6139c9305be0383a2be20a37f4e.tar.gz |
persist_data: cache connection and use cursor
Store database connection to persistent database in fetcher.
(Bitbake rev: 8a6876752b90efd81d92f0947bfc9527d8260969)
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Signed-off-by: Chris Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <rpurdie@linux.intel.com>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/bb/fetch/__init__.py | 9 | ||||
-rw-r--r-- | bitbake/lib/bb/persist_data.py | 21 |
2 files changed, 18 insertions, 12 deletions
diff --git a/bitbake/lib/bb/fetch/__init__.py b/bitbake/lib/bb/fetch/__init__.py index 01bcd36539..701e79025a 100644 --- a/bitbake/lib/bb/fetch/__init__.py +++ b/bitbake/lib/bb/fetch/__init__.py | |||
@@ -146,13 +146,14 @@ def uri_replace(uri, uri_find, uri_replace, d): | |||
146 | methods = [] | 146 | methods = [] |
147 | urldata_cache = {} | 147 | urldata_cache = {} |
148 | saved_headrevs = {} | 148 | saved_headrevs = {} |
149 | persistent_database_connection = {} | ||
149 | 150 | ||
150 | def fetcher_init(d): | 151 | def fetcher_init(d): |
151 | """ | 152 | """ |
152 | Called to initialize the fetchers once the configuration data is known. | 153 | Called to initialize the fetchers once the configuration data is known. |
153 | Calls before this must not hit the cache. | 154 | Calls before this must not hit the cache. |
154 | """ | 155 | """ |
155 | pd = persist_data.PersistData(d) | 156 | pd = persist_data.PersistData(d, persistent_database_connection) |
156 | # When to drop SCM head revisions controlled by user policy | 157 | # When to drop SCM head revisions controlled by user policy |
157 | srcrev_policy = bb.data.getVar('BB_SRCREV_POLICY', d, 1) or "clear" | 158 | srcrev_policy = bb.data.getVar('BB_SRCREV_POLICY', d, 1) or "clear" |
158 | if srcrev_policy == "cache": | 159 | if srcrev_policy == "cache": |
@@ -181,7 +182,7 @@ def fetcher_compare_revisons(d): | |||
181 | return true/false on whether they've changed. | 182 | return true/false on whether they've changed. |
182 | """ | 183 | """ |
183 | 184 | ||
184 | pd = persist_data.PersistData(d) | 185 | pd = persist_data.PersistData(d, persistent_database_connection) |
185 | data = pd.getKeyValues("BB_URI_HEADREVS") | 186 | data = pd.getKeyValues("BB_URI_HEADREVS") |
186 | data2 = bb.fetch.saved_headrevs | 187 | data2 = bb.fetch.saved_headrevs |
187 | 188 | ||
@@ -673,7 +674,7 @@ class Fetch(object): | |||
673 | if not hasattr(self, "_latest_revision"): | 674 | if not hasattr(self, "_latest_revision"): |
674 | raise ParameterError | 675 | raise ParameterError |
675 | 676 | ||
676 | pd = persist_data.PersistData(d) | 677 | pd = persist_data.PersistData(d, persistent_database_connection) |
677 | key = self.generate_revision_key(url, ud, d) | 678 | key = self.generate_revision_key(url, ud, d) |
678 | rev = pd.getValue("BB_URI_HEADREVS", key) | 679 | rev = pd.getValue("BB_URI_HEADREVS", key) |
679 | if rev != None: | 680 | if rev != None: |
@@ -690,7 +691,7 @@ class Fetch(object): | |||
690 | if hasattr(self, "_sortable_revision"): | 691 | if hasattr(self, "_sortable_revision"): |
691 | return self._sortable_revision(url, ud, d) | 692 | return self._sortable_revision(url, ud, d) |
692 | 693 | ||
693 | pd = persist_data.PersistData(d) | 694 | pd = persist_data.PersistData(d, persistent_database_connection) |
694 | key = self.generate_revision_key(url, ud, d) | 695 | key = self.generate_revision_key(url, ud, d) |
695 | 696 | ||
696 | latest_rev = self._build_revision(url, ud, d) | 697 | latest_rev = self._build_revision(url, ud, d) |
diff --git a/bitbake/lib/bb/persist_data.py b/bitbake/lib/bb/persist_data.py index 80ddeb5560..df0409cd8a 100644 --- a/bitbake/lib/bb/persist_data.py +++ b/bitbake/lib/bb/persist_data.py | |||
@@ -43,7 +43,10 @@ class PersistData: | |||
43 | 43 | ||
44 | Why sqlite? It handles all the locking issues for us. | 44 | Why sqlite? It handles all the locking issues for us. |
45 | """ | 45 | """ |
46 | def __init__(self, d): | 46 | def __init__(self, d, persistent_database_connection): |
47 | if "connection" in persistent_database_connection: | ||
48 | self.cursor = persistent_database_connection["connection"].cursor() | ||
49 | return | ||
47 | self.cachedir = bb.data.getVar("PERSISTENT_DIR", d, True) or bb.data.getVar("CACHE", d, True) | 50 | self.cachedir = bb.data.getVar("PERSISTENT_DIR", d, True) or bb.data.getVar("CACHE", d, True) |
48 | if self.cachedir in [None, '']: | 51 | if self.cachedir in [None, '']: |
49 | bb.msg.fatal(bb.msg.domain.PersistData, "Please set the 'PERSISTENT_DIR' or 'CACHE' variable.") | 52 | bb.msg.fatal(bb.msg.domain.PersistData, "Please set the 'PERSISTENT_DIR' or 'CACHE' variable.") |
@@ -55,27 +58,29 @@ class PersistData: | |||
55 | self.cachefile = os.path.join(self.cachedir, "bb_persist_data.sqlite3") | 58 | self.cachefile = os.path.join(self.cachedir, "bb_persist_data.sqlite3") |
56 | bb.msg.debug(1, bb.msg.domain.PersistData, "Using '%s' as the persistent data cache" % self.cachefile) | 59 | bb.msg.debug(1, bb.msg.domain.PersistData, "Using '%s' as the persistent data cache" % self.cachefile) |
57 | 60 | ||
58 | self.connection = sqlite3.connect(self.cachefile, timeout=5, isolation_level=None) | 61 | connection = sqlite3.connect(self.cachefile, timeout=5, isolation_level=None) |
62 | persistent_database_connection["connection"] = connection | ||
63 | self.cursor = persistent_database_connection["connection"].cursor() | ||
59 | 64 | ||
60 | def addDomain(self, domain): | 65 | def addDomain(self, domain): |
61 | """ | 66 | """ |
62 | Should be called before any domain is used | 67 | Should be called before any domain is used |
63 | Creates it if it doesn't exist. | 68 | Creates it if it doesn't exist. |
64 | """ | 69 | """ |
65 | self.connection.execute("CREATE TABLE IF NOT EXISTS %s(key TEXT, value TEXT);" % domain) | 70 | self.cursor.execute("CREATE TABLE IF NOT EXISTS %s(key TEXT, value TEXT);" % domain) |
66 | 71 | ||
67 | def delDomain(self, domain): | 72 | def delDomain(self, domain): |
68 | """ | 73 | """ |
69 | Removes a domain and all the data it contains | 74 | Removes a domain and all the data it contains |
70 | """ | 75 | """ |
71 | self.connection.execute("DROP TABLE IF EXISTS %s;" % domain) | 76 | self.cursor.execute("DROP TABLE IF EXISTS %s;" % domain) |
72 | 77 | ||
73 | def getKeyValues(self, domain): | 78 | def getKeyValues(self, domain): |
74 | """ | 79 | """ |
75 | Return a list of key + value pairs for a domain | 80 | Return a list of key + value pairs for a domain |
76 | """ | 81 | """ |
77 | ret = {} | 82 | ret = {} |
78 | data = self.connection.execute("SELECT key, value from %s;" % domain) | 83 | data = self.cursor.execute("SELECT key, value from %s;" % domain) |
79 | for row in data: | 84 | for row in data: |
80 | ret[str(row[0])] = str(row[1]) | 85 | ret[str(row[0])] = str(row[1]) |
81 | 86 | ||
@@ -85,7 +90,7 @@ class PersistData: | |||
85 | """ | 90 | """ |
86 | Return the value of a key for a domain | 91 | Return the value of a key for a domain |
87 | """ | 92 | """ |
88 | data = self.connection.execute("SELECT * from %s where key=?;" % domain, [key]) | 93 | data = self.cursor.execute("SELECT * from %s where key=?;" % domain, [key]) |
89 | for row in data: | 94 | for row in data: |
90 | return row[1] | 95 | return row[1] |
91 | 96 | ||
@@ -93,7 +98,7 @@ class PersistData: | |||
93 | """ | 98 | """ |
94 | Sets the value of a key for a domain | 99 | Sets the value of a key for a domain |
95 | """ | 100 | """ |
96 | data = self.connection.execute("SELECT * from %s where key=?;" % domain, [key]) | 101 | data = self.cursor.execute("SELECT * from %s where key=?;" % domain, [key]) |
97 | rows = 0 | 102 | rows = 0 |
98 | for row in data: | 103 | for row in data: |
99 | rows = rows + 1 | 104 | rows = rows + 1 |
@@ -111,7 +116,7 @@ class PersistData: | |||
111 | def _execute(self, *query): | 116 | def _execute(self, *query): |
112 | while True: | 117 | while True: |
113 | try: | 118 | try: |
114 | self.connection.execute(*query) | 119 | self.cursor.execute(*query) |
115 | return | 120 | return |
116 | except sqlite3.OperationalError as e: | 121 | except sqlite3.OperationalError as e: |
117 | if 'database is locked' in str(e): | 122 | if 'database is locked' in str(e): |