From: Oleg Broytman Date: Tue, 1 Aug 2017 22:14:29 +0000 (+0300) Subject: Fix(storage): Adapt to the latest Mozilla format X-Git-Tag: 5.0.0~106 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=9e3b27b8e808eb8d1453f25ef733efb8cbc41d31;p=bookmarks_db.git Fix(storage): Adapt to the latest Mozilla format Mobile Bookmarks folder doesn't have children. --- diff --git a/Storage/bkmk_stjson.py b/Storage/bkmk_stjson.py index 5fbeda8..6053bd1 100644 --- a/Storage/bkmk_stjson.py +++ b/Storage/bkmk_stjson.py @@ -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: