def put(self, data, overwrite, LUID): """ @returns: The Rid of the page at location LUID """ DataProvider.TwoWay.put(self, data, overwrite, LUID) #If LUID is None, then we have once-upon-a-time uploaded this data if LUID != None: #Check if the remote data exists (i.e. has it been deleted) if self._data_exists(LUID): #The remote page exists if overwrite == False: #Only replace the data if it is newer than the remote one oldData = self._get_data(LUID) comp = data.compare(oldData) if comp == conduit.datatypes.COMPARISON_NEWER: return self._replace_data(LUID, data) elif comp == conduit.datatypes.COMPARISON_EQUAL: #We are the same, so return either rid return oldData.get_rid() else: #If we are older that the remote page, or if the two could not #be compared, then we must ask the user what to do via a conflict raise Exceptions.SynchronizeConflictError( comp, data, oldData) #If we get here then the data is new return self._put_data(data)
def put(self, note, overwrite, LUID=None): """ Stores a Note in Tomboy. """ DataProvider.TwoWay.put(self, note, overwrite, LUID) log.debug("Put note LUID: %s" % LUID) #Check if the note, or one with same title exists existingNote = None if LUID != None: if self.remoteTomboy.NoteExists(LUID): existingNote = self._get_note(LUID) else: LUID = self.remoteTomboy.FindNote(note.get_title()) if LUID != "": existingNote = self._get_note(str(LUID)) #compare with the existing note if existingNote != None: comp = note.compare(existingNote) log.debug("Comparing new %s with existing %s" % (note.get_title(), existingNote.get_title())) if comp == conduit.datatypes.COMPARISON_EQUAL: log.info("Notes are equal") elif overwrite == True or comp == conduit.datatypes.COMPARISON_NEWER: log.info("Updating note") self._update_note(LUID, note) else: raise Exceptions.SynchronizeConflictError( comp, note, existingNote) else: log.info("Saving new Note") LUID = self._create_note(note) return self.get(LUID).get_rid()
def put(self, obj, overwrite, LUID=None): DataProvider.TwoWay.put(self, obj, overwrite, LUID) if LUID != None: existing = self._get_object(LUID) if existing != None: if overwrite == True: rid = self._update_object(LUID, obj) return rid else: comp = obj.compare( existing, "%s-%s" % (self.__class__.__name__, self.get_UID())) # only update if newer if comp != conduit.datatypes.COMPARISON_NEWER: raise Exceptions.SynchronizeConflictError( comp, obj, existing) else: # overwrite and return new ID rid = self._update_object(LUID, obj) return rid # if we get here then it is new... log.info("Creating new object") rid = self._create_object(obj) return rid
def put(self, localfile, overwrite, LUID): """ Stores the given File object remotely on Amazon S3, if certain conditions are met. @returns: The Rid of the page at location LUID. """ DataProvider.TwoWay.put(self, localfile, overwrite, LUID) # If LUID is None, then we have once-upon-a-time uploaded this file if LUID != None: # Check if the remote file exists (i.e. has it been deleted) if self._data_exists(LUID): # The remote file exists if not overwrite: # Only replace the data if it is newer than the remote one remotefile = self._get_data(LUID) comp = localfile.compare(remotefile) if comp == conduit.datatypes.COMPARISON_NEWER: return self._replace_data(LUID, localfile) elif comp == conduit.datatypes.COMPARISON_EQUAL: # We are the same, so return either rid return remotefile.get_rid() else: # If we are older than the remote page, or if the two # could not be compared, then we must ask the user what # to do via a conflict raise Exceptions.SynchronizeConflictError( comp, localfile, remotefile) # If we get here then the file is new return self._put_data(localfile)
def put(self, data, overwrite, LUID=None): DataProvider.DataSink.put(self, data, overwrite, LUID) newData = TestDataType(data.get_UID()) if not overwrite: raise Exceptions.SynchronizeConflictError( conduit.datatypes.COMPARISON_UNKNOWN, data, newData) return newData.get_rid()
def marshal_fault_to_exception(fault, **kwargs): if fault.faultCode in XML_RPC_EASY_EXCEPTIONS: klass = getattr(Exceptions, fault.faultCode) #exception.message = fault.faultString raise klass(fault.faultString) elif fault.faultCode == "SynchronizeConflictError": fromData = kwargs['server'].get(kwargs['fromDataLUID']) toData = kwargs['toData'] raise Exceptions.SynchronizeConflictError(fault.faultString, fromData, toData) else: raise Exception("Remote Exception:\n%s" % fault.faultString)
def put(self, photo, overwrite, LUID=None): """ Accepts a vfs file. Must be made local. I also store a md5 of the photos uri to check for duplicates """ DataProvider.DataSink.put(self, photo, overwrite, LUID) originalName = photo.get_filename() #Gets the local URI (/foo/bar). If this is a remote file then #it is first transferred to the local filesystem photoURI = photo.get_local_uri() mimeType = photo.get_mimetype() tags = photo.get_tags() caption = photo.get_caption() uploadInfo = UploadInfo(photoURI, mimeType, originalName, tags, caption) #Check if we have already uploaded the photo if LUID != None: info = self._get_photo_info(LUID) #check if a photo exists at that UID if info != None: if overwrite == True: #replace the photo return self._replace_photo(LUID, uploadInfo) else: #Only upload the photo if it is newer than the Remote one url = self._get_raw_photo_url(info) remoteFile = File.File(url) #this is a limited test for equality type comparison comp = photo.compare(remoteFile, True) log.debug( "Compared %s with %s to check if they are the same (size). Result = %s" % (photo.get_filename(), remoteFile.get_filename(), comp)) if comp != conduit.datatypes.COMPARISON_EQUAL: raise Exceptions.SynchronizeConflictError( comp, photo, remoteFile) else: return conduit.datatypes.Rid(uid=LUID) log.debug( "Uploading Photo URI = %s, Mimetype = %s, Original Name = %s" % (photoURI, mimeType, originalName)) #upload the file return self._upload_photo(uploadInfo)
def put(self, obj, overwrite, LUID=None): DataProvider.TwoWay.put(self, obj, overwrite, LUID) existing = None if LUID != None: existing = self.get(LUID) if existing != None: comp = obj.compare(existing) if comp == conduit.datatypes.COMPARISON_EQUAL: log.info("objects are equal") elif overwrite == True or comp == conduit.datatypes.COMPARISON_NEWER: self.update(LUID, obj) else: raise Exceptions.SynchronizeConflictError(comp, obj, existing) else: LUID = self.add(obj) return self.get(LUID).get_rid()
def put(self, photo, overwrite, LUID=None): """ Accepts a vfs file. Must be made local. I also store a md5 of the photos uri to check for duplicates """ DataProvider.DataSink.put(self, photo, overwrite, LUID) originalName = photo.get_filename() #Gets the local URI (/foo/bar). If this is a remote file then #it is first transferred to the local filesystem photoURI = photo.get_local_uri() mimeType = photo.get_mimetype() tags = photo.get_tags() caption = photo.get_caption() uploadInfo = UploadInfo(photoURI, mimeType, originalName, tags, caption) if overwrite and LUID: rid = self._replace_photo(LUID, uploadInfo) else: if LUID and self._get_photo_info(LUID): remotePhoto = self.get(LUID) comp = photo.compare(remotePhoto, False) log.debug( "Compared %s with %s. Result = %s" % (photo.get_filename(), remotePhoto.get_filename(), comp)) if LUID != None and comp == conduit.datatypes.COMPARISON_NEWER: rid = self._replace_photo(LUID, uploadInfo) elif comp == conduit.datatypes.COMPARISON_EQUAL: rid = remotePhoto.get_rid() else: raise Exceptions.SynchronizeConflictError( comp, photo, remotePhoto) else: log.debug( "Uploading Photo URI = %s, Mimetype = %s, Original Name = %s" % (photoURI, mimeType, originalName)) rid = self._upload_photo(uploadInfo) if not rid: raise Exceptions.SyncronizeError("Error putting/updating photo") else: return rid
def put(self, file, overwrite, LUID=None): """ Puts the file in the sink, this uploads the file if it is not present yet or updates it if necessary """ DataProvider.TwoWay.put(self, file, overwrite, LUID) originalName = file.get_filename() #Gets the local URI (/foo/bar). If this is a remote file then #it is first transferred to the local filesystem fileURI = file.get_local_uri() mimeType = file.get_mimetype() if LUID == None: log.debug( "Uploading file URI = %s, Mimetype = %s, Original Name = %s" % (fileURI, mimeType, originalName)) LUID = self._upload_file(fileURI, originalName) else: #check if a file exists at that UID id = self._get_file_info(LUID) if id != None: if overwrite == True: log.debug( "Replacing file URI = %s, Mimetype = %s, Original Name = %s" % (fileURI, mimeType, originalName)) LUID = self._replace_file(LUID, fileURI, originalName) else: #Only upload the file if it is newer than the Remote one url = self._get_raw_file_url(id) remoteFile = File.File(url) #this is a limited test for equality type comparison comp = file.compare(remoteFile, True) log.debug( "Compared %s with %s to check if they are the same (size). Result = %s" % (file.get_filename(), remoteFile.get_filename(), comp)) if comp != conduit.datatypes.COMPARISON_EQUAL: raise Exceptions.SynchronizeConflictError( comp, file, remoteFile) return self.get(LUID).get_rid()
def put(self, vfsFile, overwrite, LUID=None): """ Puts vfsFile at the correct location. There are three scenarios 1) File came from a foreign DP like tomboy 2) File came from another file dp Behaviour: 1) The foreign DP should have encoded enough information (such as the filename) so that we can go ahead and put the file in the dir 2) First we see if the file has a group attribute. a) If so, and the group matches the groupName here then we put the files into the directory. b) If not we put the file in a subdir by the name of the group We always retain the relative path for the files """ DataProvider.TwoWay.put(self, vfsFile, overwrite, LUID) newURI = "" if LUID != None: newURI = LUID elif vfsFile.basePath == "": #came from another type of dataprovider such as tomboy #where relative path makes no sense. Could also come from #the FileSource dp when the user has selected a single file log.debug("No basepath. Going to empty dir") newURI = Vfs.uri_join(self.folder, vfsFile.get_filename()) else: #Look for corresponding groups relpath = vfsFile.get_relative_uri() log.debug("Relative path: %s" % relpath) if self.folderGroupName == vfsFile.group: log.debug("Found corresponding group") #put in the folder newURI = Vfs.uri_join(self.folder, relpath) else: log.debug("Recreating group: %s" % vfsFile.group) #unknown. Store in the dir but recreate the group newURI = Vfs.uri_join(self.folder, vfsFile.group, relpath) #escape illegal filesystem characters if self.fstype: newURI = Vfs.uri_sanitize_for_filesystem(newURI, self.fstype) #overwrite is the easy case, as for it to be true, requires specific user #interaction if overwrite == True: self._transfer_file(vfsFile, newURI, overwrite) else: #check for conflicts destFile = File.File(URI=newURI) if destFile.exists(): comp = vfsFile.compare(destFile, sizeOnly=self.compareIgnoreMtime) if LUID != None and comp == DataType.COMPARISON_NEWER: #we were expecting an existing file, we found it, but #we are newer, so overwrite it self._transfer_file(vfsFile, newURI, True) elif comp == DataType.COMPARISON_EQUAL: #in File.compare, the files are compared based on size, if #their mtimes are the same, so this case is true when # 1) The sizes are the same, and the user told us # to ignore the mtimes # 2) The mtimes and size is the same, and we checked both pass else: raise Exceptions.SynchronizeConflictError( comp, vfsFile, destFile) else: self._transfer_file(vfsFile, newURI, overwrite) return self.get(newURI).get_rid()