diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/WebBrowser/Sync/SyncHandler.py --- a/src/eric7/WebBrowser/Sync/SyncHandler.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/WebBrowser/Sync/SyncHandler.py Wed Jul 13 14:55:47 2022 +0200 @@ -19,7 +19,7 @@ class SyncHandler(QObject): """ Base class for synchronization handlers. - + @signal syncStatus(type_, message) emitted to indicate the synchronization status (string one of "bookmarks", "history", "passwords", "useragents" or "speeddial", string) @@ -31,21 +31,22 @@ synchronization has finished (string one of "bookmarks", "history", "passwords", "useragents" or "speeddial", boolean, boolean) """ + syncStatus = pyqtSignal(str, str) syncError = pyqtSignal(str) syncMessage = pyqtSignal(str) syncFinished = pyqtSignal(str, bool, bool) - + def __init__(self, parent=None): """ Constructor - + @param parent reference to the parent object (QObject) """ super().__init__(parent) - + self._firstTimeSynced = False - + self._remoteFiles = { "bookmarks": "Bookmarks", "history": "History", @@ -53,153 +54,163 @@ "useragents": "UserAgentSettings", "speeddial": "SpeedDial", } - + self._messages = { "bookmarks": { "RemoteExists": self.tr( - "Remote bookmarks file exists! Syncing local copy..."), + "Remote bookmarks file exists! Syncing local copy..." + ), "RemoteMissing": self.tr( - "Remote bookmarks file does NOT exist. Exporting" - " local copy..."), + "Remote bookmarks file does NOT exist. Exporting" " local copy..." + ), "LocalNewer": self.tr( - "Local bookmarks file is NEWER. Exporting local copy..."), + "Local bookmarks file is NEWER. Exporting local copy..." + ), "LocalMissing": self.tr( - "Local bookmarks file does NOT exist. Skipping" - " synchronization!"), + "Local bookmarks file does NOT exist. Skipping" " synchronization!" + ), "Uploading": self.tr("Uploading local bookmarks file..."), }, "history": { "RemoteExists": self.tr( - "Remote history file exists! Syncing local copy..."), + "Remote history file exists! Syncing local copy..." + ), "RemoteMissing": self.tr( - "Remote history file does NOT exist. Exporting" - " local copy..."), + "Remote history file does NOT exist. Exporting" " local copy..." + ), "LocalNewer": self.tr( - "Local history file is NEWER. Exporting local copy..."), + "Local history file is NEWER. Exporting local copy..." + ), "LocalMissing": self.tr( - "Local history file does NOT exist. Skipping" - " synchronization!"), + "Local history file does NOT exist. Skipping" " synchronization!" + ), "Uploading": self.tr("Uploading local history file..."), }, "passwords": { "RemoteExists": self.tr( - "Remote logins file exists! Syncing local copy..."), + "Remote logins file exists! Syncing local copy..." + ), "RemoteMissing": self.tr( - "Remote logins file does NOT exist. Exporting" - " local copy..."), + "Remote logins file does NOT exist. Exporting" " local copy..." + ), "LocalNewer": self.tr( - "Local logins file is NEWER. Exporting local copy..."), + "Local logins file is NEWER. Exporting local copy..." + ), "LocalMissing": self.tr( - "Local logins file does NOT exist. Skipping" - " synchronization!"), + "Local logins file does NOT exist. Skipping" " synchronization!" + ), "Uploading": self.tr("Uploading local logins file..."), }, "useragents": { "RemoteExists": self.tr( - "Remote user agent settings file exists! Syncing local" - " copy..."), + "Remote user agent settings file exists! Syncing local" " copy..." + ), "RemoteMissing": self.tr( "Remote user agent settings file does NOT exist." - " Exporting local copy..."), + " Exporting local copy..." + ), "LocalNewer": self.tr( "Local user agent settings file is NEWER. Exporting" - " local copy..."), + " local copy..." + ), "LocalMissing": self.tr( "Local user agent settings file does NOT exist." - " Skipping synchronization!"), - "Uploading": self.tr( - "Uploading local user agent settings file..."), + " Skipping synchronization!" + ), + "Uploading": self.tr("Uploading local user agent settings file..."), }, "speeddial": { "RemoteExists": self.tr( - "Remote speed dial settings file exists! Syncing local" - " copy..."), + "Remote speed dial settings file exists! Syncing local" " copy..." + ), "RemoteMissing": self.tr( "Remote speed dial settings file does NOT exist." - " Exporting local copy..."), + " Exporting local copy..." + ), "LocalNewer": self.tr( "Local speed dial settings file is NEWER. Exporting" - " local copy..."), + " local copy..." + ), "LocalMissing": self.tr( "Local speed dial settings file does NOT exist." - " Skipping synchronization!"), - "Uploading": self.tr( - "Uploading local speed dial settings file..."), + " Skipping synchronization!" + ), + "Uploading": self.tr("Uploading local speed dial settings file..."), }, } - + def syncBookmarks(self): """ Public method to synchronize the bookmarks. - + @exception NotImplementedError raised to indicate that this method must be implemented by subclasses """ raise NotImplementedError - + def syncHistory(self): """ Public method to synchronize the history. - + @exception NotImplementedError raised to indicate that this method must be implemented by subclasses """ raise NotImplementedError - + def syncPasswords(self): """ Public method to synchronize the passwords. - + @exception NotImplementedError raised to indicate that this method must be implemented by subclasses """ raise NotImplementedError - + def syncUserAgents(self): """ Public method to synchronize the user agents. - + @exception NotImplementedError raised to indicate that this method must be implemented by subclasses """ raise NotImplementedError - + def syncSpeedDial(self): """ Public method to synchronize the speed dial data. - + @exception NotImplementedError raised to indicate that this method must be implemented by subclasses """ raise NotImplementedError - + def initialLoadAndCheck(self, forceUpload): """ Public method to do the initial check. - + @param forceUpload flag indicating a forced upload of the files (boolean) @exception NotImplementedError raised to indicate that this method must be implemented by subclasses """ raise NotImplementedError - + def shutdown(self): """ Public method to shut down the handler. - + @exception NotImplementedError raised to indicate that this method must be implemented by subclasses """ raise NotImplementedError - + def readFile(self, fileName, type_): """ Public method to read a file. - + If encrypted synchronization is enabled, the data will be encrypted using the relevant encryption key. - + @param fileName name of the file to be read (string) @param type_ type of the synchronization event (string one of "bookmarks", "history", "passwords", "useragents" or @@ -212,36 +223,38 @@ data = inputFile.read() except OSError: return QByteArray() - - if ( - Preferences.getWebBrowser("SyncEncryptData") and - (not Preferences.getWebBrowser("SyncEncryptPasswordsOnly") or - (Preferences.getWebBrowser("SyncEncryptPasswordsOnly") and - type_ == "passwords")) + + if Preferences.getWebBrowser("SyncEncryptData") and ( + not Preferences.getWebBrowser("SyncEncryptPasswordsOnly") + or ( + Preferences.getWebBrowser("SyncEncryptPasswordsOnly") + and type_ == "passwords" + ) ): key = Preferences.getWebBrowser("SyncEncryptionKey") if not key: return QByteArray() - + data, ok = dataEncrypt( - data, key, - keyLength=Preferences.getWebBrowser( - "SyncEncryptionKeyLength"), - hashIterations=100) + data, + key, + keyLength=Preferences.getWebBrowser("SyncEncryptionKeyLength"), + hashIterations=100, + ) if not ok: return QByteArray() - + return QByteArray(data) - + return QByteArray() - + def writeFile(self, data, fileName, type_, timestamp=0): """ Public method to write the data to a file. - + If encrypted synchronization is enabled, the data will be decrypted using the relevant encryption key. - + @param data data to be written and optionally decrypted (QByteArray) @param fileName name of the file the data is to be written to (string) @param type_ type of the synchronization event (string one @@ -252,23 +265,26 @@ string) """ data = bytes(data) - - if ( - Preferences.getWebBrowser("SyncEncryptData") and - (not Preferences.getWebBrowser("SyncEncryptPasswordsOnly") or - (Preferences.getWebBrowser("SyncEncryptPasswordsOnly") and - type_ == "passwords")) + + if Preferences.getWebBrowser("SyncEncryptData") and ( + not Preferences.getWebBrowser("SyncEncryptPasswordsOnly") + or ( + Preferences.getWebBrowser("SyncEncryptPasswordsOnly") + and type_ == "passwords" + ) ): key = Preferences.getWebBrowser("SyncEncryptionKey") if not key: return False, self.tr("Invalid encryption key given.") - + data, ok = dataDecrypt( - data, key, - keyLength=Preferences.getWebBrowser("SyncEncryptionKeyLength")) + data, + key, + keyLength=Preferences.getWebBrowser("SyncEncryptionKeyLength"), + ) if not ok: return False, self.tr("Data cannot be decrypted.") - + try: with open(fileName, "wb") as outputFile: outputFile.write(data)