Ejemplo n.º 1
0
class Store(object):
    """Store.
       Required constructor parameters: path, block_size, hash_algorithm,
       umask, blockpool, mappool.
    """
    def __init__(self, **params):
        umask = params['umask']
        if umask is not None:
            os.umask(umask)

        path = params['path']
        if path and not os.path.exists(path):
            os.makedirs(path)
        if not os.path.isdir(path):
            raise RuntimeError("Cannot open path '%s'" % (path, ))

        p = {
            'blocksize': params['block_size'],
            'blockpath': os.path.join(path + '/blocks'),
            'hashtype': params['hash_algorithm'],
            'blockpool': params['blockpool']
        }
        self.blocker = Blocker(**p)
        p = {
            'mappath': os.path.join(path + '/maps'),
            'namelen': self.blocker.hashlen,
            'mappool': params['mappool']
        }
        self.mapper = Mapper(**p)

    def map_get(self, name):
        return self.mapper.map_retr(name)

    def map_put(self, name, map):
        self.mapper.map_stor(name, map)

    def map_delete(self, name):
        pass

    def block_get(self, hash):
        blocks = self.blocker.block_retr((hash, ))
        if not blocks:
            return None
        return blocks[0]

    def block_put(self, data):
        hashes, absent = self.blocker.block_stor((data, ))
        return hashes[0]

    def block_update(self, hash, offset, data):
        h, e = self.blocker.block_delta(hash, offset, data)
        return h

    def block_search(self, map):
        return self.blocker.block_ping(map)
Ejemplo n.º 2
0
class Store(object):
    """Store.
       Required constructor parameters: path, block_size, hash_algorithm,
       blockpool, mappool.
    """

    def __init__(self, **params):
        pb = {'blocksize': params['block_size'],
              'hashtype': params['hash_algorithm'],
              'archipelago_cfile': params['archipelago_cfile'],
              }
        self.blocker = Blocker(**pb)
        pm = {'namelen': self.blocker.hashlen,
              'hashtype': params['hash_algorithm'],
              'archipelago_cfile': params['archipelago_cfile'],
              }
        self.mapper = Mapper(**pm)

    def map_get(self, name, size):
        return self.mapper.map_retr(name, size)

    def map_put(self, name, map, size, block_size):
        self.mapper.map_stor(name, map, size, block_size)

    def map_delete(self, name):
        pass

    def map_copy(self, dst, src, size):
        self.mapper.map_copy(dst, src, size)

    def block_get(self, hash):
        blocks = self.blocker.block_retr((hash,))
        if not blocks:
            return None
        return blocks[0]

    def block_get_archipelago(self, hash):
        blocks = self.blocker.block_retr_archipelago((hash,))
        if not blocks:
            return None
        return blocks[0]

    def block_put(self, data):
        hashes, absent = self.blocker.block_stor((data,))
        return hashes[0]

    def block_update(self, hash, offset, data):
        h, e = self.blocker.block_delta(hash, offset, data)
        return h

    def block_search(self, map):
        return self.blocker.block_ping(map)
Ejemplo n.º 3
0
class Store(object):
    """Store.
       Required constructor parameters: path, block_size, hash_algorithm,
       umask, blockpool, mappool.
    """

    def __init__(self, **params):
        umask = params['umask']
        if umask is not None:
            os.umask(umask)

        path = params['path']
        if path and not os.path.exists(path):
            os.makedirs(path)
        if not os.path.isdir(path):
            raise RuntimeError("Cannot open path '%s'" % (path,))

        p = {'blocksize': params['block_size'],
             'blockpath': os.path.join(path + '/blocks'),
             'hashtype': params['hash_algorithm'],
             'blockpool': params['blockpool']}
        self.blocker = Blocker(**p)
        p = {'mappath': os.path.join(path + '/maps'),
             'namelen': self.blocker.hashlen,
             'mappool': params['mappool']}
        self.mapper = Mapper(**p)

    def map_get(self, name):
        return self.mapper.map_retr(name)

    def map_put(self, name, map):
        self.mapper.map_stor(name, map)

    def map_delete(self, name):
        pass

    def block_get(self, hash):
        blocks = self.blocker.block_retr((hash,))
        if not blocks:
            return None
        return blocks[0]

    def block_put(self, data):
        hashes, absent = self.blocker.block_stor((data,))
        return hashes[0]

    def block_update(self, hash, offset, data):
        h, e = self.blocker.block_delta(hash, offset, data)
        return h

    def block_search(self, map):
        return self.blocker.block_ping(map)
Ejemplo n.º 4
0
class Store(object):
    """Store.
       Required constructor parameters: block_size, hash_algorithm,
                                        archipelago_cfile, namelen
    """
    def __init__(self, **params):
        pb = {
            'blocksize': params['block_size'],
            'hashtype': params['hash_algorithm'],
            'archipelago_cfile': params['archipelago_cfile'],
        }
        self.blocker = Blocker(**pb)
        pm = {
            'namelen': self.blocker.hashlen,
            'archipelago_cfile': params['archipelago_cfile'],
        }
        self.mapper = Mapper(**pm)

    def map_get(self, name, size):
        return self.mapper.map_retr(name, size)

    def map_put(self, name, map, size, block_size):
        self.mapper.map_stor(name, map, size, block_size)

    def map_delete(self, name):
        pass

    def block_get(self, hash):
        blocks = self.blocker.block_retr((hash, ))
        if not blocks:
            return None
        return blocks[0]

    def block_get_archipelago(self, hash):
        blocks = self.blocker.block_retr_archipelago((hash, ))
        if not blocks:
            return None
        return blocks[0]

    def block_put(self, data):
        hashes, absent = self.blocker.block_stor((data, ))
        return hashes[0]

    def block_update(self, hash, offset, data):
        h, e = self.blocker.block_delta(hash, offset, data)
        return h

    def block_search(self, map):
        return self.blocker.block_ping(map)
Ejemplo n.º 5
0
class Store(object):
    """Store.
       Required constructor parameters: path, block_size, hash_algorithm,
       umask, blockpool, mappool.
    """

    def __init__(self, **params):
        (pb, pm) = bootstrap_backend_storage(**params)
        self.blocker = Blocker(**pb)
        self.mapper = Mapper(**pm)

    def map_get(self, name):
        return self.mapper.map_retr(name)

    def map_put(self, name, map):
        self.mapper.map_stor(name, map)

    def map_delete(self, name):
        pass

    def block_get(self, hash):
        blocks = self.blocker.block_retr((hash,))
        if not blocks:
            return None
        return blocks[0]

    def block_put(self, data):
        hashes, absent = self.blocker.block_stor((data,))
        return hashes[0]

    def block_update(self, hash, offset, data):
        h, e = self.blocker.block_delta(hash, offset, data)
        return h

    def block_search(self, map):
        return self.blocker.block_ping(map)