3 Run through the bookmarks database and set names to titles from an external file
5 Written by Broytman. Copyright (C) 2003-2007 PhiloSoft Design.
13 from getopt import getopt
14 optlist, args = getopt(sys.argv[1:], "s")
18 for _opt, _arg in optlist:
27 print "Broytman set-title-list, Copyright (C) 2003-2007 PhiloSoft Design"
30 sys.stderr.write("Usage: set-title-list [-s] title_list_file\n")
33 # Read the external file with titles and build a mapping (URL => title)
39 title_list_file = open(args[0], 'r')
40 for line in title_list_file:
41 line = line[:-1] # strip trailing newline
48 elif line: # the third line in every 3 lines must be empty
49 raise ValueError, "line is not empty for URL `%s', title `%s': line `%s'" % (URL, title, line)
51 else: # We've got 3 lines - add new entry to the mapping
52 if titles_dict.has_key(URL):
53 if title <> titles_dict[URL]:
54 raise ValueError, "titles are not identical for URL `%s': `%s' <> `%s'" % (URL, title, titles_dict[URL])
57 titles_dict[URL] = title
63 title_list_file.close()
66 from storage import storage
70 sys.stdout.write("Loading %s: " % storage.filename)
73 root_folder = storage.load()
74 from bkmk_objects import make_linear, break_tree
75 make_linear(root_folder)
76 objects = len(root_folder.linear)
82 # Run through the list of objects and check URLs/titles
84 for object_no in range(objects):
85 object = root_folder.linear[object_no]
89 if titles_dict.has_key(URL):
90 name = titles_dict[URL]
91 if object.name <> name:
96 if changed and report_stats:
97 sys.stdout.write("Saving %s: " % storage.filename)
100 if not changed and report_stats:
101 sys.stdout.write("No need to save data\n")
105 break_tree(root_folder.linear)
106 storage.store(root_folder)
108 if changed and report_stats:
110 print objects, "objects passed"
111 print changed, "objects changed"
114 if __name__ == '__main__':