src/eric7/WebBrowser/Bookmarks/BookmarksImporters/ChromeImporter.py

branch
eric7
changeset 10436
f6881d10e995
parent 9653
e67609152c5e
child 10439
21c28b0f9e41
equal deleted inserted replaced
10435:c712d09cc839 10436:f6881d10e995
20 20
21 def getImporterInfo(sourceId): 21 def getImporterInfo(sourceId):
22 """ 22 """
23 Module function to get information for the given source id. 23 Module function to get information for the given source id.
24 24
25 @param sourceId id of the browser ("chrome", "chromium" or "edge") 25 @param sourceId id of the browser
26 @type str 26 @type str
27 @return tuple with an icon, readable name, name of the default bookmarks file, 27 @return tuple with an icon, readable name, name of the default
28 an info text, a prompt and the default directory of the bookmarks file 28 bookmarks file, an info text, a prompt and the default directory
29 of the bookmarks file
29 @rtype tuple of (QPixmap, str, str, str, str, str) 30 @rtype tuple of (QPixmap, str, str, str, str, str)
30 @exception ValueError raised to indicate an invalid browser ID 31 @exception ValueError raised to indicate an invalid browser ID
31 """ 32 """
32 if sourceId not in ("chrome", "chromium", "edge", "falkon", "opera", "vivaldi"): 33 if sourceId not in ("chrome", "chromium", "edge", "falkon", "opera", "vivaldi"):
33 raise ValueError("Unsupported browser ID given ({0}).".format(sourceId)) 34 raise ValueError("Unsupported browser ID given ({0}).".format(sourceId))
223 224
224 def setPath(self, path): 225 def setPath(self, path):
225 """ 226 """
226 Public method to set the path of the bookmarks file or directory. 227 Public method to set the path of the bookmarks file or directory.
227 228
228 @param path bookmarks file or directory (string) 229 @param path bookmarks file or directory
230 @type str
229 """ 231 """
230 self.__fileName = path 232 self.__fileName = path
231 233
232 def open(self): 234 def open(self):
233 """ 235 """
234 Public method to open the bookmarks file. 236 Public method to open the bookmarks file.
235 237
236 @return flag indicating success (boolean) 238 @return flag indicating success
239 @rtype bool
237 """ 240 """
238 if not os.path.exists(self.__fileName): 241 if not os.path.exists(self.__fileName):
239 self._error = True 242 self._error = True
240 self._errorString = self.tr("File '{0}' does not exist.").format( 243 self._errorString = self.tr("File '{0}' does not exist.").format(
241 self.__fileName 244 self.__fileName
245 248
246 def importedBookmarks(self): 249 def importedBookmarks(self):
247 """ 250 """
248 Public method to get the imported bookmarks. 251 Public method to get the imported bookmarks.
249 252
250 @return imported bookmarks (BookmarkNode) 253 @return imported bookmarks
254 @rtype BookmarkNode
251 """ 255 """
252 from ..BookmarkNode import BookmarkNode 256 from ..BookmarkNode import BookmarkNode
253 257
254 try: 258 try:
255 with open(self.__fileName, "r", encoding="utf-8") as f: 259 with open(self.__fileName, "r", encoding="utf-8") as f:
277 281
278 def __processRoots(self, data, rootNode): 282 def __processRoots(self, data, rootNode):
279 """ 283 """
280 Private method to process the bookmark roots. 284 Private method to process the bookmark roots.
281 285
282 @param data dictionary with the bookmarks data (dict) 286 @param data dictionary with the bookmarks data
283 @param rootNode node to add the bookmarks to (BookmarkNode) 287 @type dict
288 @param rootNode node to add the bookmarks to
289 @type BookmarkNode
284 """ 290 """
285 for key, node in data.items(): 291 for key, node in data.items():
286 if "type" in node: 292 if "type" in node:
287 if node["type"] == "folder": 293 if node["type"] == "folder":
288 self.__generateFolderNode(node, rootNode) 294 self.__generateFolderNode(node, rootNode)
299 305
300 def __generateFolderNode(self, data, rootNode): 306 def __generateFolderNode(self, data, rootNode):
301 """ 307 """
302 Private method to process a bookmarks folder. 308 Private method to process a bookmarks folder.
303 309
304 @param data dictionary with the bookmarks data (dict) 310 @param data dictionary with the bookmarks data
305 @param rootNode node to add the bookmarks to (BookmarkNode) 311 @type dict
312 @param rootNode node to add the bookmarks to
313 @type BookmarkNode
306 """ 314 """
307 from ..BookmarkNode import BookmarkNode 315 from ..BookmarkNode import BookmarkNode
308 316
309 folder = BookmarkNode(BookmarkNode.Folder, rootNode) 317 folder = BookmarkNode(BookmarkNode.Folder, rootNode)
310 folder.title = data["name"].replace("&", "&&") 318 folder.title = data["name"].replace("&", "&&")
316 324
317 def __generateUrlNode(self, data, rootNode): 325 def __generateUrlNode(self, data, rootNode):
318 """ 326 """
319 Private method to process a bookmarks node. 327 Private method to process a bookmarks node.
320 328
321 @param data dictionary with the bookmarks data (dict) 329 @param data dictionary with the bookmarks data
322 @param rootNode node to add the bookmarks to (BookmarkNode) 330 @type dict
331 @param rootNode node to add the bookmarks to
332 @type BookmarkNode
323 """ 333 """
324 from ..BookmarkNode import BookmarkNode 334 from ..BookmarkNode import BookmarkNode
325 335
326 bookmark = BookmarkNode(BookmarkNode.Bookmark, rootNode) 336 bookmark = BookmarkNode(BookmarkNode.Bookmark, rootNode)
327 bookmark.url = data["url"] 337 bookmark.url = data["url"]

eric ide

mercurial