예제 #1
0
 def deleteLocalFile(self, localPath, remotePath):
     #logging.warn('delete local file %s' % localPath)
     head, tail = os.path.split(localPath)
     self.outputQueue.put(messages.Status('Deleting %s' % tail))
     send2trash(localPath)
     self.state.removeObjectSyncRecord(remotePath)
     self.outputQueue.put(self._get_working_message())
예제 #2
0
 def perform(self):
     #logging.debug('Authenticate::perform')
     if self.can_authenticate():
         self.outputQueue.put(messages.Status('Authenticating...'))
         if self.objectStore.authenticate():
             self.outputQueue.put(messages.Status('Authenticated'))
             self.isAuthenticated = True
             self.retryWait = 1
         else:
             self.isAuthenticated = False
             self.outputQueue.put(messages.Status('Connection failed'))
             self.retryWait = min(120, self.retryWait * 2)
     else:
         status = 'Waiting for settings'
         self.outputQueue.put(messages.Status(status))
         self.retryWait = 1
예제 #3
0
 def perform(self):
     # get the current directory
     #logging.debug('Download::perform')
     self.outputQueue.put(self._get_working_message())
     files = self.objectStore.list_dir(None)
     for f in files:
         if not self.running:
             break
         #logging.debug('f.path = %r' % f.path)
         if f.isFolder:
             if f.name == self.trashFolder:
                 # we don't download the trash folder
                 continue
             else:
                 skipChildren = self.download_folder(f)
                 # if we deleted a bunch of stuff - it might
                 # mean our files list is out of wack
                 # so lets rather just break out - and restart
                 # next time round
                 if skipChildren:
                     logging.info('break')
                     break
         else:
             self.download_file(f)
     self.outputQueue.put(messages.Status('Local files up to date'))
예제 #4
0
 def delete_remote_file(self, path):
     self._set_hadWorkToDo(True)
     logging.info('delete remote file: %s' % path)
     head, tail = os.path.split(path)
     self.outputQueue.put(messages.Status('Deleting %s' % tail))
     self.objectStore.delete_object(path, moveToTrash=True)
     self.state.removeObjectSyncRecord(path)
     self.outputQueue.put(self._get_working_message())
예제 #5
0
 def replace_file(self, f, localPath):
     self._set_hadWorkToDo(True)
     head, tail = os.path.split(localPath)
     self.outputQueue.put(messages.Status('Downloading %s' % tail))
     tmpFile = self.get_tmp_filename()
     if os.path.exists(tmpFile):
         # if a temporary file with the same name exists, remove it
         os.remove(tmpFile)
     self.objectStore.download_object(f.path, tmpFile)
     send2trash(localPath)
     os.rename(tmpFile, localPath)
     localMD = self.localStore.get_last_modified_date(localPath)
     self.state.markObjectAsSynced(f.path, f.hash, localMD)
     self.outputQueue.put(self._get_working_message())
예제 #6
0
 def uploadFile(self, localPath, remotePath):
     #logging.warn('upload local file %s' % localPath)
     head, tail = os.path.split(localPath)
     self.outputQueue.put(messages.Status('Uploading %s' % tail))
     # before we upload it - we calculate the hash
     localFileInfo = self.localStore.get_file_info(localPath)
     self.objectStore.upload_object(localPath,
                                    remotePath,
                                    localFileInfo.hash)
     localMD = self.localStore.get_last_modified_date(localPath)
     self.state.markObjectAsSynced(remotePath,
                                   localFileInfo.hash,
                                   localMD)
     self.outputQueue.put(self._get_working_message())
예제 #7
0
 def perform(self):
     self.outputQueue.put(self._get_working_message())
     #logging.debug('Upload::perform')
     if not os.path.exists(self.localSyncPath):
         os.makedirs(self.localSyncPath)
     files = os.listdir(self.localSyncPath)
     for f in files:
         if not self._isRunning:
             break
         #logging.debug('upload: %s' % f)
         fullPath = os.path.join(self.localSyncPath, f)
         if os.path.isdir(fullPath):
             #logging.debug('is directory')
             self.upload_directory(f)
         elif os.path.isfile(fullPath):
             self.processFile(fullPath, f)
     self.outputQueue.put(messages.Status('Remote files up to date'))
예제 #8
0
 def _get_working_message(self):
     return messages.Status('Checking for updates')
예제 #9
0
 def download_file(self, f):
     localPath = self.get_local_path(f.path)
     if not os.path.exists(localPath):
         self._set_hadWorkToDo(True)
         #logging.debug('does not exist: %s' % localPath)
         if self.already_synced_file(f.path):
             # if we've already downloaded this file,
             # it means we have to delete it remotely!
             logging.info('delete remote version of %s' % localPath)
             self.delete_remote_file(f.path)
         else:
             # lets get the file
             head, tail = os.path.split(localPath)
             self.outputQueue.put(messages.Status('Downloading %s' % tail))
             tmpFile = self.get_tmp_filename()
             if os.path.exists(tmpFile):
                 # if a temporary file with the same name
                 # exists, delete it
                 os.remove(tmpFile)
             self.objectStore.download_object(f.path, tmpFile)
             os.rename(tmpFile, localPath)
             localMD = self.localStore.get_last_modified_date(localPath)
             self.state.markObjectAsSynced(f.path, f.hash, localMD)
             self.outputQueue.put(self._get_working_message())
     else:
         # the file already exists - do we overwrite it?
         syncInfo = self.state.getObjectSyncInfo(f.path)
         if syncInfo:
             localMD = self.localStore.get_last_modified_date(localPath)
             if syncInfo.dateModified != localMD:
                 # the dates differ! we need to calculate the hash!
                 localFileInfo = self.localStore.get_file_info(localPath)
                 if localFileInfo.hash != f.hash:
                     # hmm - ok, if the online one, has the same hash
                     # as I synced, then it means the local file
                     # has changed!
                     if syncInfo.hash == f.hash:
                         # online and synced have the same version!
                         # that means the local one has changed
                         # so we're not downloading anything
                         # the upload process should handle this
                         pass
                     else:
                         logging.warn('TODO: the files differ - which '
                                      'one do I use?')
                 else:
                     # all good - the files are the same
                     # we can update our local sync info
                     self.state.markObjectAsSynced(f.path,
                                                   localFileInfo.hash,
                                                   localMD)
             else:
                 # dates are the same, so we can assume the hash
                 # hasn't changed
                 if syncInfo.hash != f.hash:
                     # if the sync info is the same as the local file
                     # then it must mean the remote file has changed!
                     get_file_info = self.localStore.get_file_info
                     localFileInfo = get_file_info(localPath)
                     if localFileInfo.hash == syncInfo.hash:
                         self.replace_file(f, localPath)
                     else:
                         logging.info('remote hash: %r' % f.hash)
                         logging.info('local hash: %r' % localFileInfo.hash)
                         logging.info('sync hash: %r' % syncInfo.hash)
                         logging.warn('sync hash differs from local hash!')
                 else:
                     # sync hash is same as remote hash, and the file date
                     # hasn't changed. we assume this to mean, there have
                     # been no changes
                     pass
         else:
             # TODO: we need to do something here!
             # the file exists locally, and remotely - but we don't have any
             # record of having downloaded it
             localFileInfo = self.localStore.get_file_info(localPath)
             if localFileInfo.hash == f.hash:
                 localMD = self.localStore.get_last_modified_date(localPath)
                 self.state.markObjectAsSynced(f.path, localFileInfo.hash,
                                               localMD)
             else:
                 # we don't have any history of this file - and the hash
                 # from local differs from remote! WHAT DO WE DO!
                 logging.error(
                     'TODO: HASH differs! Which is which????: %r' % f.path)
         pass
예제 #10
0
 def _get_working_message(self):
     return messages.Status('Looking for files to download')