24 |
24 |
25 class FtpSyncHandler(SyncHandler): |
25 class FtpSyncHandler(SyncHandler): |
26 """ |
26 """ |
27 Class implementing a synchronization handler using FTP. |
27 Class implementing a synchronization handler using FTP. |
28 |
28 |
29 @signal syncStatus(type_, message) emitted to indicate the synchronization |
29 @signal syncStatus(type_, message) emitted to indicate the synchronization status |
30 status (string one of "bookmarks", "history", "passwords", |
30 @signal syncError(message) emitted for a general error with the error message |
31 "useragents" or "speeddial", string) |
31 @signal syncMessage(message) emitted to send a message about synchronization |
32 @signal syncError(message) emitted for a general error with the error |
32 @signal syncFinished(type_, done, download) emitted after a synchronization |
33 message (string) |
33 has finished |
34 @signal syncMessage(message) emitted to send a message about |
|
35 synchronization (string) |
|
36 @signal syncFinished(type_, done, download) emitted after a |
|
37 synchronization has finished (string one of "bookmarks", "history", |
|
38 "passwords", "useragents" or "speeddial", boolean, boolean) |
|
39 """ |
34 """ |
40 |
35 |
41 syncStatus = pyqtSignal(str, str) |
36 syncStatus = pyqtSignal(str, str) |
42 syncError = pyqtSignal(str) |
37 syncError = pyqtSignal(str) |
43 syncMessage = pyqtSignal(str) |
38 syncMessage = pyqtSignal(str) |
60 def initialLoadAndCheck(self, forceUpload): |
56 def initialLoadAndCheck(self, forceUpload): |
61 """ |
57 """ |
62 Public method to do the initial check. |
58 Public method to do the initial check. |
63 |
59 |
64 @param forceUpload flag indicating a forced upload of the files |
60 @param forceUpload flag indicating a forced upload of the files |
65 (boolean) |
61 @type bool |
66 """ |
62 """ |
67 if not Preferences.getWebBrowser("SyncEnabled"): |
63 if not Preferences.getWebBrowser("SyncEnabled"): |
68 return |
64 return |
69 |
65 |
70 self.__state = "initializing" |
66 self.__state = "initializing" |
119 |
115 |
120 def __connectAndLogin(self): |
116 def __connectAndLogin(self): |
121 """ |
117 """ |
122 Private method to connect to the FTP server and log in. |
118 Private method to connect to the FTP server and log in. |
123 |
119 |
124 @return flag indicating a successful log in (boolean) |
120 @return flag indicating a successful log in |
|
121 @rtype bool |
125 """ |
122 """ |
126 self.__ftp.connect( |
123 self.__ftp.connect( |
127 Preferences.getWebBrowser("SyncFtpServer"), |
124 Preferences.getWebBrowser("SyncFtpServer"), |
128 Preferences.getWebBrowser("SyncFtpPort"), |
125 Preferences.getWebBrowser("SyncFtpPort"), |
129 timeout=5, |
126 timeout=5, |
164 |
161 |
165 def __dirListCallback(self, line): |
162 def __dirListCallback(self, line): |
166 """ |
163 """ |
167 Private slot handling the receipt of directory listing lines. |
164 Private slot handling the receipt of directory listing lines. |
168 |
165 |
169 @param line the received line of the directory listing (string) |
166 @param line the received line of the directory listing |
|
167 @type str |
170 """ |
168 """ |
171 try: |
169 try: |
172 urlInfo = self.__dirLineParser.parseLine(line) |
170 urlInfo = self.__dirLineParser.parseLine(line) |
173 except FtpDirLineParserError: |
171 except FtpDirLineParserError: |
174 # silently ignore parser errors |
172 # silently ignore parser errors |
186 |
184 |
187 def __downloadFile(self, type_, fileName, timestamp): |
185 def __downloadFile(self, type_, fileName, timestamp): |
188 """ |
186 """ |
189 Private method to downlaod the given file. |
187 Private method to downlaod the given file. |
190 |
188 |
191 @param type_ type of the synchronization event (string one |
189 @param type_ type of the synchronization event (one of |
192 of "bookmarks", "history", "passwords", "useragents" or |
190 "bookmarks", "history", "passwords", "useragents" or "speeddial") |
193 "speeddial") |
191 @type str |
194 @param fileName name of the file to be downloaded (string) |
192 @param fileName name of the file to be downloaded |
|
193 @type str |
195 @param timestamp time stamp in seconds of the file to be downloaded |
194 @param timestamp time stamp in seconds of the file to be downloaded |
196 (integer) |
195 @type int |
197 """ |
196 """ |
198 self.syncStatus.emit(type_, self._messages[type_]["RemoteExists"]) |
197 self.syncStatus.emit(type_, self._messages[type_]["RemoteExists"]) |
199 buffer = io.BytesIO() |
198 buffer = io.BytesIO() |
200 try: |
199 try: |
201 self.__ftp.retrbinary( |
200 self.__ftp.retrbinary( |
214 |
213 |
215 def __downloadFileCallback(self, buffer, data): |
214 def __downloadFileCallback(self, buffer, data): |
216 """ |
215 """ |
217 Private method receiving the downloaded data. |
216 Private method receiving the downloaded data. |
218 |
217 |
219 @param buffer reference to the buffer (io.BytesIO) |
218 @param buffer reference to the buffer |
220 @param data byte string to store in the buffer (bytes) |
219 @type io.BytesIO |
221 @return number of bytes written to the buffer (integer) |
220 @param data byte string to store in the buffer |
|
221 @type bytes |
|
222 @return number of bytes written to the buffer |
|
223 @rtype int |
222 """ |
224 """ |
223 res = buffer.write(data) |
225 res = buffer.write(data) |
224 QCoreApplication.processEvents() |
226 QCoreApplication.processEvents() |
225 return res |
227 return res |
226 |
228 |
227 def __uploadFile(self, type_, fileName): |
229 def __uploadFile(self, type_, fileName): |
228 """ |
230 """ |
229 Private method to upload the given file. |
231 Private method to upload the given file. |
230 |
232 |
231 @param type_ type of the synchronization event (string one |
233 @param type_ type of the synchronization event (one of "bookmarks", |
232 of "bookmarks", "history", "passwords", "useragents" or |
234 "history", "passwords", "useragents" or "speeddial") |
233 "speeddial") |
235 @type str |
234 @param fileName name of the file to be uploaded (string) |
236 @param fileName name of the file to be uploaded |
235 @return flag indicating success (boolean) |
237 @type str |
|
238 @return flag indicating success |
|
239 @rtype bool |
236 """ |
240 """ |
237 res = False |
241 res = False |
238 data = self.readFile(fileName, type_) |
242 data = self.readFile(fileName, type_) |
239 if data.isEmpty(): |
243 if data.isEmpty(): |
240 self.syncStatus.emit(type_, self._messages[type_]["LocalMissing"]) |
244 self.syncStatus.emit(type_, self._messages[type_]["LocalMissing"]) |
256 |
260 |
257 def __initialSyncFile(self, type_, fileName): |
261 def __initialSyncFile(self, type_, fileName): |
258 """ |
262 """ |
259 Private method to do the initial synchronization of the given file. |
263 Private method to do the initial synchronization of the given file. |
260 |
264 |
261 @param type_ type of the synchronization event (string one |
265 @param type_ type of the synchronization event (one of "bookmarks", |
262 of "bookmarks", "history", "passwords", "useragents" or |
266 "history", "passwords", "useragents" or "speeddial") |
263 "speeddial") |
267 @type str |
264 @param fileName name of the file to be synchronized (string) |
268 @param fileName name of the file to be synchronized |
|
269 @type str |
265 """ |
270 """ |
266 if ( |
271 if ( |
267 not self.__forceUpload |
272 not self.__forceUpload |
268 and self._remoteFiles[type_] in self.__remoteFilesFound |
273 and self._remoteFiles[type_] in self.__remoteFilesFound |
269 ): |
274 ): |
325 |
330 |
326 def __syncFile(self, type_, fileName): |
331 def __syncFile(self, type_, fileName): |
327 """ |
332 """ |
328 Private method to synchronize the given file. |
333 Private method to synchronize the given file. |
329 |
334 |
330 @param type_ type of the synchronization event (string one |
335 @param type_ type of the synchronization event (one of "bookmarks", |
331 of "bookmarks", "history", "passwords", "useragents" or |
336 "history", "passwords", "useragents" or "speeddial") |
332 "speeddial") |
337 @type str |
333 @param fileName name of the file to be synchronized (string) |
338 @param fileName name of the file to be synchronized |
|
339 @type str |
334 """ |
340 """ |
335 if self.__state == "initializing": |
341 if self.__state == "initializing": |
336 return |
342 return |
337 |
343 |
338 # use idle timeout to check, if we are still connected |
344 # use idle timeout to check, if we are still connected |