src/eric7/WebBrowser/Sync/FtpSyncHandler.py

Fri, 04 Nov 2022 13:52:26 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 04 Nov 2022 13:52:26 +0100
branch
eric7
changeset 9473
3f23dbf37dbe
parent 9413
80c06d472826
child 9653
e67609152c5e
permissions
-rw-r--r--

Resorted the import statements using isort.

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
8881
54e42bc2437a Updated copyright for 2022.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8354
diff changeset
3 # Copyright (c) 2012 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
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
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
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
10 import contextlib
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
11 import ftplib # secok
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
12 import io
9153
506e35e424d5 Finished replacing the use of "QFileInfo()" with Python equivalents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
13 import pathlib
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
14
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
15 from PyQt6.QtCore import QByteArray, QCoreApplication, QTimer, pyqtSignal
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
16
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
17 from eric7 import Preferences
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
18 from eric7.EricNetwork.EricFtp import EricFtp, EricFtpProxyError, EricFtpProxyType
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
19 from eric7.Utilities.FtpUtilities import FtpDirLineParser, FtpDirLineParserError
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
20 from eric7.WebBrowser.WebBrowserWindow import WebBrowserWindow
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
21
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 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
23
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
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
25 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
26 """
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 Class implementing a synchronization handler using FTP.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
28
1700
40c911b8c0dd Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1695
diff changeset
29 @signal syncStatus(type_, message) emitted to indicate the synchronization
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
30 status (string one of "bookmarks", "history", "passwords",
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
31 "useragents" or "speeddial", string)
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
32 @signal syncError(message) emitted for a general error with the error
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
33 message (string)
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
34 @signal syncMessage(message) emitted to send a message about
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
35 synchronization (string)
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
36 @signal syncFinished(type_, done, download) emitted after a
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
37 synchronization has finished (string one of "bookmarks", "history",
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
38 "passwords", "useragents" or "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
39 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
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)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
45
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
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
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
49
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
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 """
8218
7c09585bd960 Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
52 super().__init__(parent)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
53
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
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
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
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 = {}
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
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.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
63
7900
72b88fb20261 Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
64 @param forceUpload flag indicating a forced upload of the files
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
65 (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
66 """
4774
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
67 if not Preferences.getWebBrowser("SyncEnabled"):
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
68 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
69
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
70 self.__state = "initializing"
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
71 self.__forceUpload = forceUpload
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
72
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
73 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
74 self.__remoteFilesFound = {}
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
75
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
76 self.__idleTimer = QTimer(self)
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
77 self.__idleTimer.setInterval(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
78 Preferences.getWebBrowser("SyncFtpIdleTimeout") * 1000
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
79 )
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
80 self.__idleTimer.timeout.connect(self.__idleTimeout)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
81
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
82 self.__ftp = EricFtp()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
83
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
84 # do proxy setup
8260
2161475d9639 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8243
diff changeset
85 proxyType = (
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
86 EricFtpProxyType.NO_PROXY
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
87 if not Preferences.getUI("UseProxy")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
88 else Preferences.getUI("ProxyType/Ftp")
8260
2161475d9639 Applied some more code simplifications suggested by the new Simplify checker (Y108: use ternary operator).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8243
diff changeset
89 )
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
90 if proxyType != EricFtpProxyType.NO_PROXY:
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
91 self.__ftp.setProxy(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
92 proxyType,
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
93 Preferences.getUI("ProxyHost/Ftp"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
94 Preferences.getUI("ProxyPort/Ftp"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
95 )
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
96 if proxyType != EricFtpProxyType.NON_AUTHORIZING:
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
97 self.__ftp.setProxyAuthentication(
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
98 Preferences.getUI("ProxyUser/Ftp"),
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
99 Preferences.getUI("ProxyPassword/Ftp"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
100 Preferences.getUI("ProxyAccount/Ftp"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
101 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
102
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
103 QTimer.singleShot(0, self.__doFtpCommands)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
104
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
105 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
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 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
108 """
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 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
110 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
111 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
112 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
113 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
114 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
115 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
116 self.__idleTimer.start()
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
117 except (ftplib.all_errors + (EricFtpProxyError,)) as err:
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
118 self.syncError.emit(str(err))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
119
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
120 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
121 """
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 Private method to connect to the FTP server and log in.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
123
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
124 @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
125 """
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
126 self.__ftp.connect(
4774
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
127 Preferences.getWebBrowser("SyncFtpServer"),
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
128 Preferences.getWebBrowser("SyncFtpPort"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
129 timeout=5,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
130 )
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
131 self.__ftp.login(
4774
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
132 Preferences.getWebBrowser("SyncFtpUser"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
133 Preferences.getWebBrowser("SyncFtpPassword"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
134 )
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
135 self.__connected = True
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
136 return True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
137
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
138 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
139 """
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
140 Private slot to change to the storage directory.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
141
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
142 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
143 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
144 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
145 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
146 storePathList = (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
147 Preferences.getWebBrowser("SyncFtpPath").replace("\\", "/").split("/")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
148 )
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
149 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
150 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
151 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
152 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
153 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
154 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
155 except ftplib.error_perm as err:
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
156 code = err.args[0].strip()[:3]
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
157 if code == "550":
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
158 # 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
159 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
160 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
161 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
162 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
163 storePathList.pop(0)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
164
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
165 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
166 """
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
167 Private slot handling the receipt of directory listing lines.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
168
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
169 @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
170 """
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
171 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
172 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
173 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
174 # 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
175 urlInfo = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
176
8227
349308e84eeb Applied some more code simplifications suggested by the new Simplify checker (Y102: use single if) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
177 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
178 urlInfo
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
179 and urlInfo.isValid()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
180 and urlInfo.isFile()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
181 and urlInfo.name() in self._remoteFiles.values()
8227
349308e84eeb Applied some more code simplifications suggested by the new Simplify checker (Y102: use single if) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
182 ):
349308e84eeb Applied some more code simplifications suggested by the new Simplify checker (Y102: use single if) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8218
diff changeset
183 self.__remoteFilesFound[urlInfo.name()] = urlInfo.lastModified()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
184
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
185 QCoreApplication.processEvents()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
186
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
187 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
188 """
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
189 Private method to downlaod the given file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
190
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
191 @param type_ type of the synchronization event (string one
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
192 of "bookmarks", "history", "passwords", "useragents" or
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
193 "speeddial")
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
194 @param fileName name of the file to be downloaded (string)
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
195 @param timestamp time stamp in seconds of the file to be downloaded
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
196 (integer)
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
197 """
1700
40c911b8c0dd Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1695
diff changeset
198 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
199 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
200 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
201 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
202 "RETR {0}".format(self._remoteFiles[type_]),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
203 lambda x: self.__downloadFileCallback(buffer, x),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
204 )
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
205 ok, error = self.writeFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
206 QByteArray(buffer.getvalue()), fileName, type_, timestamp
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
207 )
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
208 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
209 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
210 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
211 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
212 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
213 self.syncFinished.emit(type_, False, True)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
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 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
216 """
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 Private method receiving the downloaded data.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
218
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
219 @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
220 @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
221 @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
222 """
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 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
224 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
225 return res
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
226
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
227 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
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 upload the given file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
230
1680
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
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
232 of "bookmarks", "history", "passwords", "useragents" or
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
233 "speeddial")
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
234 @param fileName name of the file to be uploaded (string)
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
235 @return flag indicating success (boolean)
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
236 """
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
237 res = False
1701
9eee32bac32e Added option to only encrypt passwords upon synchronisation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1700
diff changeset
238 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
239 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
240 self.syncStatus.emit(type_, self._messages[type_]["LocalMissing"])
2083
3005ae4463aa Fixed an issue in the FTP sync handler class.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2077
diff changeset
241 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
242 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
243 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
244 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
245 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
246 "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
247 buffer,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
248 callback=lambda x: QCoreApplication.processEvents(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
249 )
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
250 self.syncFinished.emit(type_, True, False)
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
251 res = True
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
252 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
253 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
254 self.syncFinished.emit(type_, False, False)
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
255 return res
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
256
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
257 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
258 """
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
259 Private method to do the initial synchronization of the given file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
260
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
261 @param type_ type of the synchronization event (string one
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
262 of "bookmarks", "history", "passwords", "useragents" or
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
263 "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
264 @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
265 """
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
266 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
267 not self.__forceUpload
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
268 and self._remoteFiles[type_] in self.__remoteFilesFound
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
269 ):
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
270 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
271 not pathlib.Path(fileName).exists()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
272 or pathlib.Path(fileName).stat().st_mtime
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
273 < self.__remoteFilesFound[self._remoteFiles[type_].toSecsSinceEpoch()]
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
274 ):
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
275 self.__downloadFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
276 type_,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
277 fileName,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
278 self.__remoteFilesFound[self._remoteFiles[type_]].toTime_t(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
279 )
2061
b74f1d202ba7 Fixed an issue with the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2060
diff changeset
280 else:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
281 self.syncStatus.emit(type_, self.tr("No synchronization required."))
2061
b74f1d202ba7 Fixed an issue with the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2060
diff changeset
282 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
283 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
284 if self._remoteFiles[type_] not in self.__remoteFilesFound:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
285 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
286 else:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
287 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
288 self.__uploadFile(type_, fileName)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
289
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
290 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
291 """
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
292 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
293 """
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 # Bookmarks
4774
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
295 if Preferences.getWebBrowser("SyncBookmarks"):
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
296 self.__initialSyncFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
297 "bookmarks", WebBrowserWindow.bookmarksManager().getFileName()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
298 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
299
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
300 # History
4774
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
301 if Preferences.getWebBrowser("SyncHistory"):
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
302 self.__initialSyncFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
303 "history", WebBrowserWindow.historyManager().getFileName()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
304 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
305
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
306 # Passwords
4774
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
307 if Preferences.getWebBrowser("SyncPasswords"):
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
308 self.__initialSyncFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
309 "passwords", WebBrowserWindow.passwordManager().getFileName()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
310 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
311
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
312 # User Agent Settings
4906
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
313 if Preferences.getWebBrowser("SyncUserAgents"):
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
314 self.__initialSyncFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
315 "useragents", WebBrowserWindow.userAgentsManager().getFileName()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
316 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
317
1700
40c911b8c0dd Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1695
diff changeset
318 # Speed Dial Settings
4868
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4774
diff changeset
319 if Preferences.getWebBrowser("SyncSpeedDial"):
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4774
diff changeset
320 self.__initialSyncFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
321 "speeddial", WebBrowserWindow.speedDial().getFileName()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
322 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
323
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
324 self.__forceUpload = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
325
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
326 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
327 """
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 Private method to synchronize the given file.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
329
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
330 @param type_ type of the synchronization event (string one
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
331 of "bookmarks", "history", "passwords", "useragents" or
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
332 "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
333 @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
334 """
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
335 if self.__state == "initializing":
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
336 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
337
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
338 # 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
339 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
340 self.__idleTimeout()
2076
0d6286344ac1 Fixed an issue with the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
341 if not self.__connected or self.__ftp.sock is None:
0d6286344ac1 Fixed an issue with the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
342 ok = self.__connectAndLogin()
0d6286344ac1 Fixed an issue with the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
343 if not ok:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
344 self.syncStatus.emit(type_, self.tr("Cannot log in to FTP host."))
2076
0d6286344ac1 Fixed an issue with the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
345 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
346
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
347 # 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
348 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
349 self.syncStatus.emit(type_, self._messages[type_]["Uploading"])
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
350 if self.__uploadFile(type_, fileName):
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
351 self.syncStatus.emit(type_, self.tr("Synchronization finished."))
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
352 self.__state = "idle"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
353
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
354 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
355 """
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
356 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
357 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
358 self.__syncFile("bookmarks", WebBrowserWindow.bookmarksManager().getFileName())
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
359
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
360 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
361 """
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
362 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
363 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
364 self.__syncFile("history", WebBrowserWindow.historyManager().getFileName())
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
365
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
366 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
367 """
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 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
369 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
370 self.__syncFile("passwords", WebBrowserWindow.passwordManager().getFileName())
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
371
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
372 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
373 """
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 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
375 """
4906
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
376 self.__syncFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
377 "useragents", WebBrowserWindow.userAgentsManager().getFileName()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
378 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
379
1700
40c911b8c0dd Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1695
diff changeset
380 def syncSpeedDial(self):
40c911b8c0dd Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1695
diff changeset
381 """
40c911b8c0dd Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1695
diff changeset
382 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
383 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
384 self.__syncFile("speeddial", WebBrowserWindow.speedDial().getFileName())
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
385
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
386 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
387 """
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 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
389 """
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
390 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
391 self.__idleTimer.stop()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
392
8243
cc717c2ae956 Applied some more code simplifications suggested by the new Simplify checker (Y105: use contextlib.suppress) (batch 2).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8227
diff changeset
393 with contextlib.suppress(ftplib.all_errors):
2062
f275d3afe038 Fixed a little issue in the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2061
diff changeset
394 if self.__connected:
f275d3afe038 Fixed a little issue in the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2061
diff changeset
395 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
396 self.__connected = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
397
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
398 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
399 """
cd2f9e526710 Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1626
diff changeset
400 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
401 """
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
402 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
403 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
404 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
405 except ftplib.Error as err:
2074
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
406 code = err.args[0].strip()[:3]
5cb87968aad5 Reworked the FTP stuff to support a bunch of different FTP proxy types. Unfortunately FTP proxy support is not standardized.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2064
diff changeset
407 if code == "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
408 self.__connected = False
7836
2f0d208b8137 Changed code to not use the OSError aliases (IOError, EnvironmentError, socket.error and select.error) anymore.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7781
diff changeset
409 except OSError:
2064
79cfe18963ae Added another check to the FTP sync handler idle routine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2062
diff changeset
410 self.__connected = False

eric ide

mercurial