Added file_size and file_content_hex Jinja filters.
Added check if Jinja module exists and appropriate error message to project generation.
This commit is contained in:
parent
5f11d64744
commit
2769fd801f
@ -3,7 +3,6 @@ import copy
|
||||
import enum
|
||||
import glob
|
||||
import inspect
|
||||
import jinja2
|
||||
import json
|
||||
import multiprocessing
|
||||
import os
|
||||
@ -540,6 +539,11 @@ def _target_entry(target_value):
|
||||
return target_value[0]
|
||||
|
||||
def _generate_project(project_type: str) -> None:
|
||||
try:
|
||||
import jinja2
|
||||
except ImportError:
|
||||
_error(None, 'Project generation requires the jinja2 to be installed.')
|
||||
|
||||
source_folder, target_folder = {
|
||||
'clion': (os.path.join(_spp_dir.abspath, 'util', 'clion_project_template'), Dir('#.idea').abspath),
|
||||
'vscode': (os.path.join(_spp_dir.abspath, 'util', 'vscode_project_template'), Dir('#.vscode').abspath)
|
||||
|
@ -31,8 +31,19 @@ def _wrap_jinja(orig_jinja):
|
||||
return target
|
||||
return _wrapped
|
||||
|
||||
def _file_size(env, fname: str) -> int:
|
||||
return env.File(fname).get_size()
|
||||
|
||||
def _file_content_hex(env, fname: str) -> str:
|
||||
bytes = env.File(fname).get_contents()
|
||||
return ','.join([hex(byte) for byte in bytes])
|
||||
|
||||
env.AddMethod(_wrap_jinja(env.Jinja), 'Jinja')
|
||||
env.Append(JINJA_FILTERS = {'load_config': _jinja_load_config})
|
||||
env.Append(JINJA_GLOBALS = {
|
||||
'file_size': lambda *args: _file_size(env, *args),
|
||||
'file_content_hex': lambda *args: _file_content_hex(env, *args)
|
||||
})
|
||||
env.Append(JINJA_TEMPLATE_SEARCHPATH = ['data/jinja'])
|
||||
env['JINJA_CONFIG_SEARCHPATH'] = [env.Dir('#data/config')]
|
||||
Return('env')
|
||||
|
Loading…
x
Reference in New Issue
Block a user