2 """Run through the bookmarks database and set names to titles from an external file
4 This file is a part of Bookmarks database and Internet robot.
7 __author__ = "Oleg Broytman <phd@phdru.name>"
8 __copyright__ = "Copyright (C) 2003-2012 PhiloSoft Design"
9 __license__ = "GNU GPL"
15 from getopt import getopt
16 optlist, args = getopt(sys.argv[1:], "s")
20 for _opt, _arg in optlist:
29 print "Broytman set-title-list, Copyright (C) 2003-2007 PhiloSoft Design"
32 sys.stderr.write("Usage: set-title-list [-s] title_list_file\n")
35 # Read the external file with titles and build a mapping (URL => title)
41 title_list_file = open(args[0], 'r')
42 for line in title_list_file:
43 line = line[:-1] # strip trailing newline
50 elif line: # the third line in every 3 lines must be empty
51 raise ValueError, "line is not empty for URL `%s', title `%s': line `%s'" % (URL, title, line)
53 else: # We've got 3 lines - add new entry to the mapping
54 if titles_dict.has_key(URL):
55 if title <> titles_dict[URL]:
56 raise ValueError, "titles are not identical for URL `%s': `%s' <> `%s'" % (URL, title, titles_dict[URL])
59 titles_dict[URL] = title
65 title_list_file.close()
68 from storage import storage
72 sys.stdout.write("Loading %s: " % storage.filename)
75 root_folder = storage.load()
76 from bkmk_objects import make_linear, break_tree
77 make_linear(root_folder)
78 objects = len(root_folder.linear)
84 # Run through the list of objects and check URLs/titles
86 for object_no in range(objects):
87 object = root_folder.linear[object_no]
91 if titles_dict.has_key(URL):
92 name = titles_dict[URL]
93 if object.name <> name:
98 if changed and report_stats:
99 sys.stdout.write("Saving %s: " % storage.filename)
102 if not changed and report_stats:
103 sys.stdout.write("No need to save data\n")
107 break_tree(root_folder.linear)
108 storage.store(root_folder)
110 if changed and report_stats:
112 print objects, "objects passed"
113 print changed, "objects changed"
116 if __name__ == '__main__':