Helpviewer/Bookmarks/BookmarksImporters/ChromeImporter.py

branch
Py2 comp.
changeset 3057
10516539f238
parent 2525
8b507a9a2d40
parent 3002
6ffc581f00f1
child 3058
0a02c433f52d
equal deleted inserted replaced
3056:9986ec0e559a 3057:10516539f238
22 22
23 def getImporterInfo(id): 23 def getImporterInfo(id):
24 """ 24 """
25 Module function to get information for the given source id. 25 Module function to get information for the given source id.
26 26
27 @param id id of the browser ("chrome" or "chromium")
27 @return tuple with an icon (QPixmap), readable name (string), name of 28 @return tuple with an icon (QPixmap), readable name (string), name of
28 the default bookmarks file (string), an info text (string), 29 the default bookmarks file (string), an info text (string),
29 a prompt (string) and the default directory of the bookmarks file (string) 30 a prompt (string) and the default directory of the bookmarks file
31 (string)
32 @exception ValueError raised to indicate an invalid browser ID
30 """ 33 """
31 if id == "chrome": 34 if id == "chrome":
32 if Globals.isWindowsPlatform(): 35 if Globals.isWindowsPlatform():
33 standardDir = os.path.expandvars( 36 standardDir = os.path.expandvars(
34 "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\User Data\\Default") 37 "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\"
38 "User Data\\Default")
35 elif Globals.isMacPlatform(): 39 elif Globals.isMacPlatform():
36 standardDir = os.path.expanduser( 40 standardDir = os.path.expanduser(
37 "~/Library/Application Support/Google/Chrome/Default") 41 "~/Library/Application Support/Google/Chrome/Default")
38 else: 42 else:
39 standardDir = os.path.expanduser("~/.config/google-chrome/Default") 43 standardDir = os.path.expanduser("~/.config/google-chrome/Default")
40 return ( 44 return (
41 UI.PixmapCache.getPixmap("chrome.png"), 45 UI.PixmapCache.getPixmap("chrome.png"),
42 "Google Chrome", 46 "Google Chrome",
43 "Bookmarks", 47 "Bookmarks",
44 QCoreApplication.translate("ChromeImporter", 48 QCoreApplication.translate(
45 """Google Chrome stores its bookmarks in the <b>Bookmarks</b> """ 49 "ChromeImporter",
46 """text file. This file is usually located in"""), 50 """Google Chrome stores its bookmarks in the"""
51 """ <b>Bookmarks</b> text file. This file is usually"""
52 """ located in"""),
47 QCoreApplication.translate("ChromeImporter", 53 QCoreApplication.translate("ChromeImporter",
48 """Please choose the file to begin importing bookmarks."""), 54 """Please choose the file to begin importing bookmarks."""),
49 standardDir, 55 standardDir,
50 ) 56 )
51 elif id == "chromium": 57 elif id == "chromium":
52 if Globals.isWindowsPlatform(): 58 if Globals.isWindowsPlatform():
53 standardDir = os.path.expandvars( 59 standardDir = os.path.expandvars(
54 "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\User Data\\Default") 60 "%USERPROFILE%\\AppData\\Local\\Google\\Chrome\\"
61 "User Data\\Default")
55 else: 62 else:
56 standardDir = os.path.expanduser("~/.config/chromium/Default") 63 standardDir = os.path.expanduser("~/.config/chromium/Default")
57 return ( 64 return (
58 UI.PixmapCache.getPixmap("chromium.png"), 65 UI.PixmapCache.getPixmap("chromium.png"),
59 "Chromium", 66 "Chromium",
60 "Bookmarks", 67 "Bookmarks",
61 QCoreApplication.translate("ChromeImporter", 68 QCoreApplication.translate(
62 """Chromium stores its bookmarks in the <b>Bookmarks</b> text file. """ 69 "ChromeImporter",
63 """This file is usually located in"""), 70 """Chromium stores its bookmarks in the <b>Bookmarks</b>"""
71 """ text file. This file is usually located in"""),
64 QCoreApplication.translate("ChromeImporter", 72 QCoreApplication.translate("ChromeImporter",
65 """Please choose the file to begin importing bookmarks."""), 73 """Please choose the file to begin importing bookmarks."""),
66 standardDir, 74 standardDir,
67 ) 75 )
68 else: 76 else:
98 106
99 @return flag indicating success (boolean) 107 @return flag indicating success (boolean)
100 """ 108 """
101 if not os.path.exists(self.__fileName): 109 if not os.path.exists(self.__fileName):
102 self._error = True 110 self._error = True
103 self._errorString = self.trUtf8("File '{0}' does not exist.")\ 111 self._errorString = self.trUtf8(
104 .format(self.__fileName) 112 "File '{0}' does not exist.").format(self.__fileName)
105 return False 113 return False
106 return True 114 return True
107 115
108 def importedBookmarks(self): 116 def importedBookmarks(self):
109 """ 117 """
115 f = open(self.__fileName, "r", encoding="utf-8") 123 f = open(self.__fileName, "r", encoding="utf-8")
116 contents = json.load(f) 124 contents = json.load(f)
117 f.close() 125 f.close()
118 except IOError as err: 126 except IOError as err:
119 self._error = True 127 self._error = True
120 self._errorString = self.trUtf8("File '{0}' cannot be read.\nReason: {1}")\ 128 self._errorString = self.trUtf8(
129 "File '{0}' cannot be read.\nReason: {1}")\
121 .format(self.__fileName, str(err)) 130 .format(self.__fileName, str(err))
122 return None 131 return None
123 132
124 from ..BookmarkNode import BookmarkNode 133 from ..BookmarkNode import BookmarkNode
125 importRootNode = BookmarkNode(BookmarkNode.Folder) 134 importRootNode = BookmarkNode(BookmarkNode.Folder)

eric ide

mercurial