From 3bc7824ef023e60e84ba4402e658836304c248e3 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Fri, 23 Jul 2010 18:38:01 +0000 Subject: [PATCH] Store json. git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@233 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23 --- Storage/bkmk_stjson.py | 53 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/Storage/bkmk_stjson.py b/Storage/bkmk_stjson.py index 32efdff..fd77d59 100644 --- a/Storage/bkmk_stjson.py +++ b/Storage/bkmk_stjson.py @@ -17,16 +17,59 @@ class storage_json(Walker): filename = "bookmarks_db.json" def root_folder(self, f): - self.dict = {} + self.dict = dict = {} + dict["children"] = children = [] + self.folder_stack = [children] + dict["dateAdded"] = f.add_date + dict["id"] = f.id + dict["lastModified"] = f.last_modified + dict["root"] = "placesRoot" + dict["title"] = "" + dict["type"] = "text/x-moz-place-container" def start_folder(self, f, level): - pass + dict = {} + dict["children"] = children = [] + dict["dateAdded"] = f.add_date + dict["id"] = f.id + index = getattr(f, 'index') + if index: dict["index"] = index + dict["lastModified"] = f.last_modified + parent_idx = getattr(f, 'parent_idx') + if parent_idx: dict["parent"] = parent_idx + dict["title"] = f.name.decode('utf-8') + dict["type"] = "text/x-moz-place-container" + self.folder_stack[-1].append(dict) + self.folder_stack.append(children) + + def end_folder(self, f, level): + del self.folder_stack[-1] def bookmark(self, b, level): - pass + dict = {} + charset = getattr(b, 'charset') + if charset: dict["charset"] = charset + dict["dateAdded"] = b.add_date + dict["id"] = b.id + index = getattr(b, 'index') + if index: dict["index"] = index + dict["lastModified"] = b.last_modified + dict["parent"] = b.parent_idx + dict["title"] = b.name.decode('utf-8') + dict["type"] = "text/x-moz-place" + dict["uri"] = b.href + self.folder_stack[-1].append(dict) def ruler(self, r, level): - pass + dict = {} + dict["dateAdded"] = r.add_date + dict["id"] = r.id + dict["index"] = r.index + dict["lastModified"] = r.last_modified + dict["parent"] = r.parent_idx + dict["title"] = r.name.decode('utf-8') + dict["type"] = "text/x-moz-place-separator" + self.folder_stack[-1].append(dict) def store(self, root_folder): root_folder.walk_depth(self) @@ -66,7 +109,6 @@ class storage_json(Walker): folder.parent_idx = _dict.get("parent") folder.name = encode(_dict["title"]) - folder.href = _dict.get("uri") folder.comment = '' folder.add_date = _dict["dateAdded"] folder.last_modified = _dict["lastModified"] @@ -79,6 +121,7 @@ class storage_json(Walker): last_modified=record.get("lastModified"), charset=record.get("charset")) bookmark.id = record["id"] + bookmark.index = record.get("index") bookmark.parent_idx = record["parent"] bookmark.name = encode(record["title"]) self.current_folder.append(bookmark) -- 2.39.2