]> git.phdru.name Git - bookmarks_db.git/blob - Writers/bkmk_wflad.py
Pretty-print last_modified.
[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 __all__ = ['writer_flad']
14
15
16 import time
17 from bkmk_objects import Writer
18
19
20 def strftime(s):
21    try:
22       return time.strftime("%a %d %b %Y %T", time.localtime(int(s)))
23    except (TypeError, ValueError): # s is None or is already formatted
24       return s
25
26
27 class writer_flad(Writer):
28    filename = "bookmarks_db.flad"
29
30    def __init__(self, outfile, prune=None):
31       Writer.__init__(self, outfile, prune)
32       self.first_object = 1
33
34    def start_folder(self, f, level):
35       self.outfile.write("""
36 Level: %d
37 Folder: %s
38 AddDate: %s
39 Comment: %s
40 LastModified: %s
41 """ % (level, f.name, strftime(f.add_date), f.comment, strftime(f.last_modified)))
42
43    def bookmark(self, b, level):
44       self.outfile.write("""
45 Level: %d
46 Title: %s
47 URL: %s
48 AddDate: %s
49 LastVisit: %s
50 LastModified: %s
51 Keyword: %s
52 Comment: %s""" % (level+1, b.name, b.href, strftime(b.add_date), strftime(b.last_visit), strftime(b.last_modified), b.keyword, b.comment))
53
54       for attr_name, attr_out in (("error", "Error"), ("no_error", "NoError"),
55             ("moved", "Moved"), ("size", "Size"), ("md5", "Md5"),
56             ("real_title", "RealTitle"), ("test_time", "TestTime"),
57             ("icon_href", "IconURI"), ("icon", "Icon"), ("charset", "Charset")):
58          if hasattr(b, attr_name):
59             self.outfile.write("\n%s: %s" % (attr_out, getattr(b, attr_name)))
60
61       if hasattr(b, "last_tested"):
62          self.outfile.write("\n%s: %s" % ("LastTested", strftime(getattr(b, "last_tested"))))
63
64       self.outfile.write("\n")
65
66    def ruler(self, r, level):
67       self.outfile.write("\nLevel: %s\nRuler: YES\n" % (level+1))