Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F7577870
resolve.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
resolve.py
View Options
#!/usr/bin/env python3
# -------------------------------------------------------------
# Generate a template from relevant metadata
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Project: Keruald
# Description: Generate a template from metadata
# License: BSD-2-Clause
# Dependencies: Jinja2
# -------------------------------------------------------------
import
sys
import
yaml
from
jinja2
import
Environment
,
FileSystemLoader
METADATA_FILE
=
"metadata.yml"
# -------------------------------------------------------------
# Template
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def
prepare_template_engine
():
return
Environment
(
loader
=
FileSystemLoader
(
'.'
)
)
def
get_metadata
(
metadata_path
):
return
yaml
.
safe_load
(
open
(
metadata_path
))
def
generate_template
(
template_path
,
metadata_path
):
env
=
prepare_template_engine
()
template
=
env
.
get_template
(
template_path
)
return
template
.
render
(
get_metadata
(
metadata_path
))
# -------------------------------------------------------------
# Application entry point
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def
run
(
template_path
):
content
=
generate_template
(
template_path
,
METADATA_FILE
)
print
(
content
)
if
__name__
==
"__main__"
:
argc
=
len
(
sys
.
argv
)
if
argc
<
2
:
print
(
f
"Usage: {sys.argv[0]} <argument>"
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
run
(
sys
.
argv
[
1
])
File Metadata
Details
Attached
Mime Type
text/x-python
Expires
Thu, May 1, 02:44 (7 h, 38 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2565661
Default Alt Text
resolve.py (1 KB)
Attached To
Mode
rKERUALD Keruald libraries development repository
Attached
Detach File
Event Timeline
Log In to Comment