From 3a248e2d5c95bcc5b92db5fe9cd637bc201edec5 Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Thu, 12 Jun 2014 17:38:12 +0400 Subject: [PATCH] Add helper scripts to debug JSON storage --- Storage/debug-json/bkmk-pprint-json | 17 +++++++++++++++++ Storage/debug-json/pprint-json.py | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100755 Storage/debug-json/bkmk-pprint-json create mode 100755 Storage/debug-json/pprint-json.py diff --git a/Storage/debug-json/bkmk-pprint-json b/Storage/debug-json/bkmk-pprint-json new file mode 100755 index 0000000..7d4a4eb --- /dev/null +++ b/Storage/debug-json/bkmk-pprint-json @@ -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 index 0000000..2df6a81 --- /dev/null +++ b/Storage/debug-json/pprint-json.py @@ -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) -- 2.39.5