summaryrefslogtreecommitdiff
path: root/reconfigure
diff options
context:
space:
mode:
authorAndrew Shadura <andrewsh@debian.org>2018-04-25 14:33:27 +0200
committerAndrew Shadura <andrewsh@debian.org>2018-04-25 14:33:27 +0200
commitb50a7a9f6a102709eacd1335c00a1e0d0b259b8e (patch)
tree481b20200ab0c34e1f0d829d8b4b8d17dceaadcd /reconfigure
parent2989b4c027b3230b1778e3777d2cce53c89808d9 (diff)
New upstream version 0.1.81+git20171214.2b8729a8
Diffstat (limited to 'reconfigure')
-rw-r--r--reconfigure/__init__.py3
-rw-r--r--reconfigure/configs/base.py5
-rw-r--r--reconfigure/items/bound.py3
-rw-r--r--reconfigure/items/netatalk.py4
-rw-r--r--reconfigure/items/samba.py7
-rw-r--r--reconfigure/nodes.py3
-rw-r--r--reconfigure/parsers/ini.py10
-rw-r--r--reconfigure/parsers/nginx.py6
-rw-r--r--reconfigure/tests/configs/netatalk_tests.py2
-rw-r--r--reconfigure/tests/parsers/ini_tests.py10
10 files changed, 38 insertions, 15 deletions
diff --git a/reconfigure/__init__.py b/reconfigure/__init__.py
index a52a5aa..0dc4efd 100644
--- a/reconfigure/__init__.py
+++ b/reconfigure/__init__.py
@@ -1 +1,2 @@
-__version__ = "0.1.74"
+
+__version__ = "0.1.81"
diff --git a/reconfigure/configs/base.py b/reconfigure/configs/base.py
index fc2ce6f..0d707fb 100644
--- a/reconfigure/configs/base.py
+++ b/reconfigure/configs/base.py
@@ -1,5 +1,4 @@
import chardet
-import six
import sys
@@ -38,8 +37,8 @@ class Reconfig (object):
self.content = open(self.origin, 'r').read()
self.encoding = 'utf8'
- if (six.PY3 and isinstance(self.content, bytes)) or \
- (six.PY2 and isinstance(self.content, str)):
+ if (sys.version_info[0] >= 3 and isinstance(self.content, bytes)) or \
+ (sys.version_info[0] == 2 and isinstance(self.content, str)):
try:
self.content = self.content.decode('utf8')
except (UnicodeDecodeError, AttributeError):
diff --git a/reconfigure/items/bound.py b/reconfigure/items/bound.py
index fed73f4..7570fe7 100644
--- a/reconfigure/items/bound.py
+++ b/reconfigure/items/bound.py
@@ -144,6 +144,7 @@ class BoundData (object):
if node is None:
node = self.template(**kwargs)
self._node = node
+ self.bind_attribute('_extra_content', '_extra_content')
def template(self, **kwargs):
"""
@@ -157,6 +158,8 @@ class BoundData (object):
res_dict = {}
for attr_key in self.__class__.__dict__:
if attr_key in self.__class__._bound:
+ if attr_key == '_extra_content':
+ continue
attr_value = getattr(self, attr_key)
if isinstance(attr_value, BoundData):
res_dict[attr_key] = attr_value.to_dict()
diff --git a/reconfigure/items/netatalk.py b/reconfigure/items/netatalk.py
index 7989220..ed7d282 100644
--- a/reconfigure/items/netatalk.py
+++ b/reconfigure/items/netatalk.py
@@ -12,8 +12,8 @@ class GlobalData (BoundData):
class ShareData (BoundData):
- fields = ['path', 'appledouble', 'valid users', 'cnid scheme', 'ea', 'password', 'file perm', 'directory perm']
- defaults = ['', 'ea', '', 'dbd', 'none', '', '', '']
+ fields = ['path', 'appledouble', 'valid users', 'cnid scheme', 'ea', 'password', 'file perm', 'directory perm', 'rolist', 'rwlist']
+ defaults = ['', 'ea', '', 'dbd', 'none', '', '', '', '', '']
def template(self):
return Node(
diff --git a/reconfigure/items/samba.py b/reconfigure/items/samba.py
index 3288b2e..d691adc 100644
--- a/reconfigure/items/samba.py
+++ b/reconfigure/items/samba.py
@@ -58,8 +58,11 @@ GlobalData.bind_property('security', 'security', default='user')
ShareData.bind_name('name')
for f, d in zip(ShareData.fields, ShareData.default_values):
if d not in [True, False]:
- ShareData.bind_property(f, f.replace(' ', '_'), default=d)
+ ShareData.bind_property(
+ f, f.replace(' ', '_'), default=d, default_remove=[d]
+ )
else:
ShareData.bind_property(
f, f.replace(' ', '_'), default=d,
- getter=yn_getter, setter=yn_setter)
+ getter=yn_getter, setter=yn_setter
+ )
diff --git a/reconfigure/nodes.py b/reconfigure/nodes.py
index 8c2c2d4..20fd927 100644
--- a/reconfigure/nodes.py
+++ b/reconfigure/nodes.py
@@ -14,6 +14,7 @@ class Node (object):
self.name = name
self.origin = None
self.children = []
+ self._extra_content = kwargs.pop('extra_content', None)
for node in list(args) + kwargs.pop('children', []):
self.append(node)
self.comment = kwargs.pop('comment', None)
@@ -104,7 +105,7 @@ class Node (object):
"""
Replaces the child nodes by ``name``
- :param node: replacement node or list of nodes
+ :param node: replacement node or list of nodes
::
diff --git a/reconfigure/parsers/ini.py b/reconfigure/parsers/ini.py
index 2f95d33..851bfb8 100644
--- a/reconfigure/parsers/ini.py
+++ b/reconfigure/parsers/ini.py
@@ -1,4 +1,4 @@
-import six
+import sys
from reconfigure.nodes import *
from reconfigure.parsers import BaseParser
@@ -44,6 +44,7 @@ class IniFileParser (BaseParser):
name = None
section_node = Node(name)
section_node.comment = self._get_comment(cp[section]._lines[0])
+ section_node._extra_content = {}
for option in cp[section]:
if option in cp[section]._options:
node = PropertyNode(option, cp[section][option])
@@ -66,10 +67,15 @@ class IniFileParser (BaseParser):
cp[sectionname][option.name] = option.value
if option.comment:
self._set_comment(cp[sectionname]._options[option.name], option.comment)
+
+ if section._extra_content:
+ for k, v in section._extra_content.items():
+ cp[sectionname][k] = v
+
if hasattr(cp[sectionname], '_lines'):
self._set_comment(cp[sectionname]._lines[0], section.comment)
- data = (str if six.PY3 else unicode)(cp) + u'\n'
+ data = (str if sys.version_info[0] >= 3 else unicode)(cp) + u'\n'
if self.sectionless:
data = data.replace('[' + self.nullsection + ']\n', '')
return data
diff --git a/reconfigure/parsers/nginx.py b/reconfigure/parsers/nginx.py
index 421a483..06b18b4 100644
--- a/reconfigure/parsers/nginx.py
+++ b/reconfigure/parsers/nginx.py
@@ -9,8 +9,8 @@ class NginxParser (BaseParser):
"""
tokens = [
- (r"[\w_]+\s*?.*?{", lambda s, t: ('section_start', t)),
- (r"[\w_]+?.+?;", lambda s, t: ('option', t)),
+ (r"[\w_]+\s*?[^\n]*?{", lambda s, t: ('section_start', t)),
+ (r"[\w_]+?(?:[^\"]+?(?:\".*?\")?)+?;", lambda s, t: ('option', t)),
(r"\s", lambda s, t: 'whitespace'),
(r"$^", lambda s, t: 'newline'),
(r"\#.*?\n", lambda s, t: ('comment', t)),
@@ -20,7 +20,7 @@ class NginxParser (BaseParser):
token_section_end = '}'
def parse(self, content):
- scanner = re.Scanner(self.tokens)
+ scanner = re.Scanner(self.tokens, re.DOTALL)
tokens, remainder = scanner.scan(' '.join(filter(None, content.split(' '))))
if remainder:
raise Exception('Invalid tokens: %s. Tokens: %s' % (remainder, tokens))
diff --git a/reconfigure/tests/configs/netatalk_tests.py b/reconfigure/tests/configs/netatalk_tests.py
index d844e9c..30dfcd0 100644
--- a/reconfigure/tests/configs/netatalk_tests.py
+++ b/reconfigure/tests/configs/netatalk_tests.py
@@ -35,6 +35,8 @@ file perm=0755
"password": '',
"file_perm": '0755',
"directory_perm": '',
+ "rolist": '',
+ "rwlist": '',
}
]
}
diff --git a/reconfigure/tests/parsers/ini_tests.py b/reconfigure/tests/parsers/ini_tests.py
index cdb3c02..76a216c 100644
--- a/reconfigure/tests/parsers/ini_tests.py
+++ b/reconfigure/tests/parsers/ini_tests.py
@@ -18,9 +18,17 @@ s1p2=123
Node('section1',
PropertyNode('s1p1', 'asd', comment='comment 2'),
PropertyNode('s1p2', '123'),
- comment='section comment'
+ comment='section comment',
+ extra_content={'c': 'd'},
),
)
+ stringified = """a=b
+
+[section1] ;section comment
+s1p1=asd ;comment 2
+s1p2=123
+c=d
+"""
del BaseParserTest