]> git.phdru.name Git - bookmarks_db.git/blob - Writers/bkmk_wflad.py
d5cb7e01d8645dd9bc50c77f01a152c5ee9a663b
[bookmarks_db.git] / Writers / bkmk_wflad.py
1 """Dump bookmarks db to a more readable FLat Ascii Database
2
3 This file is a part of Bookmarks database and Internet robot.
4 """
5
6 __version__ = "$Revision$"[11:-2]
7 __revision__ = "$Id$"[5:-2]
8 __date__ = "$Date$"[7:-2]
9 __author__ = "Oleg Broytman <phd@phdru.name>"
10 __copyright__ = "Copyright (C) 2000-2011 PhiloSoft Design"
11 __license__ = "GNU GPL"
12
13 import time
14 from bkmk_objects import Writer
15
16
17 def strftime(s):
18    try:
19       return time.strftime("%a %d %b %Y %T", time.localtime(int(s)))
20    except (TypeError, ValueError): # s is None or is already formatted
21       return s
22
23
24 class writer_flad(Writer):
25    filename = "bookmarks_db.flad"
26
27    def __init__(self, outfile, prune=None):
28       Writer.__init__(self, outfile, prune)
29       self.first_object = 1
30
31
32    def start_folder(self, f, level):
33       self.outfile.write("""
34 Level: %d
35 Folder: %s
36 AddDate: %s
37 Comment: %s
38 LastModified: %s
39 """ % (level, f.name, strftime(f.add_date), f.comment, f.last_modified or ''))
40
41
42    def bookmark(self, b, level):
43       self.outfile.write("""
44 Level: %d
45 Title: %s
46 URL: %s
47 AddDate: %s
48 LastVisit: %s
49 LastModified: %s
50 Keyword: %s
51 Comment: %s""" % (level+1, b.name, b.href, strftime(b.add_date), strftime(b.last_visit), strftime(b.last_modified), b.keyword, b.comment))
52
53       for attr_name, attr_out in (("error", "Error"), ("no_error", "NoError"),
54             ("moved", "Moved"), ("size", "Size"), ("md5", "Md5"),
55             ("real_title", "RealTitle"), ("test_time", "TestTime"),
56             ("icon_href", "IconURI"), ("icon", "Icon"), ("charset", "Charset")):
57          if hasattr(b, attr_name):
58             self.outfile.write("\n%s: %s" % (attr_out, getattr(b, attr_name)))
59
60       if hasattr(b, "last_tested"):
61          self.outfile.write("\n%s: %s" % ("LastTested", strftime(getattr(b, "last_tested"))))
62
63       self.outfile.write("\n")
64
65    def ruler(self, r, level):
66       self.outfile.write("\nLevel: %s\nRuler: YES\n" % (level+1))