Пример #1
0
 def __init__(self, name, parent=None):
     self.name = name
     self.parent = parent
     self.creationdate = datetime.datetime.now()
     self.lastmodified = self.creationdate
     self.identifier = uuid.uuid_str()
     if parent:
         parent.add(name, self)
Пример #2
0
    def store(self, data, id=None):
        # This is our master identifier. We are not going
        # to hash these large datas
        id = id or uuid.uuid_str()

        # HEADER + "\n"
        MAX_SIZE_LAST = self.blocksize - len(self.HEADER) - 1
        # HEADER + " single" + "\n"
        MAX_SIZE_SINGLE = MAX_SIZE_LAST - len(self.SINGLE)
        # HEADER + " next " + uuid + "\n"
        MAX_SIZE = MAX_SIZE_LAST - len(self.NEXT) - UUID_SIZE 

        # Special case, if the data fits in a single block, 
        # we'll pop it in there.
        if len(data) <= MAX_SIZE_SINGLE:
            block = "%s%s\n%s" % (self.HEADER, self.SINGLE, data)
            return self.backend.store(block, id)
            
         
        # Store the block list, we'll have to make sure the
        # block list itself is also split by blocksize
        block = ""
        block_id = id
        for next_id in self._store_blocks(data):
            if len(next_id)+len(block) > MAX_SIZE:
                # We can't include it, we have to store now
                next_block = uuid.uuid_str()
                # Note, block already starts with \n
                block = "%s%s%s%s" % (self.HEADER, self.NEXT, next_block, block)
                assert len(block) <= self.blocksize
                self.backend.store(block, block_id)     
                block = ""
                block_id = next_block
            block += "\n" + next_id
        
        if block:
            block = "%s%s" % (self.HEADER, block)              
            self.backend.store(block, block_id)

        # Return the master identifier
        return id      
Пример #3
0
import os
from sha import sha
import tempfile
import uuid

UUID_SIZE = len(uuid.uuid_str())
 
class error(Exception):
    """BlockStore error"""

class FilestoreError(error):    
    """File store error"""

class NotAFilestore(FilestoreError):
    """Not a file store"""

class FilestoreUnknownVersion(FilestoreError):
    """Unknown version of file store"""

class FileIOError(FilestoreError):
    """Could not read/write"""

class NotFoundError(KeyError, error):
    """Block not found"""

class AlreadyExistsError(KeyError, error):
    """Block with explicit id already exist"""    


class Store(object):