Пример #1
0
    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
Пример #2
0
    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()
Пример #3
0
    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()
Пример #4
0
    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)
Пример #5
0
 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))
Пример #6
0
 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))
Пример #7
0
    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)
Пример #8
0
    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)
Пример #9
0
    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))
Пример #10
0
    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))
Пример #11
0
    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)
Пример #12
0
    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
Пример #13
0
    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)
Пример #14
0
    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)