tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

generate_yaml.py (2191B)


      1 #!/usr/bin/env python3
      2 # This Source Code Form is subject to the terms of the Mozilla Public
      3 # License, v. 2.0. If a copy of the MPL was not distributed with this
      4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
      5 
      6 import sys
      7 
      8 import yaml
      9 from mozshellutil import quote as shellquote
     10 from vsdownload import (
     11    getArgsParser,
     12    getManifest,
     13    getPackages,
     14    getSelectedPackages,
     15    lowercaseIgnores,
     16    setPackageSelection,
     17 )
     18 
     19 if __name__ == "__main__":
     20    parser = getArgsParser()
     21    parser.add_argument("-o", dest="output", required=True, help="Output file")
     22    parser.add_argument(
     23        "--exclude", default=[], nargs="+", help="Patterns of file names to exclude"
     24    )
     25    args = parser.parse_args()
     26    lowercaseIgnores(args)
     27 
     28    packages = getPackages(getManifest(args), "x64")
     29    setPackageSelection(args, packages)
     30    selected = getSelectedPackages(packages, args)
     31    reduced = []
     32    # Filter-out data we won't be using.
     33    for s in selected:
     34        type = s["type"]
     35        if type in {"Component", "Workload", "Group"}:
     36            continue
     37        if type == "Vsix" or s["id"].startswith(("Win10SDK", "Win11SDK")):
     38            filtered = {k: v for k, v in s.items() if k in ("type", "id", "version")}
     39            filtered["payloads"] = [
     40                {
     41                    k: v
     42                    for k, v in payload.items()
     43                    if k in ("fileName", "sha256", "size", "url")
     44                }
     45                for payload in s["payloads"]
     46                if payload["fileName"].endswith((".cab", ".msi", ".vsix"))
     47                and not any(e in payload["fileName"] for e in args.exclude)
     48            ]
     49            reduced.append(filtered)
     50    with open(args.output, "w", newline="\n") as out:
     51        print("# Generated with:", file=out)
     52        print(
     53            "# ./mach python --virtualenv build build/vs/generate_yaml.py \\", file=out
     54        )
     55        for i, arg_ in enumerate(sys.argv[1:]):
     56            arg = shellquote(arg_)
     57            if i < len(sys.argv) - 2:
     58                print("#  ", arg, "\\", file=out)
     59            else:
     60                print("#  ", arg, file=out)
     61        print(yaml.dump(reduced), file=out)