def unpack_mobi(self, filename): storage_area = self.get_mobi_storage_area() filemd5 = generate_file_md5(filename) for fname in storage_area.iterdir(): if fname.is_file() and (fname.stem == filemd5): return str(fname) with mute_stdout(): tempdir, extracted_file = mobi.extract(str(filename)) filetype = Path(extracted_file).suffix.strip(".") if filetype == "html": return self.create_valid_epub_from_epub_like_structure( tempdir, storage_area.joinpath(f"{filemd5}.epub")) dst_filename = storage_area.joinpath(f"{filemd5}.{filetype}") shutil.copy(extracted_file, dst_filename) TemporaryDirectory._rmtree(tempdir) return dst_filename
def get_tmp_dir() -> str: """ Get a temporary directory. Returns ------- path: Directory path. """ path = Path(gettempdir()).joinpath("wendigo") if path.exists(): # Delete sub directories. # Directories which were used by other applications such as Tesseract remain. for p in glob(str(path.joinpath("*"))): TemporaryDirectory._rmtree(p) else: path.mkdir(exist_ok=True) return str(path)