Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LI - Lawful Interception
Trial
Commits
113dabe5
Commit
113dabe5
authored
Jun 15, 2021
by
canterburym
Browse files
Updating XSD testing
parent
a76d7465
Pipeline
#7372
passed with stage
in 21 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
testing/check_xsd.py
View file @
113dabe5
...
...
@@ -10,6 +10,7 @@ import os
from
lxml
import
etree
from
xml.etree.ElementTree
import
ParseError
from
xmlschema
import
XMLSchema
,
XMLSchemaParseError
from
xmlschema.validators.exceptions
import
XMLSchemaModelError
def
BuildSchemaDictonary
(
fileList
):
...
...
@@ -60,7 +61,7 @@ def ValidateXSDFiles (fileList):
schema
=
XMLSchema
(
schemaFile
,
locations
=
schemaLocations
)
logging
.
info
(
schemaFile
+
": OK"
)
errors
[
schemaFile
]
=
[]
except
XMLSchemaParseError
as
ex
:
except
(
XMLSchemaParseError
,
XMLSchemaModelError
)
as
ex
:
if
(
ex
.
schema_url
)
and
(
ex
.
schema_url
!=
ex
.
origin_url
):
logging
.
info
(
" Error {1} comes from {0}, suppressing"
.
format
(
ex
.
schema_url
,
ex
.
message
))
errors
[
schemaFile
]
=
[]
...
...
@@ -90,6 +91,8 @@ def ValidateInstanceDocuments (coreFile, supportingSchemas, instanceDocs):
if
__name__
==
'__main__'
:
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"-v"
,
"--verbosity"
,
help
=
"verbosity level"
,
action
=
"count"
,
default
=
0
)
parser
.
add_argument
(
"-r"
,
"--recurse"
,
help
=
"recurse into subdirectories"
,
action
=
"store_true"
)
parser
.
add_argument
(
"-s"
,
"--skipbuild"
,
help
=
"skip the (lengthy) build checks"
,
action
=
"store_true"
)
parser
.
add_argument
(
"input"
,
help
=
"include a directory or file"
,
action
=
"append"
,
nargs
=
"+"
)
args
=
parser
.
parse_args
()
...
...
@@ -101,6 +104,12 @@ if __name__ == '__main__':
logging
.
debug
(
"Very verbose selected"
)
logging
.
debug
(
f
"Path:
{
args
.
input
}
"
)
if
(
args
.
recurse
):
logging
.
info
(
"Recursion enabled"
)
if
(
args
.
skipbuild
):
logging
.
info
(
"Skipping build checks"
)
includeFileList
=
[]
for
path
in
args
.
input
[
0
]:
p
=
Path
(
path
)
...
...
@@ -109,34 +118,47 @@ if __name__ == '__main__':
exit
(
1
)
if
p
.
is_dir
():
logging
.
debug
(
f
"Expanding directory"
)
for
g
in
glob
.
glob
(
os
.
path
.
join
(
str
(
p
),
"*.xsd"
)):
logging
.
info
(
f
">Including
{
g
}
"
)
includeFileList
.
append
(
g
)
if
(
args
.
recurse
):
files
=
p
.
rglob
(
"*.xsd"
)
else
:
files
=
p
.
glob
(
"*.xsd"
)
for
f
in
files
:
logging
.
info
(
f
"...Including
{
f
}
"
)
includeFileList
.
append
(
str
(
f
.
absolute
()))
else
:
logging
.
info
(
f
"Including
{
p
.
absolute
()
}
"
)
includeFileList
.
append
(
p
.
absolute
())
includeFileList
.
append
(
str
(
p
.
absolute
())
)
syntaxErrors
=
0
print
(
"===================================================="
)
print
(
"XSD syntax checks:"
)
print
(
"-----------------------------"
)
print
(
"----------------------------------------------------"
)
errors
=
{}
for
file
in
includeFileList
:
error
=
ValidateSingleFile
(
file
)
if
(
error
):
print
(
f
"
{
file
}
: Syntax error [
{
error
}
]"
)
syntaxErrors
+=
1
errors
[
file
]
=
error
else
:
print
(
f
"
{
file
}
: OK"
)
print
(
"-----------------------------"
)
if
(
syntaxErrors
>
0
):
print
(
f
"
{
syntaxErrors
}
syntax errors detected"
)
print
(
"----------------------------------------------------"
)
print
(
f
"
{
syntaxErrors
}
syntax errors detected"
)
if
(
len
(
errors
.
keys
())
>
0
):
for
fileName
,
error
in
errors
.
items
():
print
(
f
"
{
fileName
}
:
{
error
}
"
)
exit
(
syntaxErrors
)
if
(
args
.
skipbuild
):
print
(
"Skipping build checks"
)
exit
(
0
)
print
(
""
)
print
(
"===================================================="
)
print
(
"XSD build checks (this may take a while):"
)
print
(
"----------------------------------------------------"
)
results
=
ValidateXSDFiles
(
includeFileList
)
print
(
"XSD build checks:"
)
print
(
"-----------------------------"
)
errorCount
=
0
for
fileName
,
errors
in
results
.
items
():
if
len
(
errors
)
>
0
:
...
...
@@ -150,6 +172,16 @@ if __name__ == '__main__':
else
:
print
(
f
"
{
fileName
}
: OK"
)
print
(
"-----------------------------"
)
print
(
"-----------------------------
-----------------------
"
)
print
(
f
"
{
errorCount
}
build errors detected"
)
for
fileName
,
errors
in
results
.
items
():
if
len
(
errors
)
>
0
:
errorCount
+=
len
(
errors
)
print
(
f
"
{
fileName
}
:
{
len
(
errors
)
}
errors"
)
for
error
in
errors
:
if
isinstance
(
error
,
XMLSchemaParseError
):
print
(
str
(
error
))
else
:
print
(
f
"
{
str
(
error
.
strip
())
}
"
)
exit
(
errorCount
)
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment