eric6/WebBrowser/Bookmarks/NsHtmlWriter.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7781
607a6098cb44
child 8218
7c09585bd960
permissions
-rw-r--r--

Updated copyright for 2021.

1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
3 # Copyright (c) 2012 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a class to write Netscape HTML bookmark files.
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3178
diff changeset
10 from PyQt5.QtCore import QObject, QIODevice, QFile
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from .BookmarkNode import BookmarkNode
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import Utilities
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 class NsHtmlWriter(QObject):
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
19 Class implementing a writer object to generate Netscape HTML bookmark
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
20 files.
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 indentSize = 4
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 def __init__(self):
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
28 super(NsHtmlWriter, self).__init__()
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 def write(self, fileNameOrDevice, root):
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 Public method to write an Netscape HTML bookmark file.
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 @param fileNameOrDevice name of the file to write (string)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 or device to write to (QIODevice)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @param root root node of the bookmark tree (BookmarkNode)
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
37 @return flag indicating success (boolean)
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 if isinstance(fileNameOrDevice, QIODevice):
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 f = fileNameOrDevice
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 else:
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 f = QFile(fileNameOrDevice)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 if root is None or not f.open(QFile.WriteOnly):
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 return False
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 self.__dev = f
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 return self.__write(root)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 def __write(self, root):
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 Private method to write an Netscape HTML bookmark file.
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 @param root root node of the bookmark tree (BookmarkNode)
2954
bf0215fe12d1 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
54 @return flag indicating success (boolean)
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
56 self.__dev.write(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
57 "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n"
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 "<!-- This is an automatically generated file.\n"
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 " It will be read and overwritten.\n"
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 " DO NOT EDIT! -->\n"
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
61 "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html;"
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
62 " charset=UTF-8\">\n"
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 "<TITLE>Bookmarks</TITLE>\n"
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 "<H1>Bookmarks</H1>\n"
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 "\n"
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 "<DL><p>\n")
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 if root.type() == BookmarkNode.Root:
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 for child in root.children():
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 self.__writeItem(child, self.indentSize)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 else:
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 self.__writeItem(root, self.indentSize)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 self.__dev.write("</DL><p>\n")
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 return True
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 def __writeItem(self, node, indent):
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 Private method to write an entry for a node.
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 @param node reference to the node to be written (BookmarkNode)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 @param indent size of the indentation (integer)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 if node.type() == BookmarkNode.Folder:
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.__writeFolder(node, indent)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 elif node.type() == BookmarkNode.Bookmark:
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 self.__writeBookmark(node, indent)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 elif node.type() == BookmarkNode.Separator:
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 self.__writeSeparator(indent)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 def __writeSeparator(self, indent):
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 Private method to write a separator.
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 @param indent size of the indentation (integer)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.__dev.write(" " * indent)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 self.__dev.write("<HR>\n")
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 def __writeBookmark(self, node, indent):
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 Private method to write a bookmark node.
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 @param node reference to the node to be written (BookmarkNode)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 @param indent size of the indentation (integer)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 """
1731
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
105 if node.added.isValid():
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
106 added = " ADD_DATE=\"{0}\"".format(node.added.toTime_t())
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
107 else:
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
108 added = ""
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
109 if node.modified.isValid():
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
110 modified = " LAST_MODIFIED=\"{0}\"".format(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
111 node.modified.toTime_t())
1731
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
112 else:
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
113 modified = ""
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
114 if node.visited.isValid():
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
115 visited = " LAST_VISIT=\"{0}\"".format(node.visited.toTime_t())
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
116 else:
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
117 visited = ""
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
118
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.__dev.write(" " * indent)
1731
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
120 self.__dev.write("<DT><A HREF=\"{0}\"{1}{2}{3}>{4}</A>\n".format(
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
121 node.url, added, modified, visited,
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
122 Utilities.html_uencode(node.title)
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123 ))
1732
b140a24e147a Rewrote the reader for HTML bookmark files to cope with the various dates.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1731
diff changeset
124
b140a24e147a Rewrote the reader for HTML bookmark files to cope with the various dates.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1731
diff changeset
125 if node.desc:
b140a24e147a Rewrote the reader for HTML bookmark files to cope with the various dates.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1731
diff changeset
126 self.__dev.write(" " * indent)
b140a24e147a Rewrote the reader for HTML bookmark files to cope with the various dates.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1731
diff changeset
127 self.__dev.write("<DD>{0}\n".format(
b140a24e147a Rewrote the reader for HTML bookmark files to cope with the various dates.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1731
diff changeset
128 Utilities.html_uencode("".join(node.desc.splitlines()))))
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 def __writeFolder(self, node, indent):
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 Private method to write a bookmark node.
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 @param node reference to the node to be written (BookmarkNode)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 @param indent size of the indentation (integer)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 """
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 if node.expanded:
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 folded = ""
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 else:
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 folded = " FOLDED"
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
1731
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
142 if node.added.isValid():
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
143 added = " ADD_DATE=\"{0}\"".format(node.added.toTime_t())
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
144 else:
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
145 added = ""
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
146
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 self.__dev.write(" " * indent)
1731
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
148 self.__dev.write("<DT><H3{0}{1}>{2}</H3>\n".format(
56cf9c150dbf Added code to write the timestamps to the Netscape bookmarks file and to record a timestamp for the last modification.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1729
diff changeset
149 folded, added, Utilities.html_uencode(node.title)
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 ))
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 if node.desc:
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 self.__dev.write(" " * indent)
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
154 self.__dev.write("<DD>{0}\n".format(
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2954
diff changeset
155 "".join(node.desc.splitlines())))
1729
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 self.__dev.write(" " * indent)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158 self.__dev.write("<DL><p>\n")
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 for child in node.children():
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 self.__writeItem(child, indent + self.indentSize)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 self.__dev.write(" " * indent)
66b9dc45f2bd Added a bookmarks importer for Konqueror (Linux only) and an exporter to write Netscape bookmark files (HTML).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 self.__dev.write("</DL><p>\n")

eric ide

mercurial