def __init__(self, uncompressed_max_bytes=30 * MiB, compressed_max_bytes=20 * MiB): self.uncompressed_max_bytes = uncompressed_max_bytes self.compressed_max_bytes = compressed_max_bytes # Note: We use dulwich's LRU cache to store the tagsfile paths here, # but we could easily replace it by any other (LRU) cache implementation. self._uncompressed_cache = LRUSizeCache(uncompressed_max_bytes, compute_size=os.path.getsize) self._compressed_cache = LRUSizeCache(compressed_max_bytes, compute_size=os.path.getsize) self._clearing = False self._lock = threading.Lock()
def __init__(self, scon, filename): """ Initialize a SwiftPackReader :param scon: a `SwiftConnector` instance :param filename: the pack filename """ self.scon = scon self._filename = filename self._header_size = 12 headers = self.scon.get_object_stat(self._filename) self.pack_length = int(headers['content-length']) pack_reader = SwiftPackReader(self.scon, self._filename, self.pack_length) (version, self._num_objects) = read_pack_header(pack_reader.read) self._offset_cache = LRUSizeCache(1024*1024*self.scon.cache_length, compute_size=_compute_object_size) self.pack = None
def __init__(self, filename): """Create a PackData object that represents the pack in the given filename. The file must exist and stay readable until the object is disposed of. It must also stay the same size. It will be mapped whenever needed. Currently there is a restriction on the size of the pack as the python mmap implementation is flawed. """ self._filename = filename assert os.path.exists(filename), "%s is not a packfile" % filename self._size = os.path.getsize(filename) self._header_size = 12 assert self._size >= self._header_size, "%s is too small for a packfile (%d < %d)" % ( filename, self._size, self._header_size) self._file = open(self._filename, 'rb') self._read_header() self._offset_cache = LRUSizeCache(1024 * 1024 * 20, compute_size=_compute_object_size)