Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
xml-validation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vaclab
xml-validation
Commits
6b80344f
Commit
6b80344f
authored
6 years ago
by
Thomas Bock
Browse files
Options
Downloads
Patches
Plain Diff
config links to dcc
parent
5df42f14
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.md
+8
-0
8 additions, 0 deletions
README.md
config.json
+2
-1
2 additions, 1 deletion
config.json
server.py
+10
-6
10 additions, 6 deletions
server.py
utils.py
+19
-10
19 additions, 10 deletions
utils.py
with
39 additions
and
17 deletions
README.md
+
8
−
0
View file @
6b80344f
...
...
@@ -83,6 +83,14 @@ Returns the version of the validation server:
> <version>0.2.0</version>
```
### /version_xsd [GET]
Returns the version of the xsd-definition:
```
> curl http://localhost:5005/version
> <version>0.2.0</version>
``
### /update [POST]
...
...
This diff is collapsed.
Click to expand it.
config.json
+
2
−
1
View file @
6b80344f
...
...
@@ -7,7 +7,8 @@
"dir"
:
"."
},
"xsd"
:{
"dir"
:
"./xsd"
,
"dir"
:
"../DCC/schemata"
,
"file"
:
"DCC_v1.9.xsd"
,
"url"
:
"https://intranet.ptb.de/fileadmin/dokumente/intranet/abteilungen/abteilung_1/Digitaler_Kalibrierschein/DCC"
}
}
This diff is collapsed.
Click to expand it.
server.py
+
10
−
6
View file @
6b80344f
...
...
@@ -5,9 +5,6 @@ import utils as utils
config
=
utils
.
get_config_dict
()
git_cmd
=
utils
.
git_cmd
(
config
)
## kommt später vom server
xsd_file_name
=
'
DCC_v1.8.3.xsd
'
app
=
Flask
(
__name__
)
CORS
(
app
)
...
...
@@ -18,6 +15,14 @@ def version():
return
utils
.
xml_response
(
ret
)
@app.route
(
'
/version_xsd
'
,
methods
=
[
'
get
'
])
def
version_xsd
():
app
.
logger
.
debug
(
'
hit version_xsd
'
)
xsd_str
=
utils
.
get_xsd
(
config
,
from_server
=
False
)
version_str
=
utils
.
get_xsd_version
(
xsd_str
)
return
utils
.
xml_response
(
utils
.
return_version
(
version_str
))
@app.route
(
'
/update
'
,
methods
=
[
'
post
'
])
def
update
():
app
.
logger
.
debug
(
'
hit update
'
)
...
...
@@ -31,7 +36,7 @@ def update():
@app.route
(
'
/update_xsd
'
,
methods
=
[
'
post
'
])
def
update_xsd
():
app
.
logger
.
debug
(
'
hit update xsd
'
)
xsd_str
=
utils
.
get_xsd
(
config
,
xsd_file_name
,
from_server
=
True
)
xsd_str
=
utils
.
get_xsd
(
config
,
from_server
=
True
)
xsd_xml
=
utils
.
parse
(
xsd_str
)
if
xsd_xml
:
ret
=
utils
.
save_xsd
(
config
,
xsd_str
,
xsd_file_name
)
...
...
@@ -40,14 +45,13 @@ def update_xsd():
return
utils
.
xml_response
(
ret
)
@app.route
(
'
/validate
'
,
methods
=
[
'
post
'
])
def
validate
():
app
.
logger
.
debug
(
'
hit validate
'
)
xml_str
=
request
.
data
xml_tree
=
utils
.
parse
(
xml_str
)
if
xml_tree
:
xsd_str
=
utils
.
get_xsd
(
config
,
xsd_file_name
,
from_server
=
False
)
xsd_str
=
utils
.
get_xsd
(
config
,
from_server
=
False
)
ret
=
utils
.
validate
(
xml_str
=
xml_str
,
xsd_str
=
xsd_str
)
else
:
ret
=
utils
.
return_error
(
error
=
'
unvalid xml data
'
)
...
...
This diff is collapsed.
Click to expand it.
utils.py
+
19
−
10
View file @
6b80344f
...
...
@@ -5,8 +5,9 @@ from flask import Response
from
xml.etree
import
ElementTree
as
ET
import
xmlschema
ns
=
{
"
w3
"
:
"
http://www.w3.org/2001/XMLSchema
"
}
def
get_config_dict
():
## sollte vielleicht doch xml-datei werden
with
open
(
'
./config.json
'
)
as
json_config_file
:
config
=
json
.
load
(
json_config_file
)
...
...
@@ -15,24 +16,25 @@ def get_config_dict():
def
git_cmd
(
config
):
return
git
.
cmd
.
Git
(
config
[
'
git
'
][
'
dir
'
])
def
get_xsd_url
(
config
,
xsd
_name
):
return
"
{uri}/{
xsd
_name}
"
.
format
(
uri
=
config
[
'
xsd
'
][
'
url
'
],
xsd
_name
=
xsd
_name
)
def
get_xsd_url
(
config
,
file
_name
):
return
"
{uri}/{
file
_name}
"
.
format
(
uri
=
config
[
'
xsd
'
][
'
url
'
],
file
_name
=
file
_name
)
def
get_xsd_path_file
(
config
,
xsd
_name
):
return
"
{dir}/{
xsd
_name}
"
.
format
(
dir
=
config
[
'
xsd
'
][
'
dir
'
],
xsd
_name
=
xsd
_name
)
def
get_xsd_path_file
(
config
,
file
_name
):
return
"
{dir}/{
file
_name}
"
.
format
(
dir
=
config
[
'
xsd
'
][
'
dir
'
],
file
_name
=
file
_name
)
def
get_xsd
(
config
,
xsd_name
,
from_server
=
True
):
def
get_xsd
(
config
,
from_server
=
True
):
file_name
=
config
[
'
xsd
'
][
'
file
'
]
if
from_server
:
url
=
get_xsd_url
(
config
,
xsd
_name
)
url
=
get_xsd_url
(
config
,
file
_name
)
xsd_str
=
requests
.
get
(
url
).
text
else
:
path_file
=
get_xsd_path_file
(
config
,
xsd
_name
)
path_file
=
get_xsd_path_file
(
config
,
file
_name
)
xsd_str
=
open
(
path_file
).
read
()
return
xsd_str
def
save_xsd
(
config
,
xsd_str
,
xsd
_name
):
path_file
=
get_xsd_path_file
(
config
,
xsd
_name
)
def
save_xsd
(
config
,
xsd_str
,
file
_name
):
path_file
=
get_xsd_path_file
(
config
,
file
_name
)
file
=
open
(
path_file
,
"
w
"
)
file
.
write
(
xsd_str
)
...
...
@@ -45,6 +47,13 @@ def parse(xml_str):
tree
=
None
return
tree
def
get_xsd_version
(
xsd_str
):
tree
=
parse
(
xsd_str
)
for
annotation
in
tree
.
findall
(
"
w3:annotation
"
,
ns
):
version_text
=
annotation
.
find
(
"
w3:documentation
"
,
ns
).
text
return
version_text
def
validate
(
xml_str
,
xsd_str
):
tree
=
parse
(
xml_str
)
schema
=
xmlschema
.
XMLSchema
(
xsd_str
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment