Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndi_G <andigros72@googlemail.com>2011-09-11 17:28:25 (GMT)
committer Andi_G <andigros72@googlemail.com>2011-09-11 17:28:25 (GMT)
commit7252517d6d6ff0267fd753ae281c67144d442bf9 (patch)
tree835f8a8122c69a1ad238fd2101b9c905acfb0db7
parent99a6f57f2fbe89d04d41ccf31903144afe4249f5 (diff)
locally deleted annotations made by others are not stored locally again after the next download
-rw-r--r--readdb.py77
1 files changed, 36 insertions, 41 deletions
diff --git a/readdb.py b/readdb.py
index e2e7687..5ec129f 100644
--- a/readdb.py
+++ b/readdb.py
@@ -45,6 +45,9 @@ def _init_db():
#Situation 0: Db is existent
if os.path.exists(dbpath):
+ conn = sqlite3.connect(dbpath)
+ conn.execute("CREATE TABLE IF NOT EXISTS deleted_annotations (id INTEGER PRIMARY KEY, uuid)")
+ conn.commit()
return dbpath
#Situation 1: DB is non-existent at all
@@ -118,14 +121,14 @@ class BookmarkManager:
client = gconf.client_get_default()
user = client.get_string("/desktop/sugar/user/nick")
- # We delete only the locally made bookmark
-
t = (self._filehash, page, user)
self._conn.execute('delete from bookmarks where md5=? and page=? and user=?', t)
self._conn.commit()
self._resync_bookmark_cache()
+
+
def _populate_bookmarks(self):
# TODO: Figure out if caching the entire set of bookmarks is a good idea or not
rows = self._conn.execute('select * from bookmarks where md5=? order by page', (self._filehash,))
@@ -322,7 +325,6 @@ class AnnotationManager:
_logger.debug('got this color: %s' % color)
if self._userid == '':
self._userid = self.get_userid_for_username( self.get_user_string( user ) )
- _logger.debug('got this userid: %s' % self._userid)
note = simplejson.loads(content)
#note = cjson.decode(content)
@@ -330,14 +332,6 @@ class AnnotationManager:
self._content = note['body']
self._creator = self._userid
- _logger.debug('add_annotation content %s', self._content)
- _logger.debug('annotation annotates %s', self._annotates)
- #check what the url of the book is
- #store annotation locally
- #send annotation to server -> get url back, store url in body-url
- #update annotation body url in local db
-
-
#check the last id from the database store
row = self._conn.execute('select id from annotations order by id desc limit 1')
aid = 0
@@ -394,6 +388,8 @@ class AnnotationManager:
if row[1] == self._userid:
self._to_delete.append(row[0])
_logger.debug(str('schedule annotation %s for deletion' % str(row)))
+ else:
+ self._conn.execute('insert into deleted_annotations values (?, ?)', (None, row[0]))
t = (self._filehash, annotation_id)
_logger.debug(str('t for deletion is %s' % str(t)))
self._conn.execute('delete from annotations where md5=? and id=?', t)
@@ -634,10 +630,8 @@ class AnnotationManager:
url = self._annotationserver
annotations = []
annojson = ""
- _logger.debug("contacting annotationserver %s", url)
- #if self._annotates == "":
- # self._annotates = "_"
- #values = {'w3c_hasTarget' : self._annotates}
+ deleted_annotations_arr = self._conn.execute('select uuid from deleted_annotations')
+ deleted_annotations = [ r[0] for r in deleted_annotations_arr]
values = {'checksum' : self._filehash}
_logger.debug('download annotations -- annotates is: %s ' % self._annotates)
try:
@@ -662,32 +656,33 @@ class AnnotationManager:
self.remotecolors = {}
for a in anno_arr:
uuid = a.get_uuid()
- if uuid in localuuids:
- _logger.debug('uuid exists locally')
- ind = localuuids.index(uuid)
- rmodifiedtstamp = a.get_modified()
- _logger.debug(str('timestamps are remote: %d, local %d' % (rmodifiedtstamp, self._annotations[ind].get_modified())))
- if self._annotations[ind].get_modified() < rmodifiedtstamp - self.modifiedtolerance:
- _logger.debug('remote annotation is more recent than local annotation')
- #take over the content
- self._annotations[ind].set_note_title(a.get_note_title())
- self._annotations[ind].set_note_body(a.get_note_body())
- self._annotations[ind].set_modified(rmodifiedtstamp)
- self.update_annotation_db_record(a)
- _logger.debug(str('after update: timestamps are remote: %d, local %d' % (rmodifiedtstamp, self._annotations[ind].get_modified())))
- else:
- if self._annotations[ind].get_creator() == self._creator:
- _logger.debug(str('remote annotation is outdated, sending %s' % self._annotations[ind]))
- self.send_annotation_to_server(self._annotations[ind])
- else:
- remotecreator = a.get_creator()
- if not remotecreator in self.remotecreators:
- self.remotecreators.append(remotecreator)
- self.remotecolors[remotecreator] = XoColor()
- a.color = self.remotecolors[remotecreator]
- self.insert_annotation_db_record(a)
- self._annotations.append(a)
- self._sidebar.update_for_page(a.page)
+ if not uuid in deleted_annotations:
+ if uuid in localuuids:
+ _logger.debug('uuid exists locally')
+ ind = localuuids.index(uuid)
+ rmodifiedtstamp = a.get_modified()
+ _logger.debug(str('timestamps are remote: %d, local %d' % (rmodifiedtstamp, self._annotations[ind].get_modified())))
+ if self._annotations[ind].get_modified() < rmodifiedtstamp - self.modifiedtolerance:
+ _logger.debug('remote annotation is more recent than local annotation')
+ #take over the content
+ self._annotations[ind].set_note_title(a.get_note_title())
+ self._annotations[ind].set_note_body(a.get_note_body())
+ self._annotations[ind].set_modified(rmodifiedtstamp)
+ self.update_annotation_db_record(a)
+ _logger.debug(str('after update: timestamps are remote: %d, local %d' % (rmodifiedtstamp, self._annotations[ind].get_modified())))
+ else:
+ if self._annotations[ind].get_creator() == self._creator:
+ _logger.debug(str('remote annotation is outdated, sending %s' % self._annotations[ind]))
+ self.send_annotation_to_server(self._annotations[ind])
+ else:
+ remotecreator = a.get_creator()
+ if not remotecreator in self.remotecreators:
+ self.remotecreators.append(remotecreator)
+ self.remotecolors[remotecreator] = XoColor()
+ a.color = self.remotecolors[remotecreator]
+ self.insert_annotation_db_record(a)
+ self._annotations.append(a)
+ self._sidebar.update_for_page(a.page)