Last active
June 3, 2021 05:43
-
-
Save Neradoc/8b5819a9aebf85f6f9824037b184968b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Slightly over-engineered script to filter the versions on circuitpython.org | |
Prints out information to stderr while the resulting json file is printed to stdout | |
Run with: | |
python3 filter_cpyorg_version.py path/circuitpython-org.git/_data/files.json > new-files.json | |
Then replace the file and compare with: | |
git diff --diff-algorithm=histogram | |
""" | |
import click | |
import json | |
import pprint | |
import sys | |
@click.group(invoke_without_command=True) | |
@click.argument("file_path", nargs=1) | |
@click.option( | |
"--keep", | |
default = "", | |
help="Coma separated version(s) to keep.", | |
) | |
@click.option( | |
"--clear", | |
default = "", | |
help="Coma separated version(s) to remove.", | |
) | |
def main(file_path, keep, clear): | |
if keep: | |
keep = keep.split(",") | |
if clear: | |
clear = clear.split(",") | |
print(file_path, file=sys.stderr) | |
with open(file_path,"r") as fp: | |
data_in = json.load(fp) | |
data_out = [] | |
for board in data_in: | |
versions_out = [] | |
for version_in in board["versions"]: | |
info = board["id"] + " " + version_in["version"] | |
if clear and version_in["version"] in clear: | |
click.secho("clear: " + info, err=True, fg="yellow") | |
continue | |
if keep and version_in["version"] not in keep: | |
click.secho("no keep: " + info, err=True, fg="yellow") | |
continue | |
click.secho("include: " + info, err=True, fg="green") | |
versions_out += [version_in] | |
if len(versions_out) == 0: | |
click.secho("NO VERSION FOR: " + board["id"], err=True, fg="red") | |
board["versions"] = versions_out | |
data_out.append(board) | |
print(json.dumps(data_out, indent=1)) | |
if __name__ == "__main__": # pragma: no cover | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment