Commit 2ecf4a13 authored by Johan Ström's avatar Johan Ström

python3 compatability fixes

parent fad0d826
......@@ -9,9 +9,9 @@ import syslog
import sys
# Re-export each export module
from agoapp import *
from config import *
from agoconnection import *
from .agoapp import *
from .config import *
from .agoconnection import *
syslog.openlog(sys.argv[0], syslog.LOG_PID, syslog.LOG_DAEMON)
import logging
from six import PY2
# We want to keep C++ and Python ago-coding as similar as possible.
# In C++ we have levels TRACE and CRITICAL.
#
if PY2:
_logginglevelNames = logging._levelNames
else:
_logginglevelNames = logging._levelToName
# Add extra Trace level
TRACE = logging.TRACE = 5
logging._levelNames[TRACE] = TRACE
logging._levelNames['TRACE'] = TRACE
_logginglevelNames[TRACE] = TRACE
_logginglevelNames['TRACE'] = TRACE
# C++ impl has FATAL, in python we have CRITICAL
# Add this alias so we can use the same logging consts
FATAL = logging.FATAL = logging.CRITICAL
logging._levelNames[FATAL] = FATAL
logging._levelNames['FATAL'] = FATAL
_logginglevelNames[FATAL] = FATAL
_logginglevelNames['FATAL'] = FATAL
LOGGING_LOGGER_CLASS = logging.getLoggerClass()
......
......@@ -3,7 +3,7 @@ from __future__ import print_function
import agoclient._directories
import agoclient._logging
import argparse
import config
from . import config
import logging
import os.path
import signal
......@@ -70,7 +70,7 @@ class AgoApp:
parser.add_argument('--log-method', dest="log_method",
help='Where to log', choices=['console', 'syslog'])
facilities = SysLogHandler.facility_names.keys()
facilities = list(SysLogHandler.facility_names.keys())
facilities.sort()
parser.add_argument('--log-syslog-facility', dest="syslog_facility",
help='Which syslog facility to log to.',
......@@ -167,7 +167,7 @@ class AgoApp:
raise ConfigurationError("Invalid log_level %s" % lvl_name)
# ..and set it
lvl = logging._levelNames[lvl_name.upper()]
lvl = logging.getLevelName(lvl_name.upper())
root.setLevel(lvl)
# Find log method..
......
......@@ -266,7 +266,7 @@ class AgoConnection:
if inventory is not None and "devices" in inventory:
devices = inventory['devices']
for uuid in devices.keys():
for uuid in list(devices.keys()):
d = devices[uuid]
if d == None:
continue
......
......@@ -87,7 +87,7 @@ class AgoMqttTransport(agoclient.agotransport.AgoTransport):
if message.topic in self.pending_replies:
pending = self.pending_replies[message.topic]
c = pending['condition'] # type: threading.Condition
pending['reply'] = json.loads(message.payload)
pending['reply'] = json.loads(message.payload.decode('utf-8'))
c.notify()
return
......@@ -97,7 +97,7 @@ class AgoMqttTransport(agoclient.agotransport.AgoTransport):
self.log.trace("on_message for unknown topic ", message.topic)
return
self.queue.append(json.loads(message.payload))
self.queue.append(json.loads(message.payload.decode('utf-8')))
self.queue_condition.notify()
finally:
self.lock.release()
......@@ -114,7 +114,7 @@ class AgoMqttTransport(agoclient.agotransport.AgoTransport):
# wakeup thread
self.lock.acquire()
try:
for pending in self.pending_replies.values():
for pending in list(self.pending_replies.values()):
pending['condition'].notify()
self.queue_condition.notify()
finally:
......
......@@ -4,7 +4,7 @@ from augeas import Augeas
from threading import Lock
import logging
from _directories import *
from ._directories import *
# For old-style * exports
# Do not add new methods here; instead import what you really need
......@@ -131,7 +131,7 @@ def get_config_option(section, option, default_value=None, app=None):
if value:
# First match
return value
except ValueError, e:
except ValueError as e:
logging.error("Failed to read configuration from %s: %s",
aug_path, e)
finally:
......@@ -189,7 +189,7 @@ def set_config_option(section, option, value, app=None):
augeas.save()
return True
except IOError, exception:
except IOError as exception:
# Try to extract error
aug_err = augeas.match("/augeas//error")
e = []
......
......@@ -98,13 +98,13 @@ class ConfigTest(ConfigTestBase):
if os.getuid() == 0:
# TODO: Fix builders so they dont run as root, then change to self.fail instead.
#self.fail("You cannot run this test as. Also, do not develop as root!")
print "You cannot run this test as. Also, do not develop as root!"
print("You cannot run this test as. Also, do not develop as root!")
return
with open(config.get_config_path('conf.d/blocked.conf'), 'w') as f:
f.write("[blocked]\nnop=nop\n")
os.chmod(config.get_config_path('conf.d/blocked.conf'), 0444)
os.chmod(config.get_config_path('conf.d/blocked.conf'), 0o444)
self.assertEqual(gco('blocked', 'nop'), 'nop')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment