Skip to content

Add better error checking to misc/convert-cache.py #14909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion misc/convert-cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from __future__ import annotations

import os
import re
import sys

sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
Expand Down Expand Up @@ -36,15 +37,23 @@ def main() -> None:

input_dir = args.input_dir
output_dir = args.output_dir or input_dir
assert os.path.isdir(output_dir), f"{output_dir} is not a directory"
if args.to_sqlite:
input: MetadataStore = FilesystemMetadataStore(input_dir)
output: MetadataStore = SqliteMetadataStore(output_dir)
else:
fnam = os.path.join(input_dir, "cache.db")
msg = f"{fnam} does not exist"
if not re.match(r"[0-9]+\.[0-9]+$", os.path.basename(input_dir)):
msg += f" (are you missing Python version at the end, e.g. {input_dir}/3.11)"
assert os.path.isfile(fnam), msg
input, output = SqliteMetadataStore(input_dir), FilesystemMetadataStore(output_dir)

for s in input.list_all():
if s.endswith(".json"):
assert output.write(s, input.read(s), input.getmtime(s)), "Failed to write cache file!"
assert output.write(
s, input.read(s), input.getmtime(s)
), f"Failed to write cache file {s}!"
output.commit()


Expand Down