summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2013-04-10 10:29:35 -0500
committerSol Jerome <sol.jerome@gmail.com>2013-04-10 10:32:27 -0500
commitbfeba47ec3f33c78f44679426f682ee7a928cd05 (patch)
tree151ec1345a0527a0008d583c586ea0fea9f74ec8
parent2cb245f4ebf5dbd37f11f02a7d1598b050799515 (diff)
downloadbcfg2-py3k.tar.gz
bcfg2-py3k.tar.bz2
bcfg2-py3k.zip
PY3K: Fix client/server to work with python 3py3k
Signed-off-by: Sol Jerome <sol.jerome@gmail.com> (cherry picked from commit c313bf1d75ae4fa885cd099f299177d84dd8a95d)
-rw-r--r--src/lib/Bcfg2/Client/Client.py14
-rw-r--r--src/lib/Bcfg2/Server/BuiltinCore.py2
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py2
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Probes.py16
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Reporting.py2
5 files changed, 26 insertions, 10 deletions
diff --git a/src/lib/Bcfg2/Client/Client.py b/src/lib/Bcfg2/Client/Client.py
index 613e10e75..fad2af575 100644
--- a/src/lib/Bcfg2/Client/Client.py
+++ b/src/lib/Bcfg2/Client/Client.py
@@ -15,7 +15,7 @@ import Bcfg2.Client.XML
import Bcfg2.Client.Frame
import Bcfg2.Client.Tools
from Bcfg2.Utils import locked, Executor
-from Bcfg2.Compat import xmlrpclib
+from Bcfg2.Compat import xmlrpclib, u_str
from Bcfg2.version import __version__
@@ -91,7 +91,10 @@ class Client(object):
try:
script.write("#!%s\n" %
(probe.attrib.get('interpreter', '/bin/sh')))
- script.write(probe.text.encode('utf-8'))
+ if sys.hexversion >= 0x03000000:
+ script.write(probe.text)
+ else:
+ script.write(probe.text.encode('utf-8'))
script.close()
os.chmod(scriptname,
stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH |
@@ -105,7 +108,10 @@ class Client(object):
self._probe_failure(name, "Return value %s" % rv)
self.logger.info("Probe %s has result:" % name)
self.logger.info(rv.stdout)
- ret.text = rv.stdout.decode('utf-8')
+ if sys.hexversion >= 0x03000000:
+ ret.text = rv.stdout
+ else:
+ ret.text = rv.stdout.decode('utf-8')
finally:
os.unlink(scriptname)
except SystemExit:
@@ -247,7 +253,7 @@ class Client(object):
self.logger.info("Starting Bcfg2 client run at %s" % times['start'])
- rawconfig = self.get_config(times=times)
+ rawconfig = self.get_config(times=times).decode('utf-8')
if self.setup['cache']:
try:
diff --git a/src/lib/Bcfg2/Server/BuiltinCore.py b/src/lib/Bcfg2/Server/BuiltinCore.py
index 4d7453840..35ebc9fe6 100644
--- a/src/lib/Bcfg2/Server/BuiltinCore.py
+++ b/src/lib/Bcfg2/Server/BuiltinCore.py
@@ -12,7 +12,7 @@ from Bcfg2.SSLServer import XMLRPCServer
from lockfile import LockFailed
# pylint: disable=E0611
try:
- from daemon.pidfile import PIDLockFile
+ from lockfile.pidlockfile import PIDLockFile
except ImportError:
from daemon.pidlockfile import PIDLockFile
# pylint: enable=E0611
diff --git a/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py b/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py
index 926172e57..ffe93c25b 100644
--- a/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py
+++ b/src/lib/Bcfg2/Server/Plugins/Cfg/__init__.py
@@ -599,6 +599,8 @@ class CfgEntrySet(Bcfg2.Server.Plugin.EntrySet,
else:
try:
if not isinstance(data, unicode):
+ if not isinstance(data, str):
+ data = data.decode('utf-8')
data = u_str(data, self.encoding)
except UnicodeDecodeError:
msg = "Failed to decode %s: %s" % (entry.get('name'),
diff --git a/src/lib/Bcfg2/Server/Plugins/Probes.py b/src/lib/Bcfg2/Server/Plugins/Probes.py
index 55e5ddc47..201b4ec70 100644
--- a/src/lib/Bcfg2/Server/Plugins/Probes.py
+++ b/src/lib/Bcfg2/Server/Plugins/Probes.py
@@ -155,7 +155,10 @@ class ProbeSet(Bcfg2.Server.Plugin.EntrySet):
probe.set('source', self.plugin_name)
if (metadata.version_info and
metadata.version_info > (1, 3, 1, '', 0)):
- probe.text = entry.data.decode('utf-8')
+ try:
+ probe.text = entry.data.decode('utf-8')
+ except AttributeError:
+ probe.text = entry.data
else:
try:
probe.text = entry.data
@@ -219,9 +222,14 @@ class Probes(Bcfg2.Server.Plugin.Probing,
lxml.etree.SubElement(top, 'Client', name=client,
timestamp=str(int(probedata.timestamp)))
for probe in sorted(probedata):
- lxml.etree.SubElement(
- ctag, 'Probe', name=probe,
- value=str(self.probedata[client][probe]).decode('utf-8'))
+ try:
+ lxml.etree.SubElement(
+ ctag, 'Probe', name=probe,
+ value=str(self.probedata[client][probe]).decode('utf-8'))
+ except AttributeError:
+ lxml.etree.SubElement(
+ ctag, 'Probe', name=probe,
+ value=str(self.probedata[client][probe]))
for group in sorted(self.cgroups[client]):
lxml.etree.SubElement(ctag, "Group", name=group)
try:
diff --git a/src/lib/Bcfg2/Server/Plugins/Reporting.py b/src/lib/Bcfg2/Server/Plugins/Reporting.py
index 3bd6fd14f..3354763d4 100644
--- a/src/lib/Bcfg2/Server/Plugins/Reporting.py
+++ b/src/lib/Bcfg2/Server/Plugins/Reporting.py
@@ -96,7 +96,7 @@ class Reporting(Statistics, Threaded, PullSource, Debuggable):
client.hostname, cdata,
lxml.etree.tostring(
stats,
- xml_declaration=False).decode('UTF-8'))
+ xml_declaration=False))
self.debug_log("%s: Queued statistics data for %s" %
(self.__class__.__name__, client.hostname))
return