mirror of
https://github.com/ARM-software/devlib.git
synced 2025-09-07 04:21:54 +01:00
Add support for Python 3
Add support for running on Python 3 while maintaining Python 2 compatibility.
This commit is contained in:
committed by
Marc Bonnici
parent
0d63386343
commit
5cafd2ec4d
@@ -15,6 +15,8 @@
|
||||
import logging
|
||||
from inspect import isclass
|
||||
|
||||
from past.builtins import basestring
|
||||
|
||||
from devlib.utils.misc import walk_modules
|
||||
from devlib.utils.types import identifier
|
||||
|
||||
@@ -75,7 +77,7 @@ class BootModule(Module): # pylint: disable=R0921
|
||||
raise NotImplementedError()
|
||||
|
||||
def update(self, **kwargs):
|
||||
for name, value in kwargs.iteritems():
|
||||
for name, value in kwargs.items():
|
||||
if not hasattr(self, name):
|
||||
raise ValueError('Unknown parameter "{}" for {}'.format(name, self.name))
|
||||
self.logger.debug('Updating "{}" to "{}"'.format(name, value))
|
||||
@@ -117,6 +119,6 @@ def register_module(mod):
|
||||
|
||||
def __load_cache():
|
||||
for module in walk_modules('devlib.module'):
|
||||
for obj in vars(module).itervalues():
|
||||
for obj in vars(module).values():
|
||||
if isclass(obj) and issubclass(obj, Module) and obj.name:
|
||||
register_module(obj)
|
||||
|
@@ -63,7 +63,7 @@ class FastbootFlashModule(FlashModule):
|
||||
image_bundle = expand_path(image_bundle)
|
||||
to_flash = self._bundle_to_images(image_bundle)
|
||||
to_flash = merge_dicts(to_flash, images or {}, should_normalize=False)
|
||||
for partition, image_path in to_flash.iteritems():
|
||||
for partition, image_path in to_flash.items():
|
||||
self.logger.debug('flashing {}'.format(partition))
|
||||
self._flash_image(self.target, partition, expand_path(image_path))
|
||||
fastboot_command('reboot')
|
||||
|
@@ -325,7 +325,7 @@ class CGroup(object):
|
||||
def get_tasks(self):
|
||||
task_ids = self.target.read_value(self.tasks_file).split()
|
||||
logging.debug('Tasks: %s', task_ids)
|
||||
return map(int, task_ids)
|
||||
return list(map(int, task_ids))
|
||||
|
||||
def add_task(self, tid):
|
||||
self.target.write_value(self.tasks_file, tid, verify=False)
|
||||
|
@@ -150,7 +150,7 @@ class CpufreqModule(Module):
|
||||
if governor is None:
|
||||
governor = self.get_governor(cpu)
|
||||
valid_tunables = self.list_governor_tunables(cpu)
|
||||
for tunable, value in kwargs.iteritems():
|
||||
for tunable, value in kwargs.items():
|
||||
if tunable in valid_tunables:
|
||||
path = '/sys/devices/system/cpu/{}/cpufreq/{}/{}'.format(cpu, governor, tunable)
|
||||
try:
|
||||
@@ -176,7 +176,7 @@ class CpufreqModule(Module):
|
||||
try:
|
||||
cmd = 'cat /sys/devices/system/cpu/{}/cpufreq/scaling_available_frequencies'.format(cpu)
|
||||
output = self.target.execute(cmd)
|
||||
available_frequencies = map(int, output.strip().split()) # pylint: disable=E1103
|
||||
available_frequencies = list(map(int, output.strip().split())) # pylint: disable=E1103
|
||||
except TargetError:
|
||||
# On some devices scaling_frequencies is not generated.
|
||||
# http://adrynalyne-teachtofish.blogspot.co.uk/2011/11/how-to-enable-scalingavailablefrequenci.html
|
||||
@@ -190,7 +190,7 @@ class CpufreqModule(Module):
|
||||
return []
|
||||
raise
|
||||
|
||||
available_frequencies = map(int, reversed([f for f, _ in zip(out_iter, out_iter)]))
|
||||
available_frequencies = list(map(int, reversed([f for f, _ in zip(out_iter, out_iter)])))
|
||||
return available_frequencies
|
||||
|
||||
@memoized
|
||||
@@ -478,7 +478,7 @@ class CpufreqModule(Module):
|
||||
"""
|
||||
cpus = set(range(self.target.number_of_cpus))
|
||||
while cpus:
|
||||
cpu = iter(cpus).next()
|
||||
cpu = next(iter(cpus))
|
||||
domain = self.target.cpufreq.get_related_cpus(cpu)
|
||||
yield domain
|
||||
cpus = cpus.difference(domain)
|
||||
|
@@ -13,6 +13,8 @@
|
||||
# limitations under the License.
|
||||
#
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
from past.builtins import basestring
|
||||
|
||||
from devlib.module import Module
|
||||
from devlib.utils.misc import memoized
|
||||
from devlib.utils.types import integer, boolean
|
||||
|
@@ -75,7 +75,7 @@ class Gem5StatsModule(Module):
|
||||
raise KeyError('ROI label {} already used'.format(label))
|
||||
if len(self.rois) >= GEM5STATS_ROI_NUMBER:
|
||||
raise RuntimeError('Too many ROIs reserved')
|
||||
all_rois = set(xrange(GEM5STATS_ROI_NUMBER))
|
||||
all_rois = set(range(GEM5STATS_ROI_NUMBER))
|
||||
used_rois = set([roi.number for roi in self.rois.values()])
|
||||
avail_rois = all_rois - used_rois
|
||||
self.rois[label] = Gem5ROI(list(avail_rois)[0], self.target)
|
||||
@@ -223,7 +223,7 @@ class Gem5StatsModule(Module):
|
||||
'''
|
||||
with open(self._stats_file_path, 'r') as stats_file:
|
||||
# _goto_dump reach EOF and returns the total number of dumps + 1
|
||||
return self._goto_dump(stats_file, sys.maxint)
|
||||
return self._goto_dump(stats_file, sys.maxsize)
|
||||
|
||||
def _goto_dump(self, stats_file, target_dump):
|
||||
if target_dump < 0:
|
||||
@@ -243,7 +243,7 @@ class Gem5StatsModule(Module):
|
||||
dump_iterator = iter_statistics_dump(stats_file)
|
||||
while curr_dump < target_dump:
|
||||
try:
|
||||
dump = dump_iterator.next()
|
||||
dump = next(dump_iterator)
|
||||
except StopIteration:
|
||||
break
|
||||
# End of passed dump is beginning og next one
|
||||
|
@@ -26,7 +26,7 @@ class GpufreqModule(Module):
|
||||
def __init__(self, target):
|
||||
super(GpufreqModule, self).__init__(target)
|
||||
frequencies_str = self.target.read_value("/sys/kernel/gpu/gpu_freq_table")
|
||||
self.frequencies = map(int, frequencies_str.split(" "))
|
||||
self.frequencies = list(map(int, frequencies_str.split(" ")))
|
||||
self.frequencies.sort()
|
||||
self.governors = self.target.read_value("/sys/kernel/gpu/gpu_available_governor").split(" ")
|
||||
|
||||
|
@@ -75,8 +75,8 @@ class HwmonDevice(object):
|
||||
@property
|
||||
def sensors(self):
|
||||
all_sensors = []
|
||||
for sensors_of_kind in self._sensors.itervalues():
|
||||
all_sensors.extend(sensors_of_kind.values())
|
||||
for sensors_of_kind in self._sensors.values():
|
||||
all_sensors.extend(list(sensors_of_kind.values()))
|
||||
return all_sensors
|
||||
|
||||
def __init__(self, target, path, name, fields):
|
||||
@@ -100,7 +100,7 @@ class HwmonDevice(object):
|
||||
|
||||
def get(self, kind, number=None):
|
||||
if number is None:
|
||||
return [s for _, s in sorted(self._sensors[kind].iteritems(),
|
||||
return [s for _, s in sorted(self._sensors[kind].items(),
|
||||
key=lambda x: x[0])]
|
||||
else:
|
||||
return self._sensors[kind].get(number)
|
||||
@@ -139,7 +139,7 @@ class HwmonModule(Module):
|
||||
|
||||
def scan(self):
|
||||
values_tree = self.target.read_tree_values(self.root, depth=3)
|
||||
for entry_id, fields in values_tree.iteritems():
|
||||
for entry_id, fields in values_tree.items():
|
||||
path = self.target.path.join(self.root, entry_id)
|
||||
name = fields.pop('name', None)
|
||||
if name is None:
|
||||
|
@@ -100,5 +100,5 @@ class ThermalModule(Module):
|
||||
|
||||
def disable_all_zones(self):
|
||||
"""Disables all the thermal zones in the target"""
|
||||
for zone in self.zones.itervalues():
|
||||
for zone in self.zones.values():
|
||||
zone.set_enabled(False)
|
||||
|
@@ -251,7 +251,7 @@ class VexpressUBoot(VexpressBootModule):
|
||||
menu = UbootMenu(tty)
|
||||
self.logger.debug('Waiting for U-Boot prompt...')
|
||||
menu.open(timeout=120)
|
||||
for var, value in self.env.iteritems():
|
||||
for var, value in self.env.items():
|
||||
menu.setenv(var, value)
|
||||
menu.boot()
|
||||
|
||||
@@ -338,7 +338,7 @@ class VersatileExpressFlashModule(FlashModule):
|
||||
if images:
|
||||
self._overlay_images(images)
|
||||
os.system('sync')
|
||||
except (IOError, OSError), e:
|
||||
except (IOError, OSError) as e:
|
||||
msg = 'Could not deploy images to {}; got: {}'
|
||||
raise TargetError(msg.format(self.vemsd_mount, e))
|
||||
self.target.boot()
|
||||
@@ -352,7 +352,7 @@ class VersatileExpressFlashModule(FlashModule):
|
||||
tar.extractall(self.vemsd_mount)
|
||||
|
||||
def _overlay_images(self, images):
|
||||
for dest, src in images.iteritems():
|
||||
for dest, src in images.items():
|
||||
dest = os.path.join(self.vemsd_mount, dest)
|
||||
self.logger.debug('Copying {} to {}'.format(src, dest))
|
||||
shutil.copy(src, dest)
|
||||
@@ -379,7 +379,7 @@ def wait_for_vemsd(vemsd_mount, tty, mcc_prompt=DEFAULT_MCC_PROMPT, short_delay=
|
||||
path = os.path.join(vemsd_mount, 'config.txt')
|
||||
if os.path.exists(path):
|
||||
return
|
||||
for _ in xrange(attempts):
|
||||
for _ in range(attempts):
|
||||
tty.sendline('') # clear any garbage
|
||||
tty.expect(mcc_prompt, timeout=short_delay)
|
||||
tty.sendline('usb_on')
|
||||
|
Reference in New Issue
Block a user