diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-08-21 13:32:51 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-08-21 13:33:20 -0400 |
commit | 22016ee593d6047855964734a17120d2aea6b5a5 (patch) | |
tree | 92adbca098e89295d4217561ee53454134b781a2 /src/lib/Bcfg2/Client/Tools/POSIX | |
parent | d6bf20100848dc61b971844e21d24da44b9f65f7 (diff) | |
download | bcfg2-22016ee593d6047855964734a17120d2aea6b5a5.tar.gz bcfg2-22016ee593d6047855964734a17120d2aea6b5a5.tar.bz2 bcfg2-22016ee593d6047855964734a17120d2aea6b5a5.zip |
lots of various py3k fixes
Diffstat (limited to 'src/lib/Bcfg2/Client/Tools/POSIX')
-rw-r--r-- | src/lib/Bcfg2/Client/Tools/POSIX/Device.py | 2 | ||||
-rw-r--r-- | src/lib/Bcfg2/Client/Tools/POSIX/Directory.py | 2 | ||||
-rw-r--r-- | src/lib/Bcfg2/Client/Tools/POSIX/File.py | 24 | ||||
-rw-r--r-- | src/lib/Bcfg2/Client/Tools/POSIX/Hardlink.py | 2 | ||||
-rw-r--r-- | src/lib/Bcfg2/Client/Tools/POSIX/Nonexistent.py | 2 | ||||
-rw-r--r-- | src/lib/Bcfg2/Client/Tools/POSIX/Permissions.py | 2 | ||||
-rw-r--r-- | src/lib/Bcfg2/Client/Tools/POSIX/Symlink.py | 2 | ||||
-rw-r--r-- | src/lib/Bcfg2/Client/Tools/POSIX/__init__.py | 2 |
8 files changed, 21 insertions, 17 deletions
diff --git a/src/lib/Bcfg2/Client/Tools/POSIX/Device.py b/src/lib/Bcfg2/Client/Tools/POSIX/Device.py index b8fb0f4d0..3ecef2cd7 100644 --- a/src/lib/Bcfg2/Client/Tools/POSIX/Device.py +++ b/src/lib/Bcfg2/Client/Tools/POSIX/Device.py @@ -1,6 +1,6 @@ import os import sys -from base import POSIXTool, device_map +from .base import POSIXTool, device_map class POSIXDevice(POSIXTool): __req__ = ['name', 'dev_type', 'perms', 'owner', 'group'] diff --git a/src/lib/Bcfg2/Client/Tools/POSIX/Directory.py b/src/lib/Bcfg2/Client/Tools/POSIX/Directory.py index 4b0ad93ef..27834a16d 100644 --- a/src/lib/Bcfg2/Client/Tools/POSIX/Directory.py +++ b/src/lib/Bcfg2/Client/Tools/POSIX/Directory.py @@ -3,7 +3,7 @@ import sys import stat import shutil import Bcfg2.Client.XML -from base import POSIXTool +from .base import POSIXTool class POSIXDirectory(POSIXTool): __req__ = ['name', 'perms', 'owner', 'group'] diff --git a/src/lib/Bcfg2/Client/Tools/POSIX/File.py b/src/lib/Bcfg2/Client/Tools/POSIX/File.py index 1b5535d28..bba72791d 100644 --- a/src/lib/Bcfg2/Client/Tools/POSIX/File.py +++ b/src/lib/Bcfg2/Client/Tools/POSIX/File.py @@ -3,10 +3,9 @@ import sys import stat import time import difflib -import binascii import tempfile -from base import POSIXTool -from Bcfg2.Bcfg2Py3k import unicode +from .base import POSIXTool +from Bcfg2.Bcfg2Py3k import unicode, b64encode, b64decode class POSIXFile(POSIXTool): __req__ = ['name', 'perms', 'owner', 'group'] @@ -20,6 +19,9 @@ class POSIXFile(POSIXTool): for char in strng: if ord(char) < 9 or ord(char) > 13 and ord(char) < 32: return False + if not hasattr(strng, "decode"): + # py3k + return True try: strng.decode(encoding) return True @@ -29,13 +31,14 @@ class POSIXFile(POSIXTool): def _get_data(self, entry): is_binary = False if entry.get('encoding', 'ascii') == 'base64': - tempdata = binascii.a2b_base64(entry.text) + tempdata = b64decode(entry.text) is_binary = True + elif entry.get('empty', 'false') == 'true': tempdata = '' else: tempdata = entry.text - if isinstance(tempdata, unicode): + if isinstance(tempdata, unicode) and unicode != str: try: tempdata = tempdata.encode(self.setup['encoding']) except UnicodeEncodeError: @@ -163,7 +166,7 @@ class POSIXFile(POSIXTool): if is_binary: # don't compute diffs if the file is binary prompt.append('Binary file, no printable diff') - attrs['current_bfile'] = binascii.b2a_base64(content) + attrs['current_bfile'] = b64encode(content) else: if interactive: diff = self._diff(content, self._get_data(entry)[0], @@ -171,8 +174,10 @@ class POSIXFile(POSIXTool): filename=entry.get("name")) if diff: udiff = ''.join(diff) + if hasattr(udiff, "decode"): + udiff = udiff.decode(self.setup['encoding']) try: - prompt.append(udiff.decode(self.setup['encoding'])) + prompt.append(udiff) except UnicodeEncodeError: prompt.append("Could not encode diff") else: @@ -182,10 +187,9 @@ class POSIXFile(POSIXTool): diff = self._diff(content, self._get_data(entry)[0], difflib.ndiff, filename=entry.get("name")) if diff: - attrs["current_bdiff"] = \ - binascii.b2a_base64("\n".join(diff)) + attrs["current_bdiff"] = b64encode("\n".join(diff)) else: - attrs['current_bfile'] = binascii.b2a_base64(content) + attrs['current_bfile'] = b64encode(content) if interactive: entry.set("qtext", "\n".join(prompt)) if not sensitive: diff --git a/src/lib/Bcfg2/Client/Tools/POSIX/Hardlink.py b/src/lib/Bcfg2/Client/Tools/POSIX/Hardlink.py index 569ca3445..060c9499e 100644 --- a/src/lib/Bcfg2/Client/Tools/POSIX/Hardlink.py +++ b/src/lib/Bcfg2/Client/Tools/POSIX/Hardlink.py @@ -1,6 +1,6 @@ import os import sys -from base import POSIXTool +from .base import POSIXTool class POSIXHardlink(POSIXTool): __req__ = ['name', 'to'] diff --git a/src/lib/Bcfg2/Client/Tools/POSIX/Nonexistent.py b/src/lib/Bcfg2/Client/Tools/POSIX/Nonexistent.py index 64a36cce4..42d4a4cb4 100644 --- a/src/lib/Bcfg2/Client/Tools/POSIX/Nonexistent.py +++ b/src/lib/Bcfg2/Client/Tools/POSIX/Nonexistent.py @@ -1,7 +1,7 @@ import os import sys import shutil -from base import POSIXTool +from .base import POSIXTool class POSIXNonexistent(POSIXTool): __req__ = ['name'] diff --git a/src/lib/Bcfg2/Client/Tools/POSIX/Permissions.py b/src/lib/Bcfg2/Client/Tools/POSIX/Permissions.py index c041b9ade..de2bee120 100644 --- a/src/lib/Bcfg2/Client/Tools/POSIX/Permissions.py +++ b/src/lib/Bcfg2/Client/Tools/POSIX/Permissions.py @@ -1,6 +1,6 @@ import os import sys -from base import POSIXTool +from .base import POSIXTool class POSIXPermissions(POSIXTool): __req__ = ['name', 'perms', 'owner', 'group'] diff --git a/src/lib/Bcfg2/Client/Tools/POSIX/Symlink.py b/src/lib/Bcfg2/Client/Tools/POSIX/Symlink.py index d5222513e..1a5abc652 100644 --- a/src/lib/Bcfg2/Client/Tools/POSIX/Symlink.py +++ b/src/lib/Bcfg2/Client/Tools/POSIX/Symlink.py @@ -1,6 +1,6 @@ import os import sys -from base import POSIXTool +from .base import POSIXTool class POSIXSymlink(POSIXTool): __req__ = ['name', 'to'] diff --git a/src/lib/Bcfg2/Client/Tools/POSIX/__init__.py b/src/lib/Bcfg2/Client/Tools/POSIX/__init__.py index 7e649a2c1..2e4a54475 100644 --- a/src/lib/Bcfg2/Client/Tools/POSIX/__init__.py +++ b/src/lib/Bcfg2/Client/Tools/POSIX/__init__.py @@ -7,7 +7,7 @@ import shutil import pkgutil from datetime import datetime import Bcfg2.Client.Tools -from base import POSIXTool +from .base import POSIXTool class POSIX(Bcfg2.Client.Tools.Tool): """POSIX File support code.""" |