]> git.phdru.name Git - bookmarks_db.git/commitdiff
Store json.
authorOleg Broytman <phd@phdru.name>
Fri, 23 Jul 2010 18:38:01 +0000 (18:38 +0000)
committerOleg Broytman <phd@phdru.name>
Fri, 23 Jul 2010 18:38:01 +0000 (18:38 +0000)
git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@233 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23

Storage/bkmk_stjson.py

index 32efdff1d24dc41962b9b2eae0b14d967dbda18f..fd77d59f0dcfb6db12d68cb21e78427561588f3f 100644 (file)
@@ -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)