forked from notepad-plus-plus/userDefinedLanguages
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator_xml.py
79 lines (57 loc) · 1.87 KB
/
validator_xml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/local/bin/python3
import os
import io
import sys
import requests
from hashlib import sha256
from lxml import etree
api_url = os.environ.get('APPVEYOR_API_URL')
has_error = False
def post_error(message):
global has_error
has_error = True
message = {
"message": message,
"category": "error",
"details": ""
}
if api_url:
requests.post(api_url + "api/build/messages", json=message)
else:
from pprint import pprint
pprint(message)
def parse_xml_file(filename_xml):
# open and read schema file
#with open(filename_xsd, 'r') as schema_file:
#schema_to_check = schema_file.read()
# parse xml
try:
doc = etree.parse(filename_xml)
#print(f'{filename_xml} XML well formed, syntax ok.')
# check for file IO error
except IOError:
#print('Invalid File')
post_error(f'{filename_xml}: IOError Invalid File')
# check for XML syntax errors
except etree.XMLSyntaxError as err:
#print('XML Syntax Error, see error_syntax.log')
post_error(f'{filename_xml}: {str(err.error_log)}: XMLSyntaxError Invalid File')
except:
#print('Unknown error.')
post_error(f'{filename_xml}: Unknown error. Maybe check that no xml version is in the first line.')
def parse_xml_files_from_udls_dir():
for file in os.listdir("UDLs"):
if file.endswith(".xml"):
#print(os.path.join("UDLs", file))
parse_xml_file(os.path.join("UDLs", file))
def parse_xml_files_from_autoCompletions_dir():
for file in os.listdir("autoCompletions"):
if file.endswith(".xml"):
#print(os.path.join("autoCompletions", file))
parse_xml_file(os.path.join("autoCompletions", file))
parse_xml_files_from_udls_dir()
parse_xml_files_from_autoCompletions_dir()
if has_error:
sys.exit(-2)
else:
sys.exit()