From b50a7a9f6a102709eacd1335c00a1e0d0b259b8e Mon Sep 17 00:00:00 2001 From: Andrew Shadura Date: Wed, 25 Apr 2018 14:33:27 +0200 Subject: New upstream version 0.1.81+git20171214.2b8729a8 --- reconfigure/__init__.py | 3 ++- reconfigure/configs/base.py | 5 ++--- reconfigure/items/bound.py | 3 +++ reconfigure/items/netatalk.py | 4 ++-- reconfigure/items/samba.py | 7 +++++-- reconfigure/nodes.py | 3 ++- reconfigure/parsers/ini.py | 10 ++++++++-- reconfigure/parsers/nginx.py | 6 +++--- reconfigure/tests/configs/netatalk_tests.py | 2 ++ reconfigure/tests/parsers/ini_tests.py | 10 +++++++++- 10 files changed, 38 insertions(+), 15 deletions(-) (limited to 'reconfigure') 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 -- cgit v1.2.3