Py3 compatibility fixes.

This commit is contained in:
Pedro Algarvio 2014-11-23 22:09:14 +00:00
parent f1e86e1cf4
commit be8e880672

View File

@ -6,9 +6,9 @@ See http://code.google.com/p/psutil.
:depends: - psutil Python module, version 0.3.0 or later
- python-utmp package (optional)
'''
from __future__ import absolute_import
# Import python libs
from __future__ import absolute_import
import time
import datetime
@ -16,6 +16,8 @@ import datetime
from salt.exceptions import SaltInvocationError, CommandExecutionError
# Import third party libs
import salt.ext.six as six
# pylint: disable=import-error
try:
import psutil
@ -23,6 +25,7 @@ try:
PSUTIL2 = psutil.version_info >= (2, 0)
except ImportError:
HAS_PSUTIL = False
# pylint: enable=import-error
def __virtual__():
@ -120,7 +123,7 @@ def top(num_processes=5, interval=3):
start_usage[process] = user + system
time.sleep(interval)
usage = set()
for process, start in start_usage.items():
for process, start in six.iteritems(start_usage):
try:
user, system = process.get_cpu_times()
except psutil.NoSuchProcess:
@ -144,9 +147,9 @@ def top(num_processes=5, interval=3):
'cpu': {},
'mem': {},
}
for key, value in process.get_cpu_times()._asdict().items():
for key, value in six.iteritems(process.get_cpu_times()._asdict()):
info['cpu'][key] = value
for key, value in process.get_memory_info()._asdict().items():
for key, value in six.iteritems(process.get_memory_info()._asdict()):
info['mem'][key] = value
result.append(info)