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
9faa8e0b
Commit
9faa8e0b
authored
3 years ago
by
Rolf Niepraschk
Browse files
Options
Downloads
Patches
Plain Diff
read json structure from "releases.json"
parent
10c99ec6
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
config.json
+3
-1
3 additions, 1 deletion
config.json
server.py
+8
-4
8 additions, 4 deletions
server.py
utils.py
+23
-0
23 additions, 0 deletions
utils.py
with
34 additions
and
5 deletions
config.json
+
3
−
1
View file @
9faa8e0b
...
@@ -5,6 +5,8 @@
...
@@ -5,6 +5,8 @@
},
},
"xsd"
:{
"xsd"
:{
"filename"
:
"dcc.xsd"
,
"filename"
:
"dcc.xsd"
,
"externalBaseURL"
:
"https://ptb.de/dcc/"
"externalBaseURL"
:
"https://ptb.de/dcc/"
,
"localPath"
:
"./xsd-local/"
,
"releases"
:
"https://www.ptb.de/dcc/releases.json"
}
}
}
}
This diff is collapsed.
Click to expand it.
server.py
+
8
−
4
View file @
9faa8e0b
...
@@ -3,11 +3,13 @@ from flask_cors import CORS
...
@@ -3,11 +3,13 @@ from flask_cors import CORS
import
utils
as
utils
import
utils
as
utils
from
trans
import
Trans
from
trans
import
Trans
from
datetime
import
datetime
from
datetime
import
datetime
import
subprocess
import
subprocess
,
json
from
pprint
import
pprint
from
pprint
import
pprint
config
=
utils
.
get_config_dict
()
config
=
utils
.
get_config_dict
()
releases_dict
=
utils
.
get_releases_dict
(
config
[
'
xsd
'
][
'
releases
'
])
versions
=
utils
.
get_versions
(
releases_dict
)
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
CORS
(
app
)
CORS
(
app
)
trans
=
Trans
()
trans
=
Trans
()
...
@@ -65,11 +67,11 @@ def validate():
...
@@ -65,11 +67,11 @@ def validate():
@app.route
(
'
/validation.html
'
,
methods
=
[
'
GET
'
])
@app.route
(
'
/validation.html
'
,
methods
=
[
'
GET
'
])
def
validation
():
def
validation
():
app
.
logger
.
debug
(
'
hit validation.html
'
)
app
.
logger
.
debug
(
'
hit validation.html
'
)
# pprint(vars(request))
l
=
str
(
request
.
accept_languages
).
split
(
'
,
'
)[
0
][
0
:
2
]
l
=
str
(
request
.
accept_languages
).
split
(
'
,
'
)[
0
][
0
:
2
]
if
l
!=
'
de
'
:
if
l
!=
'
de
'
:
l
=
'
en
'
l
=
'
en
'
x
=
"
[
'
2.4.0
'
,
'
2.3.0
'
,
'
2.2.0
'
,
'
2.1.1
'
,
'
2.1.0
'
]
"
# x = '["2.4.0","2.3.0","2.2.0","2.1.1","2.1.0"]'
x
=
'
[
'
+
'
,
'
.
join
(
versions
)
+
'
]
'
# javascript array definition as string
return
trans
.
show_html
(
version
=
utils
.
get_version
(),
language
=
l
,
return
trans
.
show_html
(
version
=
utils
.
get_version
(),
language
=
l
,
xsd_versions
=
x
)
xsd_versions
=
x
)
...
@@ -90,3 +92,5 @@ def logo_folder(fn):
...
@@ -90,3 +92,5 @@ def logo_folder(fn):
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
app
.
run
(
host
=
config
[
'
server
'
][
'
host
'
],
port
=
config
[
'
server
'
][
'
port
'
])
app
.
run
(
host
=
config
[
'
server
'
][
'
host
'
],
port
=
config
[
'
server
'
][
'
port
'
])
This diff is collapsed.
Click to expand it.
utils.py
+
23
−
0
View file @
9faa8e0b
...
@@ -21,6 +21,29 @@ def get_config_dict():
...
@@ -21,6 +21,29 @@ def get_config_dict():
return
config
return
config
# get content of 'releases.json' via http request
def
get_releases_dict
(
url
):
try
:
filename
=
urlparse
(
url
).
path
.
split
(
'
/
'
)[
-
1
]
r
=
requests
.
get
(
url
,
allow_redirects
=
True
)
if
r
.
url
.
endswith
(
filename
):
# no bad redirection
try
:
return
json
.
loads
(
r
.
text
)
except
:
return
False
else
:
return
False
except
:
return
False
# a reverse list of version strings
def
get_versions
(
d
):
v
=
[]
for
i
in
d
[
'
releases
'
]:
v
.
append
(
'"'
+
i
[
'
version
'
]
+
'"'
)
v
=
list
(
reversed
(
v
))
return
v
def
get_version
():
def
get_version
():
try
:
try
:
with
open
(
'
./VERSION
'
,
'
r
'
)
as
f
:
with
open
(
'
./VERSION
'
,
'
r
'
)
as
f
:
...
...
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