From b5844ee1c12d89f210e39d17e876434a72a01f56 Mon Sep 17 00:00:00 2001 From: Chris Drexler Date: Wed, 2 Jan 2019 16:11:21 +0100 Subject: [PATCH] REF(buku) ff json import improve debug logging --- buku | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/buku b/buku index c8faa97..ee3c319 100755 --- a/buku +++ b/buku @@ -2428,7 +2428,7 @@ class BukuDb: items = import_firefox_json(data, add_bookmark_folder_as_tag, newtag) except ValueError as e: - LOGERR("JSON Decode Error: {}".format(e)) + LOGERR("ff_json: JSON Decode Error: {}".format(e)) return False except Exception as e: LOGERR(e) @@ -2981,7 +2981,7 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None) ] return d[0]['value'] except Exception: - LOGDBG("No description found for entry: {} {}".format(entry['uri'], entry['title'])) + LOGDBG("ff_json: No description found for entry: {} {}".format(entry['uri'], entry['title'])) return "" def extract_tags(entry): @@ -2989,7 +2989,7 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None) try: tags = entry['tags'].split(',') except Exception: - LOGDBG("No tags found for entry: {} {}".format(entry['uri'], entry['title'])) + LOGDBG("ff_json: No tags found for entry: {} {}".format(entry['uri'], entry['title'])) return tags @@ -2998,17 +2998,18 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None) try: typeCode = bm_entry['typeCode'] except Exception: - LOGDBG("item without typeCode found, ignoring: {}".format(bm_entry['title'])) + LOGDBG("ff_json: item without typeCode found, ignoring: {}".format(bm_entry['title'])) continue + LOGDBG("ff_json: processing typeCode '{}', title '{}'".format(typeCode, bm_entry['title'])) if TypeCode.uri.value == typeCode: try: if is_smart(bm_entry): - LOGDBG("SmartBookmark found, ignoring: {}".format(bm_entry['title'])) + LOGDBG("ff_json: SmartBookmark found, ignoring: {}".format(bm_entry['title'])) continue if is_nongeneric_url(bm_entry['uri']): - LOGDBG("Non-Generic URL found, ignoring: {}".format(bm_entry['title'])) + LOGDBG("ff_json: Non-Generic URL found, ignoring: {}".format(bm_entry['title'])) continue desc = extract_desc(bm_entry) @@ -3024,11 +3025,11 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None) formatted_tags = [DELIM + tag for tag in bookmark_tags] tags = parse_tags(formatted_tags) - LOGDBG("Entry found: {}, {}, {}, {} " - .format(bm_entry['uri'], bm_entry['title'], tags, desc)) + LOGDBG("ff_json: Entry found: {}, {}, {}, {} " .format(bm_entry['uri'], bm_entry['title'], tags, desc)) yield (bm_entry['uri'], bm_entry['title'], tags, desc, 0, True, False) + except Exception as e: - LOGERR("Error parsing entry '{}' Exception '{}'".format(bm_entry['title'], e)) + LOGERR("ff_json: Error parsing entry '{}' Exception '{}'".format(bm_entry['title'], e)) elif TypeCode.folder.value == typeCode: try: @@ -3041,28 +3042,34 @@ def import_firefox_json(json, add_bookmark_folder_as_tag=False, unique_tag=None) except Exception: # if any of the properties does not exist, bail out silently - LOGDBG("No 'children' found in bookmark folder - skipping: {}".format(bm_entry['title'])) + LOGDBG("ff_json: No 'children' found in bookmark folder - skipping: {}".format(bm_entry['title'])) elif TypeCode.separator.value == typeCode: - LOGDBG("Unknown typeCode found : {}".format(typeCode)) + LOGDBG("ff_json: Unknown typeCode found : {}".format(typeCode)) try: main_entry_list = json['children'] except Exception: - LOGERR("No children in Root entry found") + LOGDBG("ff_json: No children in Root entry found") return [] # interate over each main bookmark container, ignoring main container title # assuming all entries with 'children' are containers, skipping typeCode test for main_container in main_entry_list: try: - yield from iterate_children(None, main_container['children']) + main_container_title = main_container['title'] except Exception: - try: - title = main_container['title'] - except Exception: - title = None - LOGDBG("No 'children' found in main bookmark folder - skipping: {}".format(title)) + main_container_title = "
" + + try: + main_container_children = main_container['children'] + except Exception: + main_container_children = None + LOGDBG("ff_json: No 'children' found in main bookmark folder - skipping: {}".format(main_container_title)) + + if main_container_children: + LOGDBG("ff_json: main bookmark folder : {}".format(main_container_title)) + yield from iterate_children(None, main_container_children) def import_html(html_soup, add_parent_folder_as_tag, newtag):