diff options
author | John Estabrook <jestabro@sentrium.io> | 2020-01-10 15:28:03 -0600 |
---|---|---|
committer | John Estabrook <jestabro@sentrium.io> | 2020-01-13 12:51:29 -0600 |
commit | 0ecc2c26f7ac939e4e23c14f5027ac7592c25761 (patch) | |
tree | 3a13d38f65a358252c69c5b2ea01aee189b1e412 /scripts/build-component-versions | |
parent | 5849ba88a1a20e4d3584843e0be46e456c5f7980 (diff) | |
download | vyos-1x-0ecc2c26f7ac939e4e23c14f5027ac7592c25761.tar.gz vyos-1x-0ecc2c26f7ac939e4e23c14f5027ac7592c25761.zip |
xml: T1962: Add script to process syntaxVersion tags during build
Diffstat (limited to 'scripts/build-component-versions')
-rwxr-xr-x | scripts/build-component-versions | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/scripts/build-component-versions b/scripts/build-component-versions new file mode 100755 index 000000000..5362dbdd4 --- /dev/null +++ b/scripts/build-component-versions @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +import sys +import os +import argparse +import json + +from lxml import etree as ET + +parser = argparse.ArgumentParser() +parser.add_argument('INPUT_DIR', type=str, + help="Directory containing XML interface definition files") +parser.add_argument('OUTPUT_DIR', type=str, + help="Output directory for JSON file") + +args = parser.parse_args() + +input_dir = args.INPUT_DIR +output_dir = args.OUTPUT_DIR + +version_dict = {} + +for filename in os.listdir(input_dir): + filepath = os.path.join(input_dir, filename) + print(filepath) + try: + xml = ET.parse(filepath) + except Exception as e: + print("Failed to load interface definition file {0}".format(filename)) + print(e) + sys.exit(1) + + root = xml.getroot() + version_data = root.iterfind("syntaxVersion") + for ver in version_data: + component = ver.get("component") + version = int(ver.get("version")) + + v = version_dict.get(component) + if v is None: + version_dict[component] = version + elif version > v: + version_dict[component] = version + +out_file = os.path.join(output_dir, 'component-versions.json') +with open(out_file, 'w') as f: + json.dump(version_dict, f, indent=4, sort_keys=True) |