diff options
author | aqua <aqua@iserlohn-fortress.net> | 2022-09-22 22:07:28 +0300 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2022-09-23 09:58:14 +0300 |
commit | 52c7c9c032d547b957808d07f53f58ed247f924c (patch) | |
tree | fcc510b06bfc1d5012689f2596758624f2b8db41 /scripts | |
parent | BookmarksToolBar: elide action title (diff) | |
download | rekonq-52c7c9c032d547b957808d07f53f58ed247f924c.tar.xz |
Add validate_xml script
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/validate_xml.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/validate_xml.py b/scripts/validate_xml.py new file mode 100755 index 00000000..4f716d60 --- /dev/null +++ b/scripts/validate_xml.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +# ============================================================ +# The rekonq project +# ============================================================ +# SPDX-License-Identifier: GPL-3.0-only +# Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net> +# ============================================================ +""" Validate xml files """ + + +import argparse +import sys +from lxml import etree + + +def validate(xml_path: str, validator) -> bool: + ''' Load and validate file using lxml ''' + xml_doc = etree.parse(xml_path) + return validator.validate(xml_doc) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Validate xml files') + parser.add_argument('files', type=str, nargs='+', help='One or more files to validate') + parser.add_argument('--dtd', type=str, help='DTD') + args = parser.parse_args() + + validator = etree.DTD(args.dtd) + files_ok = True + for file in args.files: + if not validate(file, validator): + print(f'{file} failed validation') + files_ok = False + + if not files_ok: + sys.exit('validation failed') |