src/eric7/WebBrowser/Sync/FtpSyncHandler.py

Wed, 13 Jul 2022 14:55:47 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 13 Jul 2022 14:55:47 +0200
branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
permissions
-rw-r--r--

Reformatted the source code using the 'Black' utility.

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
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
10 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
11 import io
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
12 import contextlib
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
9153
506e35e424d5 Finished replacing the use of "QFileInfo()" with Python equivalents.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
15 from PyQt6.QtCore import pyqtSignal, QTimer, QCoreApplication, QByteArray
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
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
17 from EricNetwork.EricFtp import EricFtp, EricFtpProxyType, EricFtpProxyError
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
4774
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
21 from 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
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.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
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
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
33 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
34 "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
35 @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
36 message (string)
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
37 @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
38 synchronization (string)
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
39 @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
40 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
41 "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
42 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
43
1700
40c911b8c0dd Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1695
diff changeset
44 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
45 syncError = pyqtSignal(str)
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
46 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
47 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
48
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
49 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
50 """
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 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
52
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
53 @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
54 """
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
55 super().__init__(parent)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
56
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 self.__state = "idle"
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
58 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
59 self.__connected = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
60
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
61 self.__remoteFilesFound = {}
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
62
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
63 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
64 """
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 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
66
7900
72b88fb20261 Corrected the use of '@keyparam' in the source documentation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7836
diff changeset
67 @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
68 (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
69 """
4774
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
70 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
71 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
72
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
73 self.__state = "initializing"
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
74 self.__forceUpload = forceUpload
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
75
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
76 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
77 self.__remoteFilesFound = {}
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
78
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
79 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
80 self.__idleTimer.setInterval(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
81 Preferences.getWebBrowser("SyncFtpIdleTimeout") * 1000
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
82 )
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
83 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
84
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
85 self.__ftp = EricFtp()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
86
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
87 # 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
88 proxyType = (
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
89 EricFtpProxyType.NO_PROXY
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
90 if not Preferences.getUI("UseProxy")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
91 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
92 )
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
93 if proxyType != EricFtpProxyType.NO_PROXY:
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
94 self.__ftp.setProxy(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3002
diff changeset
95 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
96 Preferences.getUI("ProxyHost/Ftp"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
97 Preferences.getUI("ProxyPort/Ftp"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
98 )
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
99 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
100 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
101 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
102 Preferences.getUI("ProxyPassword/Ftp"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
103 Preferences.getUI("ProxyAccount/Ftp"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
104 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
105
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
106 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
107
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
108 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
109 """
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 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
111 """
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 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
113 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
114 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
115 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
116 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
117 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
118 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
119 self.__idleTimer.start()
8354
12ebd3934fef Renamed 'E5Utilities' to 'EricUtilities' and 'E5Network' to 'EricNetwork'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8318
diff changeset
120 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
121 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
122
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
123 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
124 """
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 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
126
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
127 @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
128 """
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
129 self.__ftp.connect(
4774
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
130 Preferences.getWebBrowser("SyncFtpServer"),
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
131 Preferences.getWebBrowser("SyncFtpPort"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
132 timeout=5,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
133 )
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
134 self.__ftp.login(
4774
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
135 Preferences.getWebBrowser("SyncFtpUser"),
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
136 Preferences.getWebBrowser("SyncFtpPassword"),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
137 )
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
138 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
139 return True
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
140
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
141 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
142 """
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
143 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
144
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
145 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
146 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
147 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
148 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
149 storePathList = (
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
150 Preferences.getWebBrowser("SyncFtpPath").replace("\\", "/").split("/")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
151 )
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
152 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
153 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
154 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
155 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
156 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
157 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
158 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
159 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
160 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
161 # 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
162 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
163 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
164 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
165 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
166 storePathList.pop(0)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
167
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
168 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
169 """
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
170 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
171
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
172 @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
173 """
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
174 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
175 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
176 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
177 # 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
178 urlInfo = None
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
179
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
180 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
181 urlInfo
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
182 and urlInfo.isValid()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
183 and urlInfo.isFile()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
184 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
185 ):
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
186 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
187
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
188 QCoreApplication.processEvents()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
189
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
190 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
191 """
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
192 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
193
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
194 @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
195 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
196 "speeddial")
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
197 @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
198 @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
199 (integer)
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
200 """
1700
40c911b8c0dd Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1695
diff changeset
201 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
202 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
203 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
204 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
205 "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
206 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
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 ok, error = self.writeFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
209 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
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 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
212 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
213 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
214 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
215 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
216 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
217
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
218 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
219 """
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 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
221
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
222 @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
223 @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
224 @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
225 """
1f3767746974 Changed the FTP sync code in the eric web browser to use ftplib.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1701
diff changeset
226 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
227 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
228 return res
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
229
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
230 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
231 """
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
232 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
233
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
234 @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
235 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
236 "speeddial")
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
237 @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
238 @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
239 """
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
240 res = False
1701
9eee32bac32e Added option to only encrypt passwords upon synchronisation.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1700
diff changeset
241 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
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 "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
250 buffer,
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
251 callback=lambda x: QCoreApplication.processEvents(),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
252 )
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
253 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
254 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
255 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
256 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
257 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
258 return res
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
259
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
260 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
261 """
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
262 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
263
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 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
265 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
266 "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
267 @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
268 """
7269
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
269 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
270 not self.__forceUpload
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
271 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
272 ):
0c63ea7f94bd Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
273 if (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
274 not pathlib.Path(fileName).exists()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
275 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
276 < 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
277 ):
3002
6ffc581f00f1 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
278 self.__downloadFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
279 type_,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
280 fileName,
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
281 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
282 )
2061
b74f1d202ba7 Fixed an issue with the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2060
diff changeset
283 else:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
284 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
285 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
286 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
287 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
288 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
289 else:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
290 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
291 self.__uploadFile(type_, fileName)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
292
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 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
294 """
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
295 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
296 """
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
297 # Bookmarks
4774
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
298 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
299 self.__initialSyncFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
300 "bookmarks", WebBrowserWindow.bookmarksManager().getFileName()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
301 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
302
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
303 # History
4774
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
304 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
305 self.__initialSyncFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
306 "history", WebBrowserWindow.historyManager().getFileName()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
307 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
308
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
309 # Passwords
4774
2c6ffa778c3b Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4631
diff changeset
310 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
311 self.__initialSyncFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
312 "passwords", WebBrowserWindow.passwordManager().getFileName()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
313 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
314
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
315 # User Agent Settings
4906
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
316 if Preferences.getWebBrowser("SyncUserAgents"):
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
317 self.__initialSyncFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
318 "useragents", WebBrowserWindow.userAgentsManager().getFileName()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
319 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
320
1700
40c911b8c0dd Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1695
diff changeset
321 # Speed Dial Settings
4868
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4774
diff changeset
322 if Preferences.getWebBrowser("SyncSpeedDial"):
985d275502c8 Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4774
diff changeset
323 self.__initialSyncFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
324 "speeddial", WebBrowserWindow.speedDial().getFileName()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
325 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
326
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
327 self.__forceUpload = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
328
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
329 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
330 """
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 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
332
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 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
334 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
335 "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
336 @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
337 """
1680
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
338 if self.__state == "initializing":
28e57079dab5 Added capability to encrypt the synchronized data (web browser).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1638
diff changeset
339 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
340
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
341 # 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
342 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
343 self.__idleTimeout()
2076
0d6286344ac1 Fixed an issue with the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
344 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
345 ok = self.__connectAndLogin()
0d6286344ac1 Fixed an issue with the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2074
diff changeset
346 if not ok:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
347 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
348 return
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
349
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
350 # 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
351 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
352 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
353 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
354 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
355 self.__state = "idle"
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
356
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
357 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
358 """
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
359 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
360 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
361 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
362
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
363 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
364 """
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
365 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
366 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
367 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
368
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
369 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
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 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
372 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
373 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
374
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
375 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
376 """
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 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
378 """
4906
939ff20f712d Continued porting the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4868
diff changeset
379 self.__syncFile(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
380 "useragents", WebBrowserWindow.userAgentsManager().getFileName()
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
381 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
382
1700
40c911b8c0dd Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1695
diff changeset
383 def syncSpeedDial(self):
40c911b8c0dd Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1695
diff changeset
384 """
40c911b8c0dd Made the speed dial settings synchronizable via the sync manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1695
diff changeset
385 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
386 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
387 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
388
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
389 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
390 """
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 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
392 """
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
393 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
394 self.__idleTimer.stop()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
395
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
396 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
397 if self.__connected:
f275d3afe038 Fixed a little issue in the FTP sync handler.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2061
diff changeset
398 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
399 self.__connected = False
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
400
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
401 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
402 """
cd2f9e526710 Added an idle timeout to the FTP synchronization handler to prevent server disconnects.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1626
diff changeset
403 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
404 """
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
405 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
406 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
407 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
408 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
409 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
410 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
411 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
412 except OSError:
2064
79cfe18963ae Added another check to the FTP sync handler idle routine.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2062
diff changeset
413 self.__connected = False

eric ide

mercurial