File tree Expand file tree Collapse file tree
netjsonconfig/backends/openwisp Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33from jinja2 import Environment , PackageLoader
44
55from ..openwrt .openwrt import OpenWrt
6+ from .renderer import OpenWrtRenderer
67from .schema import schema
78
89
@@ -12,6 +13,7 @@ class OpenWisp(OpenWrt):
1213 """
1314
1415 schema = schema
16+ renderer = OpenWrtRenderer
1517
1618 def validate (self ):
1719 self ._sanitize_radios ()
Original file line number Diff line number Diff line change 1+ from ..openwrt .renderer import OpenWrtRenderer as BaseRenderer
2+
3+
4+ class OpenWrtRenderer (BaseRenderer ):
5+ """
6+ OpenWRT Renderer for OpenWISP 1.x backend
7+
8+ It uses a slightly different template
9+ than the default OpenWRT renderer in order
10+ to provide backward compatibility with the
11+ format that was generated by OpenWISP Manager.
12+
13+ E.g.:
14+
15+ # OpenWISP Manager:
16+ config 'system' 'system'
17+ option 'hostname' 'openwisp-test'
18+
19+ # standard OpenWRT conf generated by netjsonconfig:
20+ config system 'system'
21+ option hostname 'openwisp-test'
22+ """
23+
24+ pass
Original file line number Diff line number Diff line change 1+ {% for package , config_blocks in data .items () %}
2+ package {{ package }}
3+
4+ {% for config in config_blocks %}
5+ config '{{ config['.type'] }}' '{{ config['.name'] }}'
6+ {% for key , value in config .items () %}
7+ {% if value not in ['' , None ] and not key .startswith ('.' ) %}
8+ {% if value is not string and value is iterable %}
9+ {% for list_value in value %}
10+ list '{{ key }}' '{{ list_value }}'
11+ {% endfor %}
12+ {% else %}
13+ option '{{ key }}' '{{ value }}'
14+ {% endif %}
15+ {% endif %}
16+ {% endfor %}
17+
18+ {% endfor %}
19+
20+ {% endfor %}
Original file line number Diff line number Diff line change @@ -111,8 +111,8 @@ def test_uci(self):
111111 expected = self ._tabs (
112112 """package system
113113
114- config system 'system'
115- option hostname 'openwisp-test'
114+ config ' system' 'system'
115+ option ' hostname' 'openwisp-test'
116116"""
117117 )
118118 self .assertEqual (contents , expected )
@@ -182,7 +182,7 @@ def test_double_generation(self):
182182 def test_wireless_radio_disabled_0 (self ):
183183 o = OpenWisp ({'radios' : self .config ['radios' ]})
184184 output = o .render ()
185- self .assertIn ("option disabled '0'" , output )
185+ self .assertIn ("option ' disabled' '0'" , output )
186186
187187 def test_tc_script (self ):
188188 config = deepcopy (self .config )
You can’t perform that action at this time.
0 commit comments