]> git.phdru.name Git - bookmarks_db.git/commitdiff
Fix(storage): Adapt to the latest Mozilla format
authorOleg Broytman <phd@phdru.name>
Tue, 1 Aug 2017 22:14:29 +0000 (01:14 +0300)
committerOleg Broytman <phd@phdru.name>
Tue, 1 Aug 2017 22:14:29 +0000 (01:14 +0300)
Mobile Bookmarks folder doesn't have children.

Storage/bkmk_stjson.py

index 5fbeda88ea110d2098c30594b00b86aba9df24b6..6053bd1d360f0fda72991ab53b360406df6beba1 100644 (file)
@@ -134,46 +134,47 @@ class storage_json(Walker):
         folder.root = fdict.get("root")
         folder.name = encode_title(fdict["title"])
 
-        for record in fdict["children"]:
-            if record["type"] == "text/x-moz-place-container":
-                folder = Folder(
-                    add_date=convert_date_from_json(record.get("dateAdded")),
-                    comment=get_comment(record.get("annos")),
-                    last_modified=convert_date_from_json(record.get("lastModified")))
-                folder.guid = record.get("guid")
-                self.current_folder.append(folder)
-                self.folder_stack.append(folder)
-                self.current_folder = folder
-                self.load_folder(folder, record)
-
-            elif record["type"] == "text/x-moz-place":
-                bookmark = Bookmark(
-                    href=record["uri"].encode('utf-8'),
-                    add_date=convert_date_from_json(record.get("dateAdded")),
-                    last_modified=convert_date_from_json(record.get("lastModified")),
-                    keyword=get_str(record, "keyword"),
-                    comment=get_comment(record.get("annos")),
-                    icon_href=record.get("iconuri"),
-                    charset=get_str(record, "charset"))
-                bookmark.guid = record.get("guid")
-                bookmark.id = record["id"]
-                bookmark.index = record.get("index")
-                bookmark.name = encode_title(record["title"])
-                self.current_folder.append(bookmark)
-
-            elif record["type"] == "text/x-moz-place-separator":
-                ruler = Ruler()
-                ruler.add_date = convert_date_from_json(record.get("dateAdded"))
-                ruler.guid = record.get("guid")
-                ruler.id = record["id"]
-                ruler.index = record["index"]
-                ruler.last_modified = convert_date_from_json(record.get("lastModified"))
-                ruler.name = encode_title(record.get("title"))
-                ruler.comment = get_comment(record.get("annos"))
-                self.current_folder.append(ruler)
-
-            else:
-                raise ValueError('Unknown record type "%s"' % record["type"])
+        if "children" in fdict:
+            for record in fdict["children"]:
+                if record["type"] == "text/x-moz-place-container":
+                    folder = Folder(
+                        add_date=convert_date_from_json(record.get("dateAdded")),
+                        comment=get_comment(record.get("annos")),
+                        last_modified=convert_date_from_json(record.get("lastModified")))
+                    folder.guid = record.get("guid")
+                    self.current_folder.append(folder)
+                    self.folder_stack.append(folder)
+                    self.current_folder = folder
+                    self.load_folder(folder, record)
+
+                elif record["type"] == "text/x-moz-place":
+                    bookmark = Bookmark(
+                        href=record["uri"].encode('utf-8'),
+                        add_date=convert_date_from_json(record.get("dateAdded")),
+                        last_modified=convert_date_from_json(record.get("lastModified")),
+                        keyword=get_str(record, "keyword"),
+                        comment=get_comment(record.get("annos")),
+                        icon_href=record.get("iconuri"),
+                        charset=get_str(record, "charset"))
+                    bookmark.guid = record.get("guid")
+                    bookmark.id = record["id"]
+                    bookmark.index = record.get("index")
+                    bookmark.name = encode_title(record["title"])
+                    self.current_folder.append(bookmark)
+
+                elif record["type"] == "text/x-moz-place-separator":
+                    ruler = Ruler()
+                    ruler.add_date = convert_date_from_json(record.get("dateAdded"))
+                    ruler.guid = record.get("guid")
+                    ruler.id = record["id"]
+                    ruler.index = record["index"]
+                    ruler.last_modified = convert_date_from_json(record.get("lastModified"))
+                    ruler.name = encode_title(record.get("title"))
+                    ruler.comment = get_comment(record.get("annos"))
+                    self.current_folder.append(ruler)
+
+                else:
+                    raise ValueError('Unknown record type "%s"' % record["type"])
 
         del self.folder_stack[-1]
         if self.folder_stack: