def _internal_load_key(self, path, key): key = self._metadata_rewrites.get(key, key) if key == "contents": data = ContentsFile(pjoin(path, "CONTENTS"), mutable=True) elif key == "environment": fp = pjoin(path, key) if not os.path.exists(fp + ".bz2"): if not os.path.exists(fp): # icky. raise KeyError("environment: no environment file found") data = data_source.local_source(fp) else: data = data_source.bz2_source(fp + ".bz2") elif key == "ebuild": fp = pjoin(path, os.path.basename(path.rstrip(os.path.sep)) + ".ebuild") data = data_source.local_source(fp) elif key == 'repo': # try both, for portage/paludis compatibility. data = readfile(pjoin(path, 'repository'), True) if data is None: data = readfile(pjoin(path, 'REPOSITORY'), True) if data is None: raise KeyError(key) else: data = readfile(pjoin(path, key), True) if data is None: raise KeyError((path, key)) return data
def get_obj(self, data="foonani", mutable=False, test_creation=False): self.fp = pjoin(self.dir, "bz2source.test.bz2") if not test_creation: if isinstance(data, str): data = data.encode() with open(self.fp, 'wb') as f: f.write(compression.compress_data('bzip2', data)) return data_source.bz2_source(self.fp, mutable=mutable)
def test_transfer_to_path(self): data = self._mk_data() reader = self.get_obj(data=data) if isinstance(reader, data_source.bz2_source): writer = data_source.bz2_source(pjoin(self.dir, 'transfer_to_path'), mutable=True) else: writer = data_source.local_source(pjoin(self.dir, 'transfer_to_path'), mutable=True) reader.transfer_to_path(writer.path) self.assertContents(reader, writer)