| 15 | |
| 16 | |
| 17 | def init(borders_path=None): |
| 18 | data_path = find_data_files("omim-data") |
| 19 | |
| 20 | if data_path is None: |
| 21 | logger.error("omim-data was not found.") |
| 22 | return False |
| 23 | |
| 24 | if borders_path is None: |
| 25 | borders_path = os.path.join(data_path, "borders") |
| 26 | |
| 27 | if not os.path.exists(borders_path): |
| 28 | tar_lzma_path = os.path.join(data_path, "borders.tar.xz") |
| 29 | lzma_stream = BytesIO() |
| 30 | with open(tar_lzma_path, mode="rb") as f: |
| 31 | decompressed = lzma.decompress(f.read()) |
| 32 | lzma_stream.write(decompressed) |
| 33 | |
| 34 | lzma_stream.seek(0) |
| 35 | try: |
| 36 | with tarfile.open(fileobj=lzma_stream, mode="r") as tar: |
| 37 | tar.extractall(borders_path) |
| 38 | except PermissionError as e: |
| 39 | logger.error(str(e)) |
| 40 | return False |
| 41 | |
| 42 | logger.info("{} was created.".format(borders_path)) |
| 43 | |
| 44 | return True |