Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brian-dashboard-manager
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
geant-swd
brian
brian-dashboard-manager
Commits
7f8be331
Commit
7f8be331
authored
1 year ago
by
Bjarke Madsen
Browse files
Options
Downloads
Patches
Plain Diff
cache jinja templates to speed provisioning
parent
f9907a4a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
brian_dashboard_manager/templating/render.py
+64
-45
64 additions, 45 deletions
brian_dashboard_manager/templating/render.py
with
64 additions
and
45 deletions
brian_dashboard_manager/templating/render.py
+
64
−
45
View file @
7f8be331
...
...
@@ -7,6 +7,63 @@ import json
import
jinja2
def
_read_template
(
filename
):
"""
Reads the template from the given filename.
:param filename: path to the template file
:return: template
"""
with
open
(
filename
)
as
f
:
return
jinja2
.
Template
(
f
.
read
())
dropdown_template_file
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
templates
'
,
'
shared
'
,
'
dropdown.json.j2
'
))
yaxes_template_file
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
templates
'
,
'
shared
'
,
'
yaxes.json.j2
'
))
panel_template_file
=
file
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
templates
'
,
'
shared
'
,
'
panel.json.j2
'
))
panel_target_template_file
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
templates
'
,
'
shared
'
,
'
panel_target.json.j2
'
))
nren_dashboard_template_file
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
templates
'
,
'
nren_access
'
,
'
nren-dashboard.json.j2
'
))
dashboard_template_file
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
templates
'
,
'
shared
'
,
'
dashboard.json.j2
'
))
DROPDOWN_TEMPLATE
=
_read_template
(
dropdown_template_file
)
YAXES_TEMPLATE
=
_read_template
(
yaxes_template_file
)
PANEL_TEMPLATE
=
_read_template
(
panel_template_file
)
PANEL_TARGET_TEMPLATE
=
_read_template
(
panel_target_template_file
)
NREN_DASHBOARD_TEMPLATE
=
_read_template
(
nren_dashboard_template_file
)
DASHBOARD_TEMPLATE
=
_read_template
(
dashboard_template_file
)
def
create_dropdown_panel
(
title
,
**
kwargs
):
"""
Creates a dropdown panel from the given data.
...
...
@@ -17,14 +74,7 @@ def create_dropdown_panel(title, **kwargs):
:return: rendered dropdown panel JSON
"""
TEMPLATE_FILENAME
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
templates
'
,
'
shared
'
,
'
dropdown.json.j2
'
))
with
open
(
TEMPLATE_FILENAME
)
as
f
:
template
=
jinja2
.
Template
(
f
.
read
())
return
template
.
render
({
**
kwargs
,
'
title
'
:
title
})
return
DROPDOWN_TEMPLATE
.
render
({
**
kwargs
,
'
title
'
:
title
})
def
create_yaxes
(
type
):
...
...
@@ -36,14 +86,7 @@ def create_yaxes(type):
:return: rendered yaxes JSON
"""
file
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
templates
'
,
'
shared
'
,
'
yaxes.json.j2
'
))
with
open
(
file
)
as
f
:
template
=
jinja2
.
Template
(
f
.
read
())
return
template
.
render
({
'
type
'
:
type
})
return
YAXES_TEMPLATE
.
render
({
'
type
'
:
type
})
def
create_panel_target
(
data
):
...
...
@@ -56,14 +99,7 @@ def create_panel_target(data):
:return: rendered panel target JSON
"""
file
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
templates
'
,
'
shared
'
,
'
panel_target.json.j2
'
))
with
open
(
file
)
as
f
:
template
=
jinja2
.
Template
(
f
.
read
())
return
template
.
render
(
data
)
return
PANEL_TARGET_TEMPLATE
.
render
(
data
)
def
create_panel
(
data
):
...
...
@@ -76,18 +112,11 @@ def create_panel(data):
:return: rendered panel JSON
"""
file
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
templates
'
,
'
shared
'
,
'
panel.json.j2
'
))
with
open
(
file
)
as
f
:
template
=
jinja2
.
Template
(
f
.
read
())
yaxes
=
create_yaxes
(
data
.
get
(
'
y_axis_type
'
,
'
bits
'
))
targets
=
data
.
get
(
'
targets
'
,
[])
for
target
in
data
.
get
(
'
panel_targets
'
,
[]):
targets
.
append
(
create_panel_target
(
target
))
return
template
.
render
({
**
data
,
'
yaxes
'
:
yaxes
,
'
targets
'
:
targets
})
return
PANEL_TEMPLATE
.
render
({
**
data
,
'
yaxes
'
:
yaxes
,
'
targets
'
:
targets
})
def
render_dashboard
(
dashboard
,
nren
=
False
):
...
...
@@ -103,20 +132,10 @@ def render_dashboard(dashboard, nren=False):
"""
if
nren
:
file
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
templates
'
,
'
nren_access
'
,
'
nren-dashboard.json.j2
'
))
template
=
NREN_DASHBOARD_TEMPLATE
else
:
file
=
os
.
path
.
abspath
(
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'
templates
'
,
'
shared
'
,
'
dashboard.json.j2
'
))
with
open
(
file
)
as
f
:
template
=
jinja2
.
Template
(
f
.
read
())
template
=
DASHBOARD_TEMPLATE
rendered
=
template
.
render
(
dashboard
)
rendered
=
json
.
loads
(
rendered
)
rendered
[
'
uid
'
]
=
None
...
...
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