X-Git-Url: https://git.phdru.name/?p=bookmarks_db.git;a=blobdiff_plain;f=check_dups.py;h=0a267ac60544a28322657df7ba7227aa26e7deaa;hp=f635c23ad9c48011c619a5ec0fcfaa4dcef3c818;hb=c88cb7a75e7caf1d67466cfa107981d95115fa0c;hpb=a04eaa0346e8aa5ad86a195f8f4d36487ebfe09c diff --git a/check_dups.py b/check_dups.py index f635c23..0a267ac 100755 --- a/check_dups.py +++ b/check_dups.py @@ -16,79 +16,79 @@ __license__ = "GNU GPL" log_file = None def report_dup(href, object_no): - s = "Duplicate URL: %s (first at rec. %d)" % (href, object_no) + s = "Duplicate URL: %s (first at rec. %d)" % (href, object_no) - if log_file: - log_file.write("%s\n" % s) - else: - print(s) + if log_file: + log_file.write("%s\n" % s) + else: + print(s) def run(): - from getopt import getopt - optlist, args = getopt(sys.argv[1:], "sl:") + from getopt import getopt + optlist, args = getopt(sys.argv[1:], "sl:") - report_stats = 1 - global log_file - log_filename = None + report_stats = 1 + global log_file + log_filename = None - for _opt, _arg in optlist: - if _opt == '-s': - report_stats = 0 - if _opt == '-l': - log_filename = _arg - try: - del _opt, _arg - except NameError: - pass + for _opt, _arg in optlist: + if _opt == '-s': + report_stats = 0 + if _opt == '-l': + log_filename = _arg + try: + del _opt, _arg + except NameError: + pass - if report_stats: - print("Broytman check_dups, Copyright (C) 2000-2017 PhiloSoft Design") + if report_stats: + print("Broytman check_dups, Copyright (C) 2000-2017 PhiloSoft Design") - if args: - sys.stderr.write("check_urls: too many arguments\n") - sys.stderr.write("Usage: check_urls [-s] [-l logfile]\n") - sys.exit(1) + if args: + sys.stderr.write("check_urls: too many arguments\n") + sys.stderr.write("Usage: check_urls [-s] [-l logfile]\n") + sys.exit(1) - if log_filename: - log_file = open(log_filename, 'w') + if log_filename: + log_file = open(log_filename, 'w') - from storage import storage - storage = storage() + from storage import storage + storage = storage() - if report_stats: - sys.stdout.write("Loading %s: " % storage.filename) - sys.stdout.flush() + if report_stats: + sys.stdout.write("Loading %s: " % storage.filename) + sys.stdout.flush() - root_folder = storage.load() - from bkmk_objects import make_linear - make_linear(root_folder) - objects = len(root_folder.linear) + root_folder = storage.load() + from bkmk_objects import make_linear + make_linear(root_folder) + objects = len(root_folder.linear) - if report_stats: - print("Ok") + if report_stats: + print("Ok") - dup_dict = {} + dup_dict = {} - for object_no in range(objects): - object = root_folder.linear[object_no] + for object_no in range(objects): + object = root_folder.linear[object_no] - if object.isBookmark: - href = object.href - if dup_dict.has_key(href): - report_dup(href, dup_dict[href]) - else: - dup_dict[href] = object_no + if object.isBookmark: + href = object.href + if dup_dict.has_key(href): + report_dup(href, dup_dict[href]) + else: + dup_dict[href] = object_no - if log_filename: - log_file.close() + if log_filename: + log_file.close() - if report_stats: - print("Ok") - print(objects, "objects passed") + if report_stats: + print("Ok") + print(objects, "objects passed") if __name__ == '__main__': - run() + run()