src/eric7/WebBrowser/Sync/DirectorySyncHandler.py

branch
eric7
changeset 10436
f6881d10e995
parent 9653
e67609152c5e
child 10439
21c28b0f9e41
equal deleted inserted replaced
10435:c712d09cc839 10436:f6881d10e995
20 20
21 class DirectorySyncHandler(SyncHandler): 21 class DirectorySyncHandler(SyncHandler):
22 """ 22 """
23 Class implementing a synchronization handler using a shared directory. 23 Class implementing a synchronization handler using a shared directory.
24 24
25 @signal syncStatus(type_, message) emitted to indicate the synchronization 25 @signal syncStatus(type_, message) emitted to indicate the synchronization status
26 status (string one of "bookmarks", "history", "passwords", 26 @signal syncError(message) emitted for a general error with the error message
27 "useragents" or "speeddial", string) 27 @signal syncMessage(message) emitted to send a message about synchronization
28 @signal syncError(message) emitted for a general error with the error 28 @signal syncFinished(type_, done, download) emitted after a synchronization
29 message (string) 29 has finished
30 @signal syncMessage(message) emitted to send a message about
31 synchronization (string)
32 @signal syncFinished(type_, done, download) emitted after a
33 synchronization has finished (string one of "bookmarks", "history",
34 "passwords", "useragents" or "speeddial", boolean, boolean)
35 """ 30 """
36 31
37 syncStatus = pyqtSignal(str, str) 32 syncStatus = pyqtSignal(str, str)
38 syncError = pyqtSignal(str) 33 syncError = pyqtSignal(str)
39 syncMessage = pyqtSignal(str) 34 syncMessage = pyqtSignal(str)
41 36
42 def __init__(self, parent=None): 37 def __init__(self, parent=None):
43 """ 38 """
44 Constructor 39 Constructor
45 40
46 @param parent reference to the parent object (QObject) 41 @param parent reference to the parent object
42 @type QObject
47 """ 43 """
48 super().__init__(parent) 44 super().__init__(parent)
49 self.__forceUpload = False 45 self.__forceUpload = False
50 46
51 self.__remoteFilesFound = [] 47 self.__remoteFilesFound = []
53 def initialLoadAndCheck(self, forceUpload): 49 def initialLoadAndCheck(self, forceUpload):
54 """ 50 """
55 Public method to do the initial check. 51 Public method to do the initial check.
56 52
57 @param forceUpload flag indicating a forced upload of the files 53 @param forceUpload flag indicating a forced upload of the files
58 (boolean) 54 @type bool
59 """ 55 """
60 if not Preferences.getWebBrowser("SyncEnabled"): 56 if not Preferences.getWebBrowser("SyncEnabled"):
61 return 57 return
62 58
63 self.__forceUpload = forceUpload 59 self.__forceUpload = forceUpload
81 77
82 def __downloadFile(self, type_, fileName, timestamp): 78 def __downloadFile(self, type_, fileName, timestamp):
83 """ 79 """
84 Private method to downlaod the given file. 80 Private method to downlaod the given file.
85 81
86 @param type_ type of the synchronization event (string one 82 @param type_ type of the synchronization event (one of
87 of "bookmarks", "history", "passwords", "useragents" or 83 "bookmarks", "history", "passwords", "useragents" or "speeddial")
88 "speeddial") 84 @type str
89 @param fileName name of the file to be downloaded (string) 85 @param fileName name of the file to be downloaded
86 @type str
90 @param timestamp time stamp in seconds of the file to be downloaded 87 @param timestamp time stamp in seconds of the file to be downloaded
91 (integer) 88 @type int
92 """ 89 """
93 self.syncStatus.emit(type_, self._messages[type_]["RemoteExists"]) 90 self.syncStatus.emit(type_, self._messages[type_]["RemoteExists"])
94 try: 91 try:
95 with open( 92 with open(
96 os.path.join( 93 os.path.join(
115 112
116 def __uploadFile(self, type_, fileName): 113 def __uploadFile(self, type_, fileName):
117 """ 114 """
118 Private method to upload the given file. 115 Private method to upload the given file.
119 116
120 @param type_ type of the synchronization event (string one 117 @param type_ type of the synchronization event (one of "bookmarks",
121 of "bookmarks", "history", "passwords", "useragents" or 118 "history", "passwords", "useragents" or "speeddial")
122 "speeddial") 119 @type str
123 @param fileName name of the file to be uploaded (string) 120 @param fileName name of the file to be uploaded
121 @type str
124 """ 122 """
125 QCoreApplication.processEvents() 123 QCoreApplication.processEvents()
126 data = self.readFile(fileName, type_) 124 data = self.readFile(fileName, type_)
127 if data.isEmpty(): 125 if data.isEmpty():
128 self.syncStatus.emit(type_, self._messages[type_]["LocalMissing"]) 126 self.syncStatus.emit(type_, self._messages[type_]["LocalMissing"])
150 148
151 def __initialSyncFile(self, type_, fileName): 149 def __initialSyncFile(self, type_, fileName):
152 """ 150 """
153 Private method to do the initial synchronization of the given file. 151 Private method to do the initial synchronization of the given file.
154 152
155 @param type_ type of the synchronization event (string one 153 @param type_ type of the synchronization event (one of "bookmarks",
156 of "bookmarks", "history", "passwords", "useragents" or 154 "history", "passwords", "useragents" or "speeddial")
157 "speeddial") 155 @type str
158 @param fileName name of the file to be synchronized (string) 156 @param fileName name of the file to be synchronized
157 @type str
159 """ 158 """
160 if ( 159 if (
161 not self.__forceUpload 160 not self.__forceUpload
162 and os.path.exists( 161 and os.path.exists(
163 os.path.join( 162 os.path.join(
245 244
246 def __syncFile(self, type_, fileName): 245 def __syncFile(self, type_, fileName):
247 """ 246 """
248 Private method to synchronize the given file. 247 Private method to synchronize the given file.
249 248
250 @param type_ type of the synchronization event (string one 249 @param type_ type of the synchronization event (one of "bookmarks",
251 of "bookmarks", "history", "passwords", "useragents" or 250 "history", "passwords", "useragents" or "speeddial")
252 "speeddial") 251 @type str
253 @param fileName name of the file to be synchronized (string) 252 @param fileName name of the file to be synchronized
253 @type str
254 """ 254 """
255 self.syncStatus.emit(type_, self._messages[type_]["Uploading"]) 255 self.syncStatus.emit(type_, self._messages[type_]["Uploading"])
256 self.__uploadFile(type_, fileName) 256 self.__uploadFile(type_, fileName)
257 257
258 def syncBookmarks(self): 258 def syncBookmarks(self):

eric ide

mercurial