summaryrefslogtreecommitdiff
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
commitb456fa7c572104fc85170734c84269dddbeda455 (patch)
treed9291315926e69e6f40df72525ebb295f77126dd
parenta6842a40e99bdb047c83ce2006364ec89b0108df (diff)
parent2989b4c027b3230b1778e3777d2cce53c89808d9 (diff)
Merge tag 'upstream/0.1.74+git49a20890'
Upstream version 0.1.74+git49a20890
-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
-rw-r--r--requirements.txt3
-rw-r--r--setup.py1
7 files changed, 35 insertions, 4 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
diff --git a/requirements.txt b/requirements.txt
index 983a631..a5f2273 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1,3 @@
chardet
-nose \ No newline at end of file
+nose
+six
diff --git a/setup.py b/setup.py
index 29eb023..f58484f 100644
--- a/setup.py
+++ b/setup.py
@@ -10,6 +10,7 @@ setup(
version=__version__,
install_requires=[
'chardet',
+ 'six',
],
description='An ORM for config files',
license='LGPLv3',