Helpviewer/Sync/SyncHandler.py

changeset 3002
6ffc581f00f1
parent 2954
bf0215fe12d1
child 3022
57179e4cdadd
child 3057
10516539f238
equal deleted inserted replaced
3001:3674ff5fa8f8 3002:6ffc581f00f1
19 class SyncHandler(QObject): 19 class SyncHandler(QObject):
20 """ 20 """
21 Base class for synchronization handlers. 21 Base class for synchronization handlers.
22 22
23 @signal syncStatus(type_, message) emitted to indicate the synchronization 23 @signal syncStatus(type_, message) emitted to indicate the synchronization
24 status (string one of "bookmarks", "history", "passwords", "useragents" or 24 status (string one of "bookmarks", "history", "passwords",
25 "speeddial", string) 25 "useragents" or "speeddial", string)
26 @signal syncError(message) emitted for a general error with the error message (string) 26 @signal syncError(message) emitted for a general error with the error
27 @signal syncMessage(message) emitted to send a message about synchronization (string) 27 message (string)
28 @signal syncFinished(type_, done, download) emitted after a synchronization has 28 @signal syncMessage(message) emitted to send a message about
29 finished (string one of "bookmarks", "history", "passwords", "useragents" or 29 synchronization (string)
30 "speeddial", boolean, boolean) 30 @signal syncFinished(type_, done, download) emitted after a
31 synchronization has finished (string one of "bookmarks", "history",
32 "passwords", "useragents" or "speeddial", boolean, boolean)
31 """ 33 """
32 syncStatus = pyqtSignal(str, str) 34 syncStatus = pyqtSignal(str, str)
33 syncError = pyqtSignal(str) 35 syncError = pyqtSignal(str)
34 syncMessage = pyqtSignal(str) 36 syncMessage = pyqtSignal(str)
35 syncFinished = pyqtSignal(str, bool, bool) 37 syncFinished = pyqtSignal(str, bool, bool)
55 self._messages = { 57 self._messages = {
56 "bookmarks": { 58 "bookmarks": {
57 "RemoteExists": self.trUtf8( 59 "RemoteExists": self.trUtf8(
58 "Remote bookmarks file exists! Syncing local copy..."), 60 "Remote bookmarks file exists! Syncing local copy..."),
59 "RemoteMissing": self.trUtf8( 61 "RemoteMissing": self.trUtf8(
60 "Remote bookmarks file does NOT exists. Exporting local copy..."), 62 "Remote bookmarks file does NOT exists. Exporting"
63 " local copy..."),
61 "LocalNewer": self.trUtf8( 64 "LocalNewer": self.trUtf8(
62 "Local bookmarks file is NEWER. Exporting local copy..."), 65 "Local bookmarks file is NEWER. Exporting local copy..."),
63 "LocalMissing": self.trUtf8( 66 "LocalMissing": self.trUtf8(
64 "Local bookmarks file does NOT exist. Skipping synchronization!"), 67 "Local bookmarks file does NOT exist. Skipping"
68 " synchronization!"),
65 "Uploading": self.trUtf8("Uploading local bookmarks file..."), 69 "Uploading": self.trUtf8("Uploading local bookmarks file..."),
66 }, 70 },
67 "history": { 71 "history": {
68 "RemoteExists": self.trUtf8( 72 "RemoteExists": self.trUtf8(
69 "Remote history file exists! Syncing local copy..."), 73 "Remote history file exists! Syncing local copy..."),
70 "RemoteMissing": self.trUtf8( 74 "RemoteMissing": self.trUtf8(
71 "Remote history file does NOT exists. Exporting local copy..."), 75 "Remote history file does NOT exists. Exporting"
76 " local copy..."),
72 "LocalNewer": self.trUtf8( 77 "LocalNewer": self.trUtf8(
73 "Local history file is NEWER. Exporting local copy..."), 78 "Local history file is NEWER. Exporting local copy..."),
74 "LocalMissing": self.trUtf8( 79 "LocalMissing": self.trUtf8(
75 "Local history file does NOT exist. Skipping synchronization!"), 80 "Local history file does NOT exist. Skipping"
81 " synchronization!"),
76 "Uploading": self.trUtf8("Uploading local history file..."), 82 "Uploading": self.trUtf8("Uploading local history file..."),
77 }, 83 },
78 "passwords": { 84 "passwords": {
79 "RemoteExists": self.trUtf8( 85 "RemoteExists": self.trUtf8(
80 "Remote logins file exists! Syncing local copy..."), 86 "Remote logins file exists! Syncing local copy..."),
81 "RemoteMissing": self.trUtf8( 87 "RemoteMissing": self.trUtf8(
82 "Remote logins file does NOT exists. Exporting local copy..."), 88 "Remote logins file does NOT exists. Exporting"
89 " local copy..."),
83 "LocalNewer": self.trUtf8( 90 "LocalNewer": self.trUtf8(
84 "Local logins file is NEWER. Exporting local copy..."), 91 "Local logins file is NEWER. Exporting local copy..."),
85 "LocalMissing": self.trUtf8( 92 "LocalMissing": self.trUtf8(
86 "Local logins file does NOT exist. Skipping synchronization!"), 93 "Local logins file does NOT exist. Skipping"
94 " synchronization!"),
87 "Uploading": self.trUtf8("Uploading local logins file..."), 95 "Uploading": self.trUtf8("Uploading local logins file..."),
88 }, 96 },
89 "useragents": { 97 "useragents": {
90 "RemoteExists": self.trUtf8( 98 "RemoteExists": self.trUtf8(
91 "Remote user agent settings file exists! Syncing local copy..."), 99 "Remote user agent settings file exists! Syncing local"
100 " copy..."),
92 "RemoteMissing": self.trUtf8( 101 "RemoteMissing": self.trUtf8(
93 "Remote user agent settings file does NOT exists." 102 "Remote user agent settings file does NOT exists."
94 " Exporting local copy..."), 103 " Exporting local copy..."),
95 "LocalNewer": self.trUtf8( 104 "LocalNewer": self.trUtf8(
96 "Local user agent settings file is NEWER. Exporting local copy..."), 105 "Local user agent settings file is NEWER. Exporting"
106 " local copy..."),
97 "LocalMissing": self.trUtf8( 107 "LocalMissing": self.trUtf8(
98 "Local user agent settings file does NOT exist." 108 "Local user agent settings file does NOT exist."
99 " Skipping synchronization!"), 109 " Skipping synchronization!"),
100 "Uploading": self.trUtf8("Uploading local user agent settings file..."), 110 "Uploading": self.trUtf8("Uploading local user agent"
111 " settings file..."),
101 }, 112 },
102 "speeddial": { 113 "speeddial": {
103 "RemoteExists": self.trUtf8( 114 "RemoteExists": self.trUtf8(
104 "Remote speed dial settings file exists! Syncing local copy..."), 115 "Remote speed dial settings file exists! Syncing local"
116 " copy..."),
105 "RemoteMissing": self.trUtf8( 117 "RemoteMissing": self.trUtf8(
106 "Remote speed dial settings file does NOT exists." 118 "Remote speed dial settings file does NOT exists."
107 " Exporting local copy..."), 119 " Exporting local copy..."),
108 "LocalNewer": self.trUtf8( 120 "LocalNewer": self.trUtf8(
109 "Local speed dial settings file is NEWER. Exporting local copy..."), 121 "Local speed dial settings file is NEWER. Exporting"
122 " local copy..."),
110 "LocalMissing": self.trUtf8( 123 "LocalMissing": self.trUtf8(
111 "Local speed dial settings file does NOT exist." 124 "Local speed dial settings file does NOT exist."
112 " Skipping synchronization!"), 125 " Skipping synchronization!"),
113 "Uploading": self.trUtf8("Uploading local speed dial settings file..."), 126 "Uploading": self.trUtf8("Uploading local speed dial"
127 " settings file..."),
114 }, 128 },
115 } 129 }
116 130
117 def syncBookmarks(self): 131 def syncBookmarks(self):
118 """ 132 """
161 175
162 def initialLoadAndCheck(self, forceUpload): 176 def initialLoadAndCheck(self, forceUpload):
163 """ 177 """
164 Public method to do the initial check. 178 Public method to do the initial check.
165 179
166 @keyparam forceUpload flag indicating a forced upload of the files (boolean) 180 @keyparam forceUpload flag indicating a forced upload of the files
181 (boolean)
167 @exception NotImplementedError raised to indicate that this method 182 @exception NotImplementedError raised to indicate that this method
168 must be implemented by subclasses 183 must be implemented by subclasses
169 """ 184 """
170 raise NotImplementedError 185 raise NotImplementedError
171 186
180 195
181 def readFile(self, fileName, type_): 196 def readFile(self, fileName, type_):
182 """ 197 """
183 Public method to read a file. 198 Public method to read a file.
184 199
185 If encrypted synchronization is enabled, the data will be encrypted using 200 If encrypted synchronization is enabled, the data will be encrypted
186 the relevant encryption key. 201 using the relevant encryption key.
187 202
188 @param fileName name of the file to be read (string) 203 @param fileName name of the file to be read (string)
189 @param type_ type of the synchronization event (string one 204 @param type_ type of the synchronization event (string one
190 of "bookmarks", "history", "passwords", "useragents" or "speeddial") 205 of "bookmarks", "history", "passwords", "useragents" or
206 "speeddial")
191 @return data of the file, optionally encrypted (QByteArray) 207 @return data of the file, optionally encrypted (QByteArray)
192 """ 208 """
193 if os.path.exists(fileName): 209 if os.path.exists(fileName):
194 try: 210 try:
195 inputFile = open(fileName, "rb") 211 inputFile = open(fileName, "rb")
218 234
219 def writeFile(self, data, fileName, type_, timestamp=0): 235 def writeFile(self, data, fileName, type_, timestamp=0):
220 """ 236 """
221 Public method to write the data to a file. 237 Public method to write the data to a file.
222 238
223 If encrypted synchronization is enabled, the data will be decrypted using 239 If encrypted synchronization is enabled, the data will be decrypted
224 the relevant encryption key. 240 using the relevant encryption key.
225 241
226 @param data data to be written and optionally decrypted (QByteArray) 242 @param data data to be written and optionally decrypted (QByteArray)
227 @param fileName name of the file the data is to be written to (string) 243 @param fileName name of the file the data is to be written to (string)
228 @param type_ type of the synchronization event (string one 244 @param type_ type of the synchronization event (string one
229 of "bookmarks", "history", "passwords", "useragents" or "speeddial") 245 of "bookmarks", "history", "passwords", "useragents" or
246 "speeddial")
230 @param timestamp timestamp to be given to the file (int) 247 @param timestamp timestamp to be given to the file (int)
231 @return tuple giving a success flag and an error string (boolean, string) 248 @return tuple giving a success flag and an error string (boolean,
249 string)
232 """ 250 """
233 data = bytes(data) 251 data = bytes(data)
234 252
235 if Preferences.getHelp("SyncEncryptData") and \ 253 if Preferences.getHelp("SyncEncryptData") and \
236 (not Preferences.getHelp("SyncEncryptPasswordsOnly") or \ 254 (not Preferences.getHelp("SyncEncryptPasswordsOnly") or
237 (Preferences.getHelp("SyncEncryptPasswordsOnly") and type_ == "passwords")): 255 (Preferences.getHelp("SyncEncryptPasswordsOnly") and
256 type_ == "passwords")):
238 key = Preferences.getHelp("SyncEncryptionKey") 257 key = Preferences.getHelp("SyncEncryptionKey")
239 if not key: 258 if not key:
240 return False, self.trUtf8("Invalid encryption key given.") 259 return False, self.trUtf8("Invalid encryption key given.")
241 260
242 data, ok = dataDecrypt(data, key, 261 data, ok = dataDecrypt(data, key,

eric ide

mercurial