]> git.phdru.name Git - bookmarks_db.git/commitdiff
Add helper scripts to debug JSON storage
authorOleg Broytman <phd@phdru.name>
Thu, 12 Jun 2014 13:38:12 +0000 (17:38 +0400)
committerOleg Broytman <phd@phdru.name>
Thu, 12 Jun 2014 13:38:12 +0000 (17:38 +0400)
Storage/debug-json/bkmk-pprint-json [new file with mode: 0755]
Storage/debug-json/pprint-json.py [new file with mode: 0755]

diff --git a/Storage/debug-json/bkmk-pprint-json b/Storage/debug-json/bkmk-pprint-json
new file mode 100755 (executable)
index 0000000..7d4a4eb
--- /dev/null
@@ -0,0 +1,17 @@
+#! /bin/sh
+
+DEBUG_DIR="`pwd`"
+cd "`dirname \"$0\"`"/../..
+. "`dirname \"$0\"`"/set-path
+cd "$DEBUG_DIR"
+
+rm -f bookmarks_db.json bookmarks_db.pickle bookmarks_db.txt \
+   mozilla.json mozilla.txt json.diff
+ln -s "$HOME"/Desktop/bookmarks-*.json bookmarks_db.json &&
+BKMK_STORAGE=json convert_st.py pickle &&
+mv bookmarks_db.json mozilla.json &&
+convert_st.py json &&
+
+./pprint-json.py mozilla.json >mozilla.txt &&
+./pprint-json.py bookmarks_db.json >bookmarks_db.txt &&
+exec diff bookmarks_db.txt mozilla.txt >json.diff
diff --git a/Storage/debug-json/pprint-json.py b/Storage/debug-json/pprint-json.py
new file mode 100755 (executable)
index 0000000..2df6a81
--- /dev/null
@@ -0,0 +1,16 @@
+#! /usr/bin/env python
+
+import sys
+import json
+from pprint import pprint
+
+infile = open(sys.argv[1], 'rb')
+bkmk_s = infile.read()
+infile.close()
+
+# Work around a bug in Mozilla - remove the trailing comma
+bkmk_s = bkmk_s.strip().replace(',]', ']')
+bookmarks_dict = json.loads(bkmk_s)
+del bkmk_s
+
+pprint(bookmarks_dict)