summaryrefslogtreecommitdiff
path: root/reconfigure
diff options
context:
space:
mode:
authorAndrew Shadura <andrew@shadura.me>2015-08-20 16:04:48 +0200
committerAndrew Shadura <andrew@shadura.me>2015-08-20 16:04:48 +0200
commit2989b4c027b3230b1778e3777d2cce53c89808d9 (patch)
treeeaae33622a6ced0a09a5610d79ab9d54e77a5a9f /reconfigure
parent1e93e1498efdfd85a599a7e831f4a3a55f78aa75 (diff)
Imported Upstream version 0.1.74+git49a20890
Diffstat (limited to 'reconfigure')
-rw-r--r--reconfigure/__init__.py2
-rw-r--r--reconfigure/configs/base.py5
-rw-r--r--reconfigure/items/group.py12
-rw-r--r--reconfigure/items/passwd.py12
-rw-r--r--reconfigure/parsers/ini.py4
5 files changed, 32 insertions, 3 deletions
diff --git a/reconfigure/__init__.py b/reconfigure/__init__.py
index 69f79d2..a52a5aa 100644
--- a/reconfigure/__init__.py
+++ b/reconfigure/__init__.py
@@ -1 +1 @@
-__version__ = "0.1.67"
+__version__ = "0.1.74"
diff --git a/reconfigure/configs/base.py b/reconfigure/configs/base.py
index 5d0bb61..fc2ce6f 100644
--- a/reconfigure/configs/base.py
+++ b/reconfigure/configs/base.py
@@ -1,4 +1,6 @@
import chardet
+import six
+import sys
class Reconfig (object):
@@ -36,7 +38,8 @@ class Reconfig (object):
self.content = open(self.origin, 'r').read()
self.encoding = 'utf8'
- if hasattr(self.content, 'decode'): # str (2) or bytes (3)
+ if (six.PY3 and isinstance(self.content, bytes)) or \
+ (six.PY2 and isinstance(self.content, str)):
try:
self.content = self.content.decode('utf8')
except (UnicodeDecodeError, AttributeError):
diff --git a/reconfigure/items/group.py b/reconfigure/items/group.py
index f95b28a..107bc64 100644
--- a/reconfigure/items/group.py
+++ b/reconfigure/items/group.py
@@ -1,3 +1,4 @@
+from reconfigure.nodes import Node, PropertyNode
from reconfigure.items.bound import BoundData
@@ -8,6 +9,17 @@ class GroupsData (BoundData):
class GroupData (BoundData):
fields = ['name', 'password', 'gid', 'users']
+ def template(self):
+ return Node(
+ 'line',
+ *[
+ Node('token', children=[
+ PropertyNode('value', '')
+ ])
+ for x in GroupData.fields
+ ]
+ )
+
GroupsData.bind_collection('groups', item_class=GroupData)
for i in range(0, len(GroupData.fields)):
diff --git a/reconfigure/items/passwd.py b/reconfigure/items/passwd.py
index 147bc8a..6943300 100644
--- a/reconfigure/items/passwd.py
+++ b/reconfigure/items/passwd.py
@@ -1,3 +1,4 @@
+from reconfigure.nodes import Node, PropertyNode
from reconfigure.items.bound import BoundData
@@ -8,6 +9,17 @@ class PasswdData (BoundData):
class UserData (BoundData):
fields = ['name', 'password', 'uid', 'gid', 'comment', 'home', 'shell']
+ def template(self):
+ return Node(
+ 'line',
+ *[
+ Node('token', children=[
+ PropertyNode('value', '')
+ ])
+ for x in UserData.fields
+ ]
+ )
+
PasswdData.bind_collection('users', item_class=UserData)
for i in range(0, len(UserData.fields)):
diff --git a/reconfigure/parsers/ini.py b/reconfigure/parsers/ini.py
index 2f3b82e..2f95d33 100644
--- a/reconfigure/parsers/ini.py
+++ b/reconfigure/parsers/ini.py
@@ -1,3 +1,5 @@
+import six
+
from reconfigure.nodes import *
from reconfigure.parsers import BaseParser
from reconfigure.parsers.iniparse import INIConfig
@@ -67,7 +69,7 @@ class IniFileParser (BaseParser):
if hasattr(cp[sectionname], '_lines'):
self._set_comment(cp[sectionname]._lines[0], section.comment)
- data = str(cp) + '\n'
+ data = (str if six.PY3 else unicode)(cp) + u'\n'
if self.sectionless:
data = data.replace('[' + self.nullsection + ']\n', '')
return data