Mon, 24 Sep 2012 19:14:39 +0200
Fixed a little issue in the FTP sync handler.
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
3 | # Copyright (c) 2012 Detlev Offenbach <detlev@die-offenbachs.de> |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing a synchronization handler using FTP. |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
10 | import ftplib |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
11 | import io |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
12 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
13 | from PyQt4.QtCore import pyqtSignal, QUrl, QTimer, QFileInfo, QCoreApplication, QByteArray |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
14 | from PyQt4.QtNetwork import QNetworkProxyQuery, QNetworkProxy, QAuthenticator |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
15 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
16 | from E5Network.E5NetworkProxyFactory import E5NetworkProxyFactory, \ |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
17 | proxyAuthenticationRequired |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | from .SyncHandler import SyncHandler |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | import Helpviewer.HelpWindow |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | import Preferences |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
25 | from Utilities.FtpUtilities import FtpDirLineParser, FtpDirLineParserError |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
26 | |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | class FtpSyncHandler(SyncHandler): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | Class implementing a synchronization handler using FTP. |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | |
1700
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
32 | @signal syncStatus(type_, message) emitted to indicate the synchronization |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
33 | status (string one of "bookmarks", "history", "passwords", "useragents" or |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
34 | "speeddial", string) |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | @signal syncError(message) emitted for a general error with the error message (string) |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
36 | @signal syncMessage(message) emitted to send a message about synchronization (string) |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
37 | @signal syncFinished(type_, done, download) emitted after a synchronization has |
1700
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
38 | finished (string one of "bookmarks", "history", "passwords", "useragents" or |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
39 | "speeddial", boolean, boolean) |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | """ |
1700
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
41 | syncStatus = pyqtSignal(str, str) |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | syncError = pyqtSignal(str) |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
43 | syncMessage = pyqtSignal(str) |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | syncFinished = pyqtSignal(str, bool, bool) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | def __init__(self, parent=None): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | Constructor |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | @param parent reference to the parent object (QObject) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | super().__init__(parent) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | self.__state = "idle" |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
55 | self.__forceUpload = False |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
56 | self.__connected = False |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | |
1695
7b115f986d48
Added capability to synchronize bookmarks, history, passwords and user agent settings via a shared directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1681
diff
changeset
|
58 | self.__remoteFilesFound = {} |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
60 | def initialLoadAndCheck(self, forceUpload): |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | Public method to do the initial check. |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
63 | |
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
64 | @keyparam forceUpload flag indicating a forced upload of the files (boolean) |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
65 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
66 | if not Preferences.getHelp("SyncEnabled"): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
67 | return |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
68 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
69 | self.__state = "initializing" |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
70 | self.__forceUpload = forceUpload |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
71 | |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
72 | self.__dirLineParser = FtpDirLineParser() |
1695
7b115f986d48
Added capability to synchronize bookmarks, history, passwords and user agent settings via a shared directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1681
diff
changeset
|
73 | self.__remoteFilesFound = {} |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
74 | |
1638
cd2f9e526710
Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1626
diff
changeset
|
75 | self.__idleTimer = QTimer(self) |
cd2f9e526710
Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1626
diff
changeset
|
76 | self.__idleTimer.setInterval(Preferences.getHelp("SyncFtpIdleTimeout") * 1000) |
cd2f9e526710
Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1626
diff
changeset
|
77 | self.__idleTimer.timeout.connect(self.__idleTimeout) |
cd2f9e526710
Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1626
diff
changeset
|
78 | |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
79 | self.__ftp = ftplib.FTP() |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | # do proxy setup |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
82 | self.__proxy = None |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | url = QUrl("ftp://{0}:{1}".format( |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | Preferences.getHelp("SyncFtpServer"), |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | Preferences.getHelp("SyncFtpPort") |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | )) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | query = QNetworkProxyQuery(url) |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
88 | proxyList = E5NetworkProxyFactory().queryProxy(query) |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | ftpProxy = QNetworkProxy() |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | for proxy in proxyList: |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | if proxy.type() == QNetworkProxy.NoProxy or \ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | proxy.type() == QNetworkProxy.FtpCachingProxy: |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | ftpProxy = proxy |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | break |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | if ftpProxy.type() == QNetworkProxy.DefaultProxy: |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | self.syncError.emit(self.trUtf8("No suitable proxy found.")) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | return |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | elif ftpProxy.type() == QNetworkProxy.FtpCachingProxy: |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
99 | self.__proxy = ftpProxy |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
100 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
101 | QTimer.singleShot(0, self.__doFtpCommands) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
102 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
103 | def __doFtpCommands(self): |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
104 | """ |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
105 | Private slot executing the sequence of FTP commands. |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
106 | """ |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
107 | try: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
108 | ok = self.__connectAndLogin() |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
109 | if ok: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
110 | self.__changeToStore() |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
111 | self.__ftp.retrlines("LIST", self.__dirListCallback) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
112 | self.__initialSync() |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
113 | self.__state = "idle" |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
114 | self.__idleTimer.start() |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
115 | except ftplib.all_errors as err: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
116 | self.syncError.emit(str(err)) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
117 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
118 | def __connectAndLogin(self): |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
119 | """ |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
120 | Private method to connect to the FTP server and log in. |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
122 | @return flag indicating a successful log in (boolean) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
123 | """ |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
124 | retry = True |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
125 | while retry: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
126 | if self.__proxy: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
127 | self.__ftp.connect( |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
128 | self.__proxy.hostName(), |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
129 | self.__proxy.port(), |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
130 | timeout=10) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
131 | else: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
132 | self.__ftp.connect( |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
133 | Preferences.getHelp("SyncFtpServer"), |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
134 | Preferences.getHelp("SyncFtpPort"), |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
135 | timeout=10) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
136 | ok, retry = self.__doFtpLogin( |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
137 | Preferences.getHelp("SyncFtpUser"), |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
138 | Preferences.getHelp("SyncFtpPassword")) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
139 | self.__connected = ok |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
140 | if not ok: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
141 | self.syncError.emit(self.trUtf8("Cannot log in to FTP host.")) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
142 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
143 | return ok |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
144 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
145 | def __doFtpLogin(self, username, password): |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
146 | """ |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
147 | Private method to do the FTP login with asking for a username and password, |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
148 | if the login fails with an error 530. |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
149 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
150 | @param username user name to use for the login (string) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
151 | @param password password to use for the login (string) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
152 | @return tuple of two flags indicating a successful login and |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
153 | if the login should be retried (boolean, boolean) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
154 | """ |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
155 | # 1. do proxy login, if a proxy is used |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
156 | if self.__proxy: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
157 | try: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
158 | self.__ftp.login(self.__proxy.user(), self.__proxy.password()) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
159 | except ftplib.error_perm as err: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
160 | code, msg = err.args[0].split(None, 1) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
161 | if code.strip() == "530": |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
162 | auth = QAuthenticator() |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
163 | auth.setOption("realm", self.__proxy.hostName()) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
164 | proxyAuthenticationRequired(self.__proxy, auth) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
165 | if not auth.isNull() and auth.user(): |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
166 | self.__proxy.setUser(auth.user()) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
167 | self.__proxy.setPassword(auth.password()) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
168 | return False, True |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
169 | return False, False |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
170 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
171 | # 2. do the real login |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
172 | if self.__proxy: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
173 | loginName = "{0}@{1}".format( |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
174 | username, Preferences.getHelp("SyncFtpServer")) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
175 | if Preferences.getHelp("SyncFtpPort") != ftplib.FTP_PORT: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
176 | loginName = "{0}:{1}".format( |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
177 | loginName, Preferences.getHelp("SyncFtpPort")) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
178 | else: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
179 | loginName = username |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
180 | self.__ftp.login(loginName, password) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
181 | return True, False |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | def __changeToStore(self): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
184 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
185 | Private slot to change to the storage directory. |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
187 | This action will create the storage path on the server, if it |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
188 | does not exist. Upon return, the current directory of the server |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
189 | is the sync directory. |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | """ |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
191 | storePathList = \ |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
192 | Preferences.getHelp("SyncFtpPath").replace("\\", "/").split("/") |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
193 | if storePathList[0] == "": |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
194 | storePathList.pop(0) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
195 | while storePathList: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
196 | path = storePathList[0] |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
197 | try: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
198 | self.__ftp.cwd(path) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
199 | except ftplib.error_perm as err: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
200 | code, msg = err.args[0].split(None, 1) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
201 | if code.strip() == "550": |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
202 | # path does not exist, create it |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
203 | self.__ftp.mkd(path) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
204 | self.__ftp.cwd(path) |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | else: |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
206 | raise |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
207 | storePathList.pop(0) |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
209 | def __dirListCallback(self, line): |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | """ |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
211 | Private slot handling the receipt of directory listing lines. |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
212 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
213 | @param line the received line of the directory listing (string) |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | """ |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
215 | try: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
216 | urlInfo = self.__dirLineParser.parseLine(line) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
217 | except FtpDirLineParserError: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
218 | # silently ignore parser errors |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
219 | urlInfo = None |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
221 | if urlInfo and urlInfo.isValid() and urlInfo.isFile(): |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
222 | if urlInfo.name() in self._remoteFiles.values(): |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
223 | self.__remoteFilesFound[urlInfo.name()] = urlInfo.lastModified() |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
224 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
225 | QCoreApplication.processEvents() |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | |
1695
7b115f986d48
Added capability to synchronize bookmarks, history, passwords and user agent settings via a shared directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1681
diff
changeset
|
227 | def __downloadFile(self, type_, fileName, timestamp): |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
228 | """ |
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
229 | Private method to downlaod the given file. |
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
230 | |
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
231 | @param type_ type of the synchronization event (string one |
1701
9eee32bac32e
Added option to only encrypt passwords upon synchronisation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1700
diff
changeset
|
232 | of "bookmarks", "history", "passwords", "useragents" or "speeddial") |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
233 | @param fileName name of the file to be downloaded (string) |
1695
7b115f986d48
Added capability to synchronize bookmarks, history, passwords and user agent settings via a shared directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1681
diff
changeset
|
234 | @param timestamp time stamp in seconds of the file to be downloaded (int) |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
235 | """ |
1700
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
236 | self.syncStatus.emit(type_, self._messages[type_]["RemoteExists"]) |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
237 | buffer = io.BytesIO() |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
238 | try: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
239 | self.__ftp.retrbinary( |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
240 | "RETR {0}".format(self._remoteFiles[type_]), |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
241 | lambda x: self.__downloadFileCallback(buffer, x)) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
242 | ok, error = self.writeFile( |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
243 | QByteArray(buffer.getvalue()), fileName, type_, timestamp) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
244 | if not ok: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
245 | self.syncStatus.emit(type_, error) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
246 | self.syncFinished.emit(type_, ok, True) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
247 | except ftplib.all_errors as err: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
248 | self.syncStatus.emit(type_, str(err)) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
249 | self.syncFinished.emit(type_, False, True) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
250 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
251 | def __downloadFileCallback(self, buffer, data): |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
252 | """ |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
253 | Private method receiving the downloaded data. |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
254 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
255 | @param buffer reference to the buffer (io.BytesIO) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
256 | @param data byte string to store in the buffer (bytes) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
257 | @return number of bytes written to the buffer (integer) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
258 | """ |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
259 | res = buffer.write(data) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
260 | QCoreApplication.processEvents() |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
261 | return res |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
262 | |
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
263 | def __uploadFile(self, type_, fileName): |
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
264 | """ |
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
265 | Private method to upload the given file. |
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
266 | |
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
267 | @param type_ type of the synchronization event (string one |
1701
9eee32bac32e
Added option to only encrypt passwords upon synchronisation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1700
diff
changeset
|
268 | of "bookmarks", "history", "passwords", "useragents" or "speeddial") |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
269 | @param fileName name of the file to be uploaded (string) |
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
270 | """ |
1701
9eee32bac32e
Added option to only encrypt passwords upon synchronisation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1700
diff
changeset
|
271 | data = self.readFile(fileName, type_) |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
272 | if data.isEmpty(): |
1700
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
273 | self.syncStatus.emit(type_, self._messages[type_]["LocalMissing"]) |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
274 | self.syncFinished(type_, False, False) |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
275 | else: |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
276 | buffer = io.BytesIO(data.data()) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
277 | try: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
278 | self.__ftp.storbinary( |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
279 | "STOR {0}".format(self._remoteFiles[type_]), |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
280 | buffer, |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
281 | callback=lambda x: QCoreApplication.processEvents()) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
282 | self.syncFinished.emit(type_, True, False) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
283 | except ftplib.all_errors as err: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
284 | self.syncStatus.emit(type_, str(err)) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
285 | self.syncFinished.emit(type_, False, False) |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
286 | |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | def __initialSyncFile(self, type_, fileName): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | Private method to do the initial synchronization of the given file. |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | @param type_ type of the synchronization event (string one |
1701
9eee32bac32e
Added option to only encrypt passwords upon synchronisation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1700
diff
changeset
|
292 | of "bookmarks", "history", "passwords", "useragents" or "speeddial") |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | @param fileName name of the file to be synchronized (string) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | """ |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
295 | if not self.__forceUpload and \ |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
296 | self._remoteFiles[type_] in self.__remoteFilesFound: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
297 | if QFileInfo(fileName).lastModified() < \ |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
298 | self.__remoteFilesFound[self._remoteFiles[type_]]: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
299 | self.__downloadFile(type_, fileName, |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
300 | self.__remoteFilesFound[self._remoteFiles[type_]].toTime_t()) |
2061
b74f1d202ba7
Fixed an issue with the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2060
diff
changeset
|
301 | else: |
b74f1d202ba7
Fixed an issue with the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2060
diff
changeset
|
302 | self.syncStatus.emit(type_, self.trUtf8("No synchronization required.")) |
b74f1d202ba7
Fixed an issue with the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2060
diff
changeset
|
303 | self.syncFinished.emit(type_, True, True) |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
304 | else: |
1695
7b115f986d48
Added capability to synchronize bookmarks, history, passwords and user agent settings via a shared directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1681
diff
changeset
|
305 | if self._remoteFiles[type_] not in self.__remoteFilesFound: |
1700
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
306 | self.syncStatus.emit(type_, self._messages[type_]["RemoteMissing"]) |
1695
7b115f986d48
Added capability to synchronize bookmarks, history, passwords and user agent settings via a shared directory.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1681
diff
changeset
|
307 | else: |
1700
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
308 | self.syncStatus.emit(type_, self._messages[type_]["LocalNewer"]) |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
309 | self.__uploadFile(type_, fileName) |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | def __initialSync(self): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
312 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
313 | Private slot to do the initial synchronization. |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
314 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
315 | # Bookmarks |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
316 | if Preferences.getHelp("SyncBookmarks"): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
317 | self.__initialSyncFile("bookmarks", |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
318 | Helpviewer.HelpWindow.HelpWindow.bookmarksManager().getFileName()) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
319 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
320 | # History |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | if Preferences.getHelp("SyncHistory"): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
322 | self.__initialSyncFile("history", |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
323 | Helpviewer.HelpWindow.HelpWindow.historyManager().getFileName()) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
325 | # Passwords |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
326 | if Preferences.getHelp("SyncPasswords"): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
327 | self.__initialSyncFile("passwords", |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
328 | Helpviewer.HelpWindow.HelpWindow.passwordManager().getFileName()) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
329 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
330 | # User Agent Settings |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
331 | if Preferences.getHelp("SyncUserAgents"): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
332 | self.__initialSyncFile("useragents", |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
333 | Helpviewer.HelpWindow.HelpWindow.userAgentsManager().getFileName()) |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
334 | |
1700
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
335 | # Speed Dial Settings |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
336 | if Preferences.getHelp("SyncSpeedDial"): |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
337 | self.__initialSyncFile("speeddial", |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
338 | Helpviewer.HelpWindow.HelpWindow.speedDial().getFileName()) |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
339 | |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
340 | self.__forceUpload = False |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
341 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
342 | def __syncFile(self, type_, fileName): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
343 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
344 | Private method to synchronize the given file. |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
345 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
346 | @param type_ type of the synchronization event (string one |
1701
9eee32bac32e
Added option to only encrypt passwords upon synchronisation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1700
diff
changeset
|
347 | of "bookmarks", "history", "passwords", "useragents" or "speeddial") |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
348 | @param fileName name of the file to be synchronized (string) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
349 | """ |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
350 | if self.__state == "initializing": |
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
351 | return |
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
352 | |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
353 | # use idle timeout to check, if we are still connected |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
354 | if self.__connected: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
355 | self.__idleTimeout() |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
356 | if not self.__connected: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
357 | ok = self.__connectAndLogin() |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
358 | if not ok: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
359 | self.syncStatus.emit(type_, self.trUtf8("Cannot log in to FTP host.")) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
360 | return |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
361 | |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
362 | # upload the changed file |
1638
cd2f9e526710
Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1626
diff
changeset
|
363 | self.__state = "uploading" |
1700
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
364 | self.syncStatus.emit(type_, self._messages[type_]["Uploading"]) |
1680
28e57079dab5
Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1638
diff
changeset
|
365 | self.__uploadFile(type_, fileName) |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
366 | self.syncStatus.emit(type_, self.trUtf8("Synchronization finished.")) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
367 | self.__state = "idle" |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
368 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
369 | def syncBookmarks(self): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
370 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
371 | Public method to synchronize the bookmarks. |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
372 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
373 | self.__syncFile("bookmarks", |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
374 | Helpviewer.HelpWindow.HelpWindow.bookmarksManager().getFileName()) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
375 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
376 | def syncHistory(self): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
377 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
378 | Public method to synchronize the history. |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
379 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
380 | self.__syncFile("history", |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
381 | Helpviewer.HelpWindow.HelpWindow.historyManager().getFileName()) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
382 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
383 | def syncPasswords(self): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
384 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
385 | Public method to synchronize the passwords. |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
386 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
387 | self.__syncFile("passwords", |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
388 | Helpviewer.HelpWindow.HelpWindow.passwordManager().getFileName()) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
389 | |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
390 | def syncUserAgents(self): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
391 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
392 | Public method to synchronize the user agents. |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
393 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
394 | self.__syncFile("useragents", |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
395 | Helpviewer.HelpWindow.HelpWindow.userAgentsManager().getFileName()) |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
396 | |
1700
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
397 | def syncSpeedDial(self): |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
398 | """ |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
399 | Public method to synchronize the speed dial data. |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
400 | """ |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
401 | self.__syncFile("speeddial", |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
402 | Helpviewer.HelpWindow.HelpWindow.speedDial().getFileName()) |
40c911b8c0dd
Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1695
diff
changeset
|
403 | |
1626
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
404 | def shutdown(self): |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
405 | """ |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
406 | Public method to shut down the handler. |
a77c8ea8582c
Added capability to synchronise bookmarks, history, passwords and user agent settings via an FTP server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
407 | """ |
1638
cd2f9e526710
Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1626
diff
changeset
|
408 | if self.__idleTimer.isActive(): |
cd2f9e526710
Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1626
diff
changeset
|
409 | self.__idleTimer.stop() |
cd2f9e526710
Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1626
diff
changeset
|
410 | |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
411 | try: |
2062
f275d3afe038
Fixed a little issue in the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2061
diff
changeset
|
412 | if self.__connected: |
f275d3afe038
Fixed a little issue in the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
2061
diff
changeset
|
413 | self.__ftp.quit() |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
414 | except ftplib.all_errors: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
415 | pass # ignore FTP errors because we are shutting down anyway |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
416 | self.__connected = False |
1638
cd2f9e526710
Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1626
diff
changeset
|
417 | |
cd2f9e526710
Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1626
diff
changeset
|
418 | def __idleTimeout(self): |
cd2f9e526710
Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1626
diff
changeset
|
419 | """ |
cd2f9e526710
Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1626
diff
changeset
|
420 | Private slot to prevent a disconnect from the server. |
cd2f9e526710
Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1626
diff
changeset
|
421 | """ |
2060
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
422 | if self.__state == "idle" and self.__connected: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
423 | try: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
424 | self.__ftp.voidcmd("NOOP") |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
425 | except ftplib.Error as err: |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
426 | code, msg = err.args[0].split(None, 1) |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
427 | if code.strip() == "421": |
1f3767746974
Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
1701
diff
changeset
|
428 | self.__connected = False |