diff -r 9986ec0e559a -r 10516539f238 Helpviewer/Sync/DirectorySyncHandler.py --- a/Helpviewer/Sync/DirectorySyncHandler.py Tue Oct 15 22:03:54 2013 +0200 +++ b/Helpviewer/Sync/DirectorySyncHandler.py Fri Oct 18 23:00:41 2013 +0200 @@ -25,13 +25,15 @@ Class implementing a synchronization handler using a shared directory. @signal syncStatus(type_, message) emitted to indicate the synchronization - status (string one of "bookmarks", "history", "passwords", "useragents" or - "speeddial", string) - @signal syncError(message) emitted for a general error with the error message (string) - @signal syncMessage(message) emitted to send a message about synchronization (string) - @signal syncFinished(type_, done, download) emitted after a synchronization has - finished (string one of "bookmarks", "history", "passwords", "useragents" or - "speeddial", boolean, boolean) + status (string one of "bookmarks", "history", "passwords", + "useragents" or "speeddial", string) + @signal syncError(message) emitted for a general error with the error + message (string) + @signal syncMessage(message) emitted to send a message about + synchronization (string) + @signal syncFinished(type_, done, download) emitted after a + synchronization has finished (string one of "bookmarks", "history", + "passwords", "useragents" or "speeddial", boolean, boolean) """ syncStatus = pyqtSignal(str, str) syncError = pyqtSignal(str) @@ -53,7 +55,8 @@ """ Public method to do the initial check. - @keyparam forceUpload flag indicating a forced upload of the files (boolean) + @keyparam forceUpload flag indicating a forced upload of the files + (boolean) """ if not Preferences.getHelp("SyncEnabled"): return @@ -62,7 +65,8 @@ self.__remoteFilesFound = [] - # check the existence of the shared directory; create it, if it is not there + # check the existence of the shared directory; create it, if it is + # not there if not os.path.exists(Preferences.getHelp("SyncDirectoryPath")): try: os.makedirs(Preferences.getHelp("SyncDirectoryPath")) @@ -79,9 +83,11 @@ Private method to downlaod the given file. @param type_ type of the synchronization event (string one - of "bookmarks", "history", "passwords", "useragents" or "speeddial") + of "bookmarks", "history", "passwords", "useragents" or + "speeddial") @param fileName name of the file to be downloaded (string) - @param timestamp time stamp in seconds of the file to be downloaded (int) + @param timestamp time stamp in seconds of the file to be downloaded + (integer) """ self.syncStatus.emit(type_, self._messages[type_]["RemoteExists"]) try: @@ -96,7 +102,8 @@ return QCoreApplication.processEvents() - ok, error = self.writeFile(QByteArray(data), fileName, type_, timestamp) + ok, error = self.writeFile(QByteArray(data), fileName, type_, + timestamp) if not ok: self.syncStatus.emit(type_, error) self.syncFinished.emit(type_, ok, True) @@ -106,7 +113,8 @@ Private method to upload the given file. @param type_ type of the synchronization event (string one - of "bookmarks", "history", "passwords", "useragents" or "speeddial") + of "bookmarks", "history", "passwords", "useragents" or + "speeddial") @param fileName name of the file to be uploaded (string) """ QCoreApplication.processEvents() @@ -122,8 +130,10 @@ f.write(bytes(data)) f.close() except IOError as err: - self.syncStatus.emit(type_, - self.trUtf8("Cannot write remote file.\n{0}").format(str(err))) + self.syncStatus.emit( + type_, + self.trUtf8("Cannot write remote file.\n{0}").format( + str(err))) self.syncFinished.emit(type_, False, False) return @@ -134,24 +144,30 @@ Private method to do the initial synchronization of the given file. @param type_ type of the synchronization event (string one - of "bookmarks", "history", "passwords", "useragents" or "speeddial") + of "bookmarks", "history", "passwords", "useragents" or + "speeddial") @param fileName name of the file to be synchronized (string) """ if not self.__forceUpload and \ - os.path.exists(os.path.join(Preferences.getHelp("SyncDirectoryPath"), - self._remoteFiles[type_])) and \ - QFileInfo(fileName).lastModified() <= \ - QFileInfo(os.path.join(Preferences.getHelp("SyncDirectoryPath"), - self._remoteFiles[type_])).lastModified(): + os.path.exists( + os.path.join(Preferences.getHelp("SyncDirectoryPath"), + self._remoteFiles[type_])) and \ + QFileInfo(fileName).lastModified() <= QFileInfo( + os.path.join(Preferences.getHelp("SyncDirectoryPath"), + self._remoteFiles[type_])).lastModified(): self.__downloadFile(type_, fileName, - QFileInfo(os.path.join(Preferences.getHelp("SyncDirectoryPath"), + QFileInfo(os.path.join( + Preferences.getHelp("SyncDirectoryPath"), self._remoteFiles[type_])).lastModified().toTime_t()) else: - if os.path.exists(os.path.join(Preferences.getHelp("SyncDirectoryPath"), - self._remoteFiles[type_])): - self.syncStatus.emit(type_, self._messages[type_]["RemoteMissing"]) + if os.path.exists( + os.path.join(Preferences.getHelp("SyncDirectoryPath"), + self._remoteFiles[type_])): + self.syncStatus.emit( + type_, self._messages[type_]["RemoteMissing"]) else: - self.syncStatus.emit(type_, self._messages[type_]["LocalNewer"]) + self.syncStatus.emit( + type_, self._messages[type_]["LocalNewer"]) self.__uploadFile(type_, fileName) def __initialSync(self): @@ -161,26 +177,34 @@ QCoreApplication.processEvents() # Bookmarks if Preferences.getHelp("SyncBookmarks"): - self.__initialSyncFile("bookmarks", - Helpviewer.HelpWindow.HelpWindow.bookmarksManager().getFileName()) + self.__initialSyncFile( + "bookmarks", + Helpviewer.HelpWindow.HelpWindow.bookmarksManager()\ + .getFileName()) QCoreApplication.processEvents() # History if Preferences.getHelp("SyncHistory"): - self.__initialSyncFile("history", - Helpviewer.HelpWindow.HelpWindow.historyManager().getFileName()) + self.__initialSyncFile( + "history", + Helpviewer.HelpWindow.HelpWindow.historyManager()\ + .getFileName()) QCoreApplication.processEvents() # Passwords if Preferences.getHelp("SyncPasswords"): - self.__initialSyncFile("passwords", - Helpviewer.HelpWindow.HelpWindow.passwordManager().getFileName()) + self.__initialSyncFile( + "passwords", + Helpviewer.HelpWindow.HelpWindow.passwordManager() + .getFileName()) QCoreApplication.processEvents() # User Agent Settings if Preferences.getHelp("SyncUserAgents"): - self.__initialSyncFile("useragents", - Helpviewer.HelpWindow.HelpWindow.userAgentsManager().getFileName()) + self.__initialSyncFile( + "useragents", + Helpviewer.HelpWindow.HelpWindow.userAgentsManager() + .getFileName()) QCoreApplication.processEvents() # Speed Dial Settings @@ -196,7 +220,8 @@ Private method to synchronize the given file. @param type_ type of the synchronization event (string one - of "bookmarks", "history", "passwords", "useragents" or "speeddial") + of "bookmarks", "history", "passwords", "useragents" or + "speeddial") @param fileName name of the file to be synchronized (string) """ self.syncStatus.emit(type_, self._messages[type_]["Uploading"])