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

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
--- a/src/eric7/WebBrowser/Bookmarks/BookmarksImporters/ChromeImporter.py	Wed Jul 13 11:16:20 2022 +0200
+++ b/src/eric7/WebBrowser/Bookmarks/BookmarksImporters/ChromeImporter.py	Wed Jul 13 14:55:47 2022 +0200
@@ -21,7 +21,7 @@
 def getImporterInfo(sourceId):
     """
     Module function to get information for the given source id.
-    
+
     @param sourceId id of the browser ("chrome" or "chromium")
     @return tuple with an icon (QPixmap), readable name (string), name of
         the default bookmarks file (string), an info text (string),
@@ -30,17 +30,17 @@
     @exception ValueError raised to indicate an invalid browser ID
     """
     if sourceId not in ("chrome", "chromium"):
-        raise ValueError(
-            "Unsupported browser ID given ({0}).".format(sourceId))
-    
+        raise ValueError("Unsupported browser ID given ({0}).".format(sourceId))
+
     if sourceId == "chrome":
         if Globals.isWindowsPlatform():
             standardDir = os.path.expandvars(
-                "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\"
-                "User Data\\Default")
+                "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\" "User Data\\Default"
+            )
         elif Globals.isMacPlatform():
             standardDir = os.path.expanduser(
-                "~/Library/Application Support/Google/Chrome/Default")
+                "~/Library/Application Support/Google/Chrome/Default"
+            )
         else:
             standardDir = os.path.expanduser("~/.config/google-chrome/Default")
         return (
@@ -51,17 +51,19 @@
                 "ChromeImporter",
                 """Google Chrome stores its bookmarks in the"""
                 """ <b>Bookmarks</b> text file. This file is usually"""
-                """ located in"""),
+                """ located in""",
+            ),
             QCoreApplication.translate(
                 "ChromeImporter",
-                """Please choose the file to begin importing bookmarks."""),
+                """Please choose the file to begin importing bookmarks.""",
+            ),
             standardDir,
         )
     else:
         if Globals.isWindowsPlatform():
             standardDir = os.path.expandvars(
-                "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\"
-                "User Data\\Default")
+                "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\" "User Data\\Default"
+            )
         else:
             standardDir = os.path.expanduser("~/.config/chromium/Default")
         return (
@@ -71,10 +73,12 @@
             QCoreApplication.translate(
                 "ChromeImporter",
                 """Chromium stores its bookmarks in the <b>Bookmarks</b>"""
-                """ text file. This file is usually located in"""),
+                """ text file. This file is usually located in""",
+            ),
             QCoreApplication.translate(
                 "ChromeImporter",
-                """Please choose the file to begin importing bookmarks."""),
+                """Please choose the file to begin importing bookmarks.""",
+            ),
             standardDir,
         )
 
@@ -83,42 +87,44 @@
     """
     Class implementing the Chrome bookmarks importer.
     """
+
     def __init__(self, sourceId="", parent=None):
         """
         Constructor
-        
+
         @param sourceId source ID (string)
         @param parent reference to the parent object (QObject)
         """
         super().__init__(sourceId, parent)
-        
+
         self.__fileName = ""
-    
+
     def setPath(self, path):
         """
         Public method to set the path of the bookmarks file or directory.
-        
+
         @param path bookmarks file or directory (string)
         """
         self.__fileName = path
-    
+
     def open(self):
         """
         Public method to open the bookmarks file.
-        
+
         @return flag indicating success (boolean)
         """
         if not os.path.exists(self.__fileName):
             self._error = True
-            self._errorString = self.tr(
-                "File '{0}' does not exist.").format(self.__fileName)
+            self._errorString = self.tr("File '{0}' does not exist.").format(
+                self.__fileName
+            )
             return False
         return True
-    
+
     def importedBookmarks(self):
         """
         Public method to get the imported bookmarks.
-        
+
         @return imported bookmarks (BookmarkNode)
         """
         try:
@@ -130,27 +136,27 @@
                 "File '{0}' cannot be read.\nReason: {1}"
             ).format(self.__fileName, str(err))
             return None
-        
+
         from ..BookmarkNode import BookmarkNode
+
         importRootNode = BookmarkNode(BookmarkNode.Folder)
         if contents["version"] == 1:
             self.__processRoots(contents["roots"], importRootNode)
-        
+
         if self._id == "chrome":
             importRootNode.title = self.tr("Google Chrome Import")
         elif self._id == "chromium":
             importRootNode.title = self.tr("Chromium Import")
         else:
-            importRootNode.title = self.tr(
-                "Imported {0}"
-            ).format(QDate.currentDate().toString(
-                Qt.DateFormat.SystemLocaleShortDate))
+            importRootNode.title = self.tr("Imported {0}").format(
+                QDate.currentDate().toString(Qt.DateFormat.SystemLocaleShortDate)
+            )
         return importRootNode
-    
+
     def __processRoots(self, data, rootNode):
         """
         Private method to process the bookmark roots.
-        
+
         @param data dictionary with the bookmarks data (dict)
         @param rootNode node to add the bookmarks to (BookmarkNode)
         """
@@ -159,15 +165,16 @@
                 self.__generateFolderNode(node, rootNode)
             elif node["type"] == "url":
                 self.__generateUrlNode(node, rootNode)
-    
+
     def __generateFolderNode(self, data, rootNode):
         """
         Private method to process a bookmarks folder.
-        
+
         @param data dictionary with the bookmarks data (dict)
         @param rootNode node to add the bookmarks to (BookmarkNode)
         """
         from ..BookmarkNode import BookmarkNode
+
         folder = BookmarkNode(BookmarkNode.Folder, rootNode)
         folder.title = data["name"].replace("&", "&&")
         for node in data["children"]:
@@ -175,15 +182,16 @@
                 self.__generateFolderNode(node, folder)
             elif node["type"] == "url":
                 self.__generateUrlNode(node, folder)
-    
+
     def __generateUrlNode(self, data, rootNode):
         """
         Private method to process a bookmarks node.
-        
+
         @param data dictionary with the bookmarks data (dict)
         @param rootNode node to add the bookmarks to (BookmarkNode)
         """
         from ..BookmarkNode import BookmarkNode
+
         bookmark = BookmarkNode(BookmarkNode.Bookmark, rootNode)
         bookmark.url = data["url"]
         bookmark.title = data["name"].replace("&", "&&")

eric ide

mercurial