diff --git a/android_git_scanner/commands/odex.py b/android_git_scanner/commands/odex.py index e1f5a04..50d5078 100644 --- a/android_git_scanner/commands/odex.py +++ b/android_git_scanner/commands/odex.py @@ -54,7 +54,8 @@ def find_oat_version_file(commit: Commit): @click.command(name="oat") @click.argument("git-folder", type=click.Path(exists=True)) @click.option("--output", type=click.Path(), default="oat_versions.json") -def oat(git_folder, output): +@click.option("--invert", help="Invert the output", is_flag=True) +def oat(git_folder, output, invert): git_folder = pathlib.Path(git_folder) repo = Repo(git_folder) @@ -70,16 +71,28 @@ def oat(git_folder, output): if android_version_match: android_version, android_version_revision = android_version_match - if android_version not in android_versions: - android_versions[android_version] = set() + if invert: + if oat_version not in android_versions: + android_versions[oat_version] = set() - android_versions[android_version].add(oat_version) + android_versions[oat_version].add(android_version) + else: + if android_version not in android_versions: + android_versions[android_version] = set() + + android_versions[android_version].add(oat_version) with open(output, "w") as f: - output_data = dict( - (version, sorted(list(items))) - for version, items in sorted( - android_versions.items(), key=lambda x: parse(x[0]) + if invert: + output_data = dict( + (key, sorted(list(values), key=parse) if values else []) + for key, values in sorted(android_versions.items()) + ) + else: + output_data = dict( + (version, sorted(list(items))) + for version, items in sorted( + android_versions.items(), key=lambda x: parse(x[0]) + ) ) - ) json.dump(output_data, f, separators=(",", ":")) diff --git a/android_git_scanner/commands/vdex.py b/android_git_scanner/commands/vdex.py index 4036a54..8b10393 100644 --- a/android_git_scanner/commands/vdex.py +++ b/android_git_scanner/commands/vdex.py @@ -25,7 +25,8 @@ @click.command(name="vdex") @click.argument("git-folder", type=click.Path(exists=True)) @click.option("--output", type=click.Path(), default="vdex_versions.json") -def vdex(git_folder, output): +@click.option("--invert", help="Invert the output", is_flag=True) +def vdex(git_folder, output, invert): git_folder = pathlib.Path(git_folder) repo = Repo(git_folder) @@ -48,16 +49,28 @@ def vdex(git_folder, output): if android_version_match: android_version, android_version_revision = android_version_match - if android_version not in android_versions: - android_versions[android_version] = set() + if invert: + if vdex_version not in android_versions: + android_versions[vdex_version] = set() - android_versions[android_version].add(vdex_version) + android_versions[vdex_version].add(android_version) + else: + if android_version not in android_versions: + android_versions[android_version] = set() + + android_versions[android_version].add(vdex_version) with open(output, "w") as f: - output_data = dict( - (version, sorted(list(items))) - for version, items in sorted( - android_versions.items(), key=lambda x: parse(x[0]) + if invert: + output_data = dict( + (key, sorted(list(values), key=parse) if values else []) + for key, values in sorted(android_versions.items()) + ) + else: + output_data = dict( + (version, sorted(list(items))) + for version, items in sorted( + android_versions.items(), key=lambda x: parse(x[0]) + ) ) - ) json.dump(output_data, f, separators=(",", ":"))