Created
May 6, 2020 12:43
-
-
Save mjeveritt/d11242515d466a6d53456d3d0e7bef40 to your computer and use it in GitHub Desktop.
Bug 705976 - Add JSON/YAML version of 'Packages' index file for easier machine parsing
This file contains 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
#!/usr/bin/env python3 | |
import argparse | |
import json | |
import sys | |
from portage.getbinpkg import PackageIndex | |
def main(): | |
parser = argparse.ArgumentParser(description='convert ${PKGDIR}/Packages file to JSON') | |
parser.add_argument('input_file', default='-', nargs='?', help='default is stdin') | |
args = parser.parse_args() | |
pkgindex = PackageIndex() | |
packages_json = {} | |
if args.input_file == '-': | |
pkgindex.read(sys.stdin) | |
else: | |
with open(args.input_file, 'rt', encoding='utf8') as input_file: | |
pkgindex.read(input_file) | |
packages_json['header'] = pkgindex.header | |
packages_json['packages'] = pkgindex.packages | |
json.dump(packages_json, sys.stdout) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment