def copyValueFile(self, **kwargs): """Duplicate file value on filesystem""" src_path = self.getValueFilePath(uid=kwargs['src_uid'], path=kwargs['src_path'], name=kwargs['name'], title=kwargs.get('title', '')) if not os.path.exists(src_path): return name = kwargs['name'] path = self.getValueDirectoryPath(**kwargs) # Process new filename filename = self.getValueFilename(**kwargs) # Update config file self.createSubDirectories(path, self.storage_path) self.setFilenameInConfigFile(path, name, filename) # Then copy file dst_path = self.getValueFilePath(**kwargs) copy_file(src_path, dst_path) return
def setRDFFile(self, value, **kwargs): """Copy rdf file on filesystem""" # Put value in buffer buffer = StringIO(value) copy_file(buffer, self.getRDFFilePath(**kwargs)) buffer.close()
def copyValueFile(self, **kwargs): """Duplicate file value on filesystem""" src_path = self.getValueFilePath(uid=kwargs['src_uid'], name=kwargs['name']) if not os.path.exists(src_path): return dst_path = self.getValueFilePath(**kwargs) copy_file(src_path, dst_path)
def setData(self, value): """ @param : value """ if type(value) is StringType: value = cStringIO.StringIO(value) if hasattr(value, 'read') and hasattr(value, 'seek'): value.seek(0, 0) copy_file(value, self.path) else: raise ValueError('%s is not a file' % type(value))
def setData(self, value): """ @param : value """ if type(value) is StringType: value = cStringIO.StringIO(value) if hasattr(value, 'read') and hasattr(value, 'seek'): value.seek(0,0) copy_file(value, self.path) else: raise ValueError('%s is not a file' % type(value))
def copyValueFile(self, **kwargs): """Duplicate file value on filesystem""" src_path = self.getValueFilePath(uid=kwargs['src_uid'], path=kwargs['src_path'], name=kwargs['name'], title=kwargs.get('title', '')) if not os.path.exists(src_path): return dst_path = self.getValueFilePath(**kwargs) self.createSubDirectories(self.getValueDirectoryPath(**kwargs), self.storage_path) copy_file(src_path, dst_path)
def setValueFile(self, value, **kwargs): """Copy file value on filesystem""" # Put value in buffer buffer = value if type(value) is type(''): # Put value in buffer buffer = StringIO(value) if hasattr(buffer, 'read') and hasattr(buffer, 'seek'): copy_file(buffer, self.getValueFilePath(**kwargs)) else: raise ValueError('%s is not a file' % type(buffer))
def set(self, name, instance, value, **kwargs): """Set value of a field""" # Ignore initialize process initializing = kwargs.get('_initializing_', False) if initializing: return # Remove acquisition wrappers value = aq_base(value) # Create File System Storage Info info = self.setFSSInfo(name, instance, value, **kwargs) # Wrap value if objectImplements(IObjectField, value): value = value.getRaw(self.instance) if objectImplements(IBaseUnit, value): value = value.getRaw() elif isinstance(value, File): value = value.data else: value = str(value) # Copy file on filesystem strategy = self.getStorageStrategy(name, instance) props = self.getStorageStrategyProperties(name, instance, info) if isinstance(value, FSSPdata): ## put all in temporory file fd, pathtemp = tempfile.mkstemp(prefix="tempfss") copy_file(value, pathtemp) value = filestream_iterator(pathtemp, mode='rb') strategy.setValueFile(value, **props) value.close() os.close(fd) rm_file(pathtemp) elif isinstance(value, Pdata): fd, pathtemp = tempfile.mkstemp(prefix="tempfss") f = open(pathtemp, 'wb') data = value while data is not None: f.write(data.data) data = data.next f.seek(0, 0) f.close() f = open(pathtemp, 'rb') strategy.setValueFile(f, **props) f.close() os.close(fd) rm_file(pathtemp) else: strategy.setValueFile(value, **props) # Create RDF file conf = self.getConf() is_rdf_enabled = conf.isRDFEnabled() rdf_script = conf.getRDFScript() if is_rdf_enabled: # Replace rdf file rdf_value = info.getRDFValue(name, instance, rdf_script) strategy.setRDFFile(rdf_value, **props)
def set(self, name, instance, value, **kwargs): """Set value of a field""" # Ignore initialize process initializing = kwargs.get('_initializing_', False) if initializing: return # Remove acquisition wrappers value = aq_base(value) # Create File System Storage Info info = self.setFSSInfo(name, instance, value, **kwargs) # Wrap value if objectImplements(IObjectField, value): value = value.getRaw(self.instance) if objectImplements(IBaseUnit, value): value = value.getRaw() elif isinstance(value, File): value = value.data else: value = str(value) # Copy file on filesystem strategy = self.getStorageStrategy(name, instance) props = self.getStorageStrategyProperties(name, instance, info) if isinstance(value, FSSPdata): ## put all in temporory file fd, pathtemp = tempfile.mkstemp(prefix="tempfss") copy_file(value, pathtemp) value = filestream_iterator(pathtemp, mode='rb') strategy.setValueFile(value, **props) value.close() os.close(fd) rm_file(pathtemp) elif isinstance(value, Pdata): fd, pathtemp = tempfile.mkstemp(prefix="tempfss") f = open(pathtemp,'wb') data = value while data is not None: f.write(data.data) data = data.next f.seek(0, 0) f.close() f = open(pathtemp,'rb') strategy.setValueFile(f, **props) f.close() os.close(fd) rm_file(pathtemp) else: strategy.setValueFile(value, **props) # Create RDF file conf = self.getConf() is_rdf_enabled = conf.isRDFEnabled() rdf_script = conf.getRDFScript() if is_rdf_enabled: # Replace rdf file rdf_value = info.getRDFValue(name, instance, rdf_script) strategy.setRDFFile(rdf_value, **props)