Skip to content

Commit

Permalink
feat: add option to invert the output
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomoferretti committed Nov 7, 2024
1 parent 5de158d commit 78a0d7b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
31 changes: 22 additions & 9 deletions android_git_scanner/commands/odex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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=(",", ":"))
31 changes: 22 additions & 9 deletions android_git_scanner/commands/vdex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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=(",", ":"))

0 comments on commit 78a0d7b

Please sign in to comment.