Working on python version
This commit is contained in:
36
scripts/utils.py
Normal file
36
scripts/utils.py
Normal file
@ -0,0 +1,36 @@
|
||||
from vars import VARS
|
||||
|
||||
import os
|
||||
import jinja2
|
||||
import subprocess
|
||||
|
||||
PROJECT_PATH = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
|
||||
print('PROJECT_PATH: {}'.format(PROJECT_PATH))
|
||||
|
||||
template_path = os.path.join(PROJECT_PATH, 'conf/templates')
|
||||
template_loader = jinja2.FileSystemLoader(searchpath=template_path)
|
||||
template_env = jinja2.Environment(loader=template_loader)
|
||||
|
||||
|
||||
def render_template(src, dest, template_vars=None):
|
||||
"""
|
||||
:param src: relative string path to jinja template file
|
||||
:param dest: absolute string path of output destination file
|
||||
:param template_vars: variables to render template with
|
||||
:return: None
|
||||
"""
|
||||
template = template_env.get_template(src)
|
||||
if template_vars:
|
||||
template_vars.update(VARS)
|
||||
else:
|
||||
template_vars = VARS
|
||||
output_text = template.render(template_vars=template_vars)
|
||||
if os.path.exists(dest):
|
||||
os.remove(dest)
|
||||
with open(dest, 'w') as f:
|
||||
f.write(output_text)
|
||||
|
||||
|
||||
def cargo_install(package):
|
||||
subprocess.call(['/root/.cargo/bin/cargo', 'install', package])
|
||||
|
||||
Reference in New Issue
Block a user