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 __version__ = "$Revision$"[11:-2]
8 __revision__ = "$Id$"[5:-2]
9 __date__ = "$Date$"[7:-2]
10 __author__ = "Oleg Broytman <phd@phdru.name>"
11 __copyright__ = "Copyright (C) 2003-2011 PhiloSoft Design"
12 __license__ = "GNU GPL"
18 from getopt import getopt
19 optlist, args = getopt(sys.argv[1:], "s")
23 for _opt, _arg in optlist:
32 print "Broytman set-title-list, Copyright (C) 2003-2007 PhiloSoft Design"
35 sys.stderr.write("Usage: set-title-list [-s] title_list_file\n")
38 # Read the external file with titles and build a mapping (URL => title)
44 title_list_file = open(args[0], 'r')
45 for line in title_list_file:
46 line = line[:-1] # strip trailing newline
53 elif line: # the third line in every 3 lines must be empty
54 raise ValueError, "line is not empty for URL `%s', title `%s': line `%s'" % (URL, title, line)
56 else: # We've got 3 lines - add new entry to the mapping
57 if titles_dict.has_key(URL):
58 if title <> titles_dict[URL]:
59 raise ValueError, "titles are not identical for URL `%s': `%s' <> `%s'" % (URL, title, titles_dict[URL])
62 titles_dict[URL] = title
68 title_list_file.close()
71 from storage import storage
75 sys.stdout.write("Loading %s: " % storage.filename)
78 root_folder = storage.load()
79 from bkmk_objects import make_linear, break_tree
80 make_linear(root_folder)
81 objects = len(root_folder.linear)
87 # Run through the list of objects and check URLs/titles
89 for object_no in range(objects):
90 object = root_folder.linear[object_no]
94 if titles_dict.has_key(URL):
95 name = titles_dict[URL]
96 if object.name <> name:
101 if changed and report_stats:
102 sys.stdout.write("Saving %s: " % storage.filename)
105 if not changed and report_stats:
106 sys.stdout.write("No need to save data\n")
110 break_tree(root_folder.linear)
111 storage.store(root_folder)
113 if changed and report_stats:
115 print objects, "objects passed"
116 print changed, "objects changed"
119 if __name__ == '__main__':