Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSayamindu Dasgupta <sayamindu@gmail.com>2009-08-05 17:59:08 (GMT)
committer Sayamindu Dasgupta <sayamindu@gmail.com>2009-08-05 17:59:08 (GMT)
commit98e358b9f712aa02a86e076387e6e567fb48167a (patch)
tree2a13d495f0dbe4b656d6b9f6e38ecf3d39bde29d
parent851a69a1fdb9cfb440369a0f8746e131c678d0bc (diff)
Add a path for moving to the new bookmark database schema
-rw-r--r--read_v1.db (renamed from read.db)bin2048 -> 2048 bytes
-rw-r--r--readdb.py48
2 files changed, 40 insertions, 8 deletions
diff --git a/read.db b/read_v1.db
index 5268778..fac21dd 100644
--- a/read.db
+++ b/read_v1.db
Binary files differ
diff --git a/readdb.py b/readdb.py
index c24a664..8309e0e 100644
--- a/readdb.py
+++ b/readdb.py
@@ -28,17 +28,50 @@ from readbookmark import Bookmark
_logger = logging.getLogger('read-activity')
+def _init_db():
+ dbdir = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'], 'data')
+ dbpath = os.path.join(dbdir, 'read_v1.db')
+ olddbpath = os.path.join(dbdir, 'read.db')
+
+ srcpath = os.path.join(os.environ['SUGAR_BUNDLE_PATH'], 'read_v1.db')
+
+ #Situation 0: Db is existent
+ if os.path.exists(dbpath):
+ return dbpath
+
+ #Situation 1: DB is non-existent at all
+ if not os.path.exists(dbpath) and not os.path.exists(olddbpath):
+ try:
+ os.makedirs(dbdir)
+ except:
+ pass
+ shutil.copy(srcpath, dbpath)
+ return dbpath
+
+ #Situation 2: DB is outdated
+ if not os.path.exists(dbpath) and os.path.exists(olddbpath):
+ shutil.copy(olddbpath, dbpath)
+
+ conn = sqlite3.connect(dbpath)
+ conn.execute("CREATE TABLE temp_bookmarks AS SELECT md5, page, title 'content', timestamp, user, color, local FROM bookmarks")
+ conn.execute("ALTER TABLE bookmarks RENAME TO bookmarks_old")
+ conn.execute("ALTER TABLE temp_bookmarks RENAME TO bookmarks")
+ conn.execute("DROP TABLE bookmarks_old")
+ conn.commit()
+ conn.close()
+
+ return dbpath
+
+ # Should not reach this point
+ return None
+
class BookmarkManager:
- def __init__(self, filehash, dbfile='read.db'):
+ def __init__(self, filehash):
self._filehash = filehash
- dbpath = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'], 'data', \
- dbfile)
+ dbpath = _init_db()
- if not os.path.exists(dbpath):
- # This makes me nervous
- srcpath = os.path.join(os.environ['SUGAR_BUNDLE_PATH'], 'read.db')
- shutil.copy(srcpath, dbpath)
+ assert dbpath != None
self._conn = sqlite3.connect(dbpath)
self._conn.text_factory = lambda x: unicode(x, "utf-8", "ignore")
@@ -55,7 +88,6 @@ class BookmarkManager:
user = client.get_string("/desktop/sugar/user/nick")
color = client.get_string("/desktop/sugar/user/color")
- #XXX: the field for content is called title for compatibility reasons
t = (self._filehash, page, content, timestamp, user, color, local)
self._conn.execute('insert into bookmarks values (?, ?, ?, ?, ?, ?, ?)', t)
self._conn.commit()