[tor-commits] [bridgedb/master] Remove bridgedb.Storage.openOrConvertDatabase().
isis at torproject.org
isis at torproject.org
Fri May 1 07:10:59 UTC 2015
commit fbe46fb0ef8103f3cd09842677034899098e7b8a
Author: Isis Lovecruft <isis at torproject.org>
Date: Tue Apr 21 22:52:25 2015 +0000
Remove bridgedb.Storage.openOrConvertDatabase().
The databases were converted *many* years ago. We don't need this cruft
anymore.
---
lib/bridgedb/Main.py | 2 +-
lib/bridgedb/Storage.py | 66 ++---------------------------------------------
2 files changed, 3 insertions(+), 65 deletions(-)
diff --git a/lib/bridgedb/Main.py b/lib/bridgedb/Main.py
index d5f4c24..116f827 100644
--- a/lib/bridgedb/Main.py
+++ b/lib/bridgedb/Main.py
@@ -412,7 +412,7 @@ def run(options, reactor=reactor):
# Initialize our DB.
bridgedb.Storage.initializeDBLock()
- db = bridgedb.Storage.openOrConvertDatabase(cfg.DB_FILE + ".sqlite", cfg.DB_FILE)
+ db = bridgedb.Storage.openDatabase(cfg.DB_FILE + ".sqlite")
bridgedb.Storage.setDBFilename(cfg.DB_FILE + ".sqlite")
load(state, splitter, clear=False)
diff --git a/lib/bridgedb/Storage.py b/lib/bridgedb/Storage.py
index 732d8ab..f9fcf43 100644
--- a/lib/bridgedb/Storage.py
+++ b/lib/bridgedb/Storage.py
@@ -130,11 +130,8 @@ class BridgeData:
self.last_seen = last_seen
class Database(object):
- def __init__(self, sqlite_fname, db_fname=None):
- if db_fname is None:
- self._conn = openDatabase(sqlite_fname)
- else:
- self._conn = openOrConvertDatabase(sqlite_fname, db_fname)
+ def __init__(self, sqlite_fname):
+ self._conn = openDatabase(sqlite_fname)
self._cur = self._conn.cursor()
self.sqlite_fname = sqlite_fname
@@ -326,62 +323,6 @@ def openDatabase(sqlite_file):
return conn
-def openOrConvertDatabase(sqlite_file, db_file):
- """Open a sqlite database, converting it from a db file if needed."""
- if os.path.exists(sqlite_file):
- return openDatabase(sqlite_file)
-
- conn = sqlite3.Connection(sqlite_file)
- cur = conn.cursor()
- cur.executescript(SCHEMA3_SCRIPT)
- conn.commit()
-
- import anydbm
-
- try:
- db = anydbm.open(db_file, 'r')
- except anydbm.error:
- return conn
-
- try:
- # We handle all the sp| keys first, since other tables have
- # dependencies on Bridges.
- for k in db.keys():
- v = db[k]
- if k.startswith("sp|"):
- assert len(k) == 23
- cur.execute("INSERT INTO Bridges ( hex_key, distributor ) "
- "VALUES (?, ?)", (toHex(k[3:]),v))
- # Now we handle the other key types.
- for k in db.keys():
- v = db[k]
- if k.startswith("fs|"):
- assert len(k) == 23
- cur.execute("UPDATE Bridges SET first_seen = ? "
- "WHERE hex_key = ?", (v, toHex(k[3:])))
- elif k.startswith("ls|"):
- assert len(k) == 23
- cur.execute("UPDATE Bridges SET last_seen = ? "
- "WHERE hex_key = ?", (v, toHex(k[3:])))
- #elif k.startswith("em|"):
- # keys = list(toHex(i) for i in
- # bridgedb.Bridges.chopString(v, bridgedb.Bridges.ID_LEN))
- # cur.executemany("INSERT INTO EmailedBridges ( email, id ) "
- # "SELECT ?, id FROM Bridges WHERE hex_key = ?",
- # [(k[3:],i) for i in keys])
- elif k.startswith("sp|") or k.startswith("em|"):
- pass
- else:
- logging.warn("Unrecognized key %r", k)
- except:
- conn.rollback()
- conn.close()
- os.unlink(sqlite_file)
- raise
-
- conn.commit()
- return conn
-
class DBGeneratorContextManager(GeneratorContextManager):
"""Helper for @contextmanager decorator.
@@ -470,9 +411,6 @@ def initializeDBLock():
_LOCK = threading.RLock()
assert _LOCK
-def checkAndConvertDB(sqlite_file, db_file):
- openOrConvertDatabase(sqlite_file, db_file).close()
-
def setDBFilename(sqlite_fname):
global _DB_FNAME
_DB_FNAME = sqlite_fname
More information about the tor-commits
mailing list