Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
OpnSense
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
OpnSense
Commits
5f38b93d
Commit
5f38b93d
authored
Feb 20, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add alternate root location for template generation (for local testing)
parent
37cadc25
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
2 deletions
+10
-2
actions_template.conf
src/opnsense/service/conf/actions_template.conf
+1
-0
ph_inline_actions.py
src/opnsense/service/modules/ph_inline_actions.py
+1
-1
template.py
src/opnsense/service/modules/template.py
+8
-1
No files found.
src/opnsense/service/conf/actions_template.conf
View file @
5f38b93d
...
...
@@ -4,3 +4,4 @@ parameters:%s
type
:
inline
message
:
generate
template
%
s
config
:/
conf
/
config
.
xml
root_dir
:/
src/opnsense/service/modules/ph_inline_actions.py
View file @
5f38b93d
...
...
@@ -47,7 +47,7 @@ def execute(action,parameters):
if
action
.
command
==
'template.reload'
:
import
template
import
config
tmpl
=
template
.
Template
()
tmpl
=
template
.
Template
(
action
.
root_dir
)
conf
=
config
.
Config
(
action
.
config
)
tmpl
.
setConfig
(
conf
.
get
())
filenames
=
tmpl
.
generate
(
parameters
)
...
...
src/opnsense/service/modules/template.py
View file @
5f38b93d
...
...
@@ -42,11 +42,16 @@ import jinja2
class
Template
(
object
):
def
__init__
(
self
):
def
__init__
(
self
,
target_root_directory
=
"/"
):
""" constructor
:return:
"""
# init config (config.xml) data
self
.
_config
=
{}
# set target root
self
.
_target_root_directory
=
target_root_directory
# setup jinja2 environment
self
.
_template_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
+
'/../templates/'
self
.
_j2_env
=
jinja2
.
Environment
(
loader
=
jinja2
.
FileSystemLoader
(
self
.
_template_dir
),
trim_blocks
=
True
)
...
...
@@ -229,6 +234,8 @@ class Template(object):
# render page and write to disc
content
=
j2_page
.
render
(
cnf_data
)
# prefix filename with defined root directory
filename
=
(
'
%
s/
%
s'
%
(
self
.
_target_root_directory
,
filename
))
.
replace
(
'//'
,
'/'
)
if
create_directory
:
# make sure the target directory exists
self
.
_create_directory
(
filename
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment