Helpviewer/Sync/DirectorySyncHandler.py

changeset 3002
6ffc581f00f1
parent 2829
528d6b04e0be
child 3022
57179e4cdadd
child 3057
10516539f238
--- a/Helpviewer/Sync/DirectorySyncHandler.py	Wed Oct 09 19:47:41 2013 +0200
+++ b/Helpviewer/Sync/DirectorySyncHandler.py	Thu Oct 10 18:35:45 2013 +0200
@@ -23,13 +23,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)
@@ -51,7 +53,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
@@ -60,7 +63,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"))
@@ -77,9 +81,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:
@@ -94,7 +100,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)
@@ -104,7 +111,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()
@@ -120,8 +128,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
             
@@ -132,24 +142,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):
@@ -159,26 +175,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
@@ -194,7 +218,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"])

eric ide

mercurial