()
| 20 | |
| 21 | |
| 22 | def main() -> None: |
| 23 | parser = argparse.ArgumentParser() |
| 24 | parser.add_argument( |
| 25 | "--to-sqlite", |
| 26 | action="store_true", |
| 27 | default=False, |
| 28 | help="Convert to a sqlite cache (default: convert from)", |
| 29 | ) |
| 30 | parser.add_argument( |
| 31 | "--num-shards", |
| 32 | type=int, |
| 33 | default=SQLITE_NUM_SHARDS, |
| 34 | dest="num_shards", |
| 35 | help=argparse.SUPPRESS, |
| 36 | ) |
| 37 | parser.add_argument( |
| 38 | "--output_dir", |
| 39 | action="store", |
| 40 | default=None, |
| 41 | help="Output cache location (default: same as input)", |
| 42 | ) |
| 43 | parser.add_argument("input_dir", help="Input directory for the cache") |
| 44 | args = parser.parse_args() |
| 45 | |
| 46 | input_dir = args.input_dir |
| 47 | output_dir = args.output_dir or input_dir |
| 48 | num_shards = args.num_shards |
| 49 | assert os.path.isdir(output_dir), f"{output_dir} is not a directory" |
| 50 | if args.to_sqlite: |
| 51 | input: MetadataStore = FilesystemMetadataStore(input_dir) |
| 52 | output: MetadataStore = SqliteMetadataStore(output_dir, num_shards=num_shards) |
| 53 | else: |
| 54 | if num_shards <= 1: |
| 55 | db_files = [os.path.join(input_dir, "cache.db")] |
| 56 | else: |
| 57 | db_files = [os.path.join(input_dir, f"cache.{i}.db") for i in range(num_shards)] |
| 58 | for fnam in db_files: |
| 59 | msg = f"{fnam} does not exist" |
| 60 | if not re.match(r"[0-9]+\.[0-9]+$", os.path.basename(input_dir)): |
| 61 | msg += f" (are you missing Python version at the end, e.g. {input_dir}/3.11)" |
| 62 | assert os.path.isfile(fnam), msg |
| 63 | input = SqliteMetadataStore(input_dir, num_shards=num_shards) |
| 64 | output = FilesystemMetadataStore(output_dir) |
| 65 | |
| 66 | for s in input.list_all(): |
| 67 | if s.endswith((".json", ".ff")): |
| 68 | assert output.write( |
| 69 | s, input.read(s), input.getmtime(s) |
| 70 | ), f"Failed to write cache file {s}!" |
| 71 | output.commit() |
| 72 | |
| 73 | |
| 74 | if __name__ == "__main__": |
no test coverage detected
searching dependent graphs…