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
8e107684
Commit
8e107684
authored
Apr 06, 2015
by
Ad Schellevis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
style fixes configd
parent
cba10171
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
104 additions
and
108 deletions
+104
-108
__init__.py
src/opnsense/service/modules/addons/__init__.py
+1
-0
template_helpers.py
src/opnsense/service/modules/addons/template_helpers.py
+7
-5
config.py
src/opnsense/service/modules/config.py
+7
-9
ph_inline_actions.py
src/opnsense/service/modules/ph_inline_actions.py
+3
-3
processhandler.py
src/opnsense/service/modules/processhandler.py
+43
-43
template.py
src/opnsense/service/modules/template.py
+43
-48
No files found.
src/opnsense/service/modules/addons/__init__.py
View file @
8e107684
...
@@ -29,3 +29,4 @@
...
@@ -29,3 +29,4 @@
--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------
package : configd
package : configd
"""
"""
src/opnsense/service/modules/addons/template_helpers.py
View file @
8e107684
...
@@ -30,8 +30,9 @@
...
@@ -30,8 +30,9 @@
package : configd
package : configd
"""
"""
class
Helpers
(
object
):
class
Helpers
(
object
):
def
__init__
(
self
,
template_in_data
):
def
__init__
(
self
,
template_in_data
):
""" initialize template helpers
""" initialize template helpers
:param template_in_data:
:param template_in_data:
...
@@ -39,22 +40,22 @@ class Helpers(object):
...
@@ -39,22 +40,22 @@ class Helpers(object):
"""
"""
self
.
_template_in_data
=
template_in_data
self
.
_template_in_data
=
template_in_data
def
getNodeByTag
(
self
,
tag
):
def
getNodeByTag
(
self
,
tag
):
""" get tree node by tag
""" get tree node by tag
:param tag: tag in dot notation (section.item)
:param tag: tag in dot notation (section.item)
:return: dict or None if not found
:return: dict or None if not found
"""
"""
node
=
self
.
_template_in_data
node
=
self
.
_template_in_data
for
item
in
tag
.
split
(
'.'
):
for
item
in
tag
.
split
(
'.'
):
if
node
.
has_key
(
item
)
:
if
item
in
node
:
node
=
node
[
item
]
node
=
node
[
item
]
else
:
else
:
# not found
# not found
return
None
return
None
# path found, return
# path found, return
return
node
return
node
def
exists
(
self
,
tag
):
def
exists
(
self
,
tag
):
"""
"""
check if node exists in dictionary structure
check if node exists in dictionary structure
:param tag: tag in dot notation (section.item)
:param tag: tag in dot notation (section.item)
...
@@ -64,3 +65,4 @@ class Helpers(object):
...
@@ -64,3 +65,4 @@ class Helpers(object):
return
True
return
True
else
:
else
:
return
False
return
False
src/opnsense/service/modules/config.py
View file @
8e107684
...
@@ -43,7 +43,7 @@ import xml.etree.cElementTree as ElementTree
...
@@ -43,7 +43,7 @@ import xml.etree.cElementTree as ElementTree
class
Config
(
object
):
class
Config
(
object
):
def
__init__
(
self
,
filename
):
def
__init__
(
self
,
filename
):
self
.
_filename
=
filename
self
.
_filename
=
filename
self
.
_config_data
=
{}
self
.
_config_data
=
{}
self
.
_file_mod
=
0
self
.
_file_mod
=
0
...
@@ -62,25 +62,25 @@ class Config(object):
...
@@ -62,25 +62,25 @@ class Config(object):
self
.
_config_data
=
self
.
_traverse
(
root
)
self
.
_config_data
=
self
.
_traverse
(
root
)
self
.
_file_mod
=
mod_time
self
.
_file_mod
=
mod_time
def
_traverse
(
self
,
xmlNode
):
def
_traverse
(
self
,
xmlNode
):
""" traverse xml node and return ordered dictionary structure
""" traverse xml node and return ordered dictionary structure
:param xmlNode: ElementTree node
:param xmlNode: ElementTree node
:return: collections.OrderedDict
:return: collections.OrderedDict
"""
"""
this_item
=
collections
.
OrderedDict
()
this_item
=
collections
.
OrderedDict
()
if
len
(
list
(
xmlNode
))
>
0
:
if
len
(
list
(
xmlNode
))
>
0
:
for
item
in
list
(
xmlNode
):
for
item
in
list
(
xmlNode
):
item_content
=
self
.
_traverse
(
item
)
item_content
=
self
.
_traverse
(
item
)
if
this_item
.
has_key
(
item
.
tag
)
:
if
item
.
tag
in
this_item
:
if
type
(
this_item
[
item
.
tag
])
!=
list
:
if
type
(
this_item
[
item
.
tag
])
!=
list
:
tmp_item
=
copy
.
deepcopy
(
this_item
[
item
.
tag
])
tmp_item
=
copy
.
deepcopy
(
this_item
[
item
.
tag
])
this_item
[
item
.
tag
]
=
[]
this_item
[
item
.
tag
]
=
[]
this_item
[
item
.
tag
]
.
append
(
tmp_item
)
this_item
[
item
.
tag
]
.
append
(
tmp_item
)
if
item_content
!=
None
:
if
item_content
is
not
None
:
# skip empty fields
# skip empty fields
this_item
[
item
.
tag
]
.
append
(
item_content
)
this_item
[
item
.
tag
]
.
append
(
item_content
)
elif
item_content
!=
None
:
elif
item_content
is
not
None
:
# create a new named item
# create a new named item
this_item
[
item
.
tag
]
=
self
.
_traverse
(
item
)
this_item
[
item
.
tag
]
=
self
.
_traverse
(
item
)
else
:
else
:
...
@@ -89,8 +89,7 @@ class Config(object):
...
@@ -89,8 +89,7 @@ class Config(object):
return
this_item
return
this_item
def
indent
(
self
,
elem
,
level
=
0
):
def
indent
(
self
,
elem
,
level
=
0
):
""" indent cElementTree (prettyprint fix)
""" indent cElementTree (prettyprint fix)
used from : http://infix.se/2007/02/06/gentlemen-indent-your-xml
used from : http://infix.se/2007/02/06/gentlemen-indent-your-xml
@param elem: cElementTree
@param elem: cElementTree
...
@@ -110,7 +109,6 @@ class Config(object):
...
@@ -110,7 +109,6 @@ class Config(object):
if
level
and
(
not
elem
.
tail
or
not
elem
.
tail
.
strip
()):
if
level
and
(
not
elem
.
tail
or
not
elem
.
tail
.
strip
()):
elem
.
tail
=
i
elem
.
tail
=
i
def
get
(
self
):
def
get
(
self
):
""" get active config data, load from disc if file in memory is different
""" get active config data, load from disc if file in memory is different
...
...
src/opnsense/service/modules/ph_inline_actions.py
View file @
8e107684
...
@@ -37,14 +37,14 @@ __author__ = 'Ad Schellevis'
...
@@ -37,14 +37,14 @@ __author__ = 'Ad Schellevis'
import
syslog
import
syslog
def
execute
(
action
,
parameters
):
def
execute
(
action
,
parameters
):
""" wrapper for inline functions
""" wrapper for inline functions
:param action: action object ( processhandler.Action type )
:param action: action object ( processhandler.Action type )
:param parameters: parameter string
:param parameters: parameter string
:return: status ( string )
:return: status ( string )
"""
"""
if
action
.
command
==
'template.reload'
:
if
action
.
command
==
'template.reload'
:
import
template
import
template
import
config
import
config
tmpl
=
template
.
Template
(
action
.
root_dir
)
tmpl
=
template
.
Template
(
action
.
root_dir
)
...
@@ -54,7 +54,7 @@ def execute(action,parameters):
...
@@ -54,7 +54,7 @@ def execute(action,parameters):
# send generated filenames to syslog
# send generated filenames to syslog
for
filename
in
filenames
:
for
filename
in
filenames
:
syslog
.
syslog
(
syslog
.
LOG_DEBUG
,
'
%
s generated
%
s'
%
(
parameters
,
filename
)
)
syslog
.
syslog
(
syslog
.
LOG_DEBUG
,
'
%
s generated
%
s'
%
(
parameters
,
filename
)
)
del
conf
del
conf
del
tmpl
del
tmpl
...
...
src/opnsense/service/modules/processhandler.py
View file @
8e107684
This diff is collapsed.
Click to expand it.
src/opnsense/service/modules/template.py
View file @
8e107684
This diff is collapsed.
Click to expand it.
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