| 1 |
|
| 2 |
|
| 3 |
if __name__ != "__main__": |
| 4 |
raise SystemExit(f'Utility script "{__file__}" should not be used as a module!') |
| 5 |
|
| 6 |
import argparse |
| 7 |
import sys |
| 8 |
|
| 9 |
import xmlschema |
| 10 |
|
| 11 |
sys.path.insert(0, "./") |
| 12 |
|
| 13 |
try: |
| 14 |
from methods import print_error |
| 15 |
except ImportError: |
| 16 |
raise SystemExit(f"Utility script {__file__} must be run from repository root!") |
| 17 |
|
| 18 |
|
| 19 |
def main(): |
| 20 |
parser = argparse.ArgumentParser(description="Validate XML documents against `doc/class.xsd`") |
| 21 |
parser.add_argument("files", nargs="+", help="A list of XML files to parse") |
| 22 |
args = parser.parse_args() |
| 23 |
|
| 24 |
SCHEMA = xmlschema.XMLSchema("doc/class.xsd") |
| 25 |
ret = 0 |
| 26 |
|
| 27 |
for file in args.files: |
| 28 |
try: |
| 29 |
SCHEMA.validate(file) |
| 30 |
except xmlschema.validators.exceptions.XMLSchemaValidationError as err: |
| 31 |
print_error(f'Validation failed for "{file}"!\n\n{err}') |
| 32 |
ret += 1 |
| 33 |
|
| 34 |
return ret |
| 35 |
|
| 36 |
|
| 37 |
try: |
| 38 |
raise SystemExit(main()) |
| 39 |
except KeyboardInterrupt: |
| 40 |
import os |
| 41 |
import signal |
| 42 |
|
| 43 |
signal.signal(signal.SIGINT, signal.SIG_DFL) |
| 44 |
os.kill(os.getpid(), signal.SIGINT) |