Skip to content

Commit d2b9681

Browse files
committed
Updates to *.py in 'tools/' for Python 3
1 parent e723571 commit d2b9681

File tree

7 files changed

+31
-30
lines changed

7 files changed

+31
-30
lines changed

tools/device_management.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ def inner(options):
115115
# Get the currently in-use API key (may come from environment or
116116
# configuration files, which is handled by the cloud SDK)
117117
api_key_value = accounts.config.get("api_key")
118-
api_key = accounts.list_api_keys(
118+
api_key = next(accounts.list_api_keys(
119119
filter={
120120
"key": api_key_value
121121
}
122-
).next()
122+
))
123123
certificates_owned = list(certs.list_certificates())
124124
dev_cert_info = None
125125
for certif in certificates_owned:

tools/memap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from prettytable import PrettyTable, HEADER
3434
from jinja2 import FileSystemLoader, StrictUndefined
3535
from jinja2.environment import Environment
36+
from future.utils import with_metaclass
3637

3738

3839
# Be sure that the tools directory is in the search path
@@ -46,9 +47,8 @@
4647
) # noqa: E402
4748

4849

49-
class _Parser(object):
50+
class _Parser(with_metaclass(ABCMeta, object)):
5051
"""Internal interface for parsing"""
51-
__metaclass__ = ABCMeta
5252
SECTIONS = ('.text', '.data', '.bss', '.heap', '.stack')
5353
MISC_FLASH_SECTIONS = ('.interrupts', '.flash_config')
5454
OTHER_SECTIONS = ('.interrupts_ram', '.init', '.ARM.extab',
@@ -76,7 +76,7 @@ def module_add(self, object_name, size, section):
7676
return
7777

7878
obj_split = sep + basename(object_name)
79-
for module_path, contents in self.modules.items():
79+
for module_path, contents in list(self.modules.items()):
8080
if module_path.endswith(obj_split) or module_path == object_name:
8181
contents.setdefault(section, 0)
8282
contents[section] += size

tools/singletest.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,14 @@ def get_version():
103103

104104
# Print scrip version
105105
if opts.version:
106-
print parser.description
107-
print parser.epilog
108-
print "Version %d.%d"% get_version()
106+
print(parser.description)
107+
print(parser.epilog)
108+
print("Version %d.%d"% get_version())
109109
exit(0)
110110

111111
# Print summary / information about automation test status
112112
if opts.test_automation_report:
113-
print get_avail_tests_summary_table(platform_filter=opts.general_filter_regex)
113+
print(get_avail_tests_summary_table(platform_filter=opts.general_filter_regex))
114114
exit(0)
115115

116116
# Print summary / information about automation test status
@@ -122,15 +122,15 @@ def get_version():
122122
'host_test',
123123
'duration',
124124
'source_dir']
125-
print get_avail_tests_summary_table(cols=test_case_report_cols,
125+
print(get_avail_tests_summary_table(cols=test_case_report_cols,
126126
result_summary=False,
127127
join_delim='\n',
128-
platform_filter=opts.general_filter_regex)
128+
platform_filter=opts.general_filter_regex))
129129
exit(0)
130130

131131
# Only prints matrix of supported toolchains
132132
if opts.supported_toolchains:
133-
print mcu_toolchain_matrix(platform_filter=opts.general_filter_regex)
133+
print(mcu_toolchain_matrix(platform_filter=opts.general_filter_regex))
134134
exit(0)
135135

136136
test_spec = None
@@ -139,14 +139,14 @@ def get_version():
139139
if hasattr(opts, 'auto_detect') and opts.auto_detect:
140140
# If auto_detect attribute is present, we assume other auto-detection
141141
# parameters like 'toolchains_filter' are also set.
142-
print "MBEDLS: Detecting connected mbed-enabled devices... "
142+
print("MBEDLS: Detecting connected mbed-enabled devices... ")
143143

144144
MUTs = get_autodetected_MUTS_list()
145145

146146
for mut in MUTs.values():
147-
print "MBEDLS: Detected %s, port: %s, mounted: %s"% (mut['mcu_unique'] if 'mcu_unique' in mut else mut['mcu'],
147+
print("MBEDLS: Detected %s, port: %s, mounted: %s"% (mut['mcu_unique'] if 'mcu_unique' in mut else mut['mcu'],
148148
mut['port'],
149-
mut['disk'])
149+
mut['disk']))
150150

151151
# Set up parameters for test specification filter function (we need to set toolchains per target here)
152152
use_default_toolchain = 'default' in opts.toolchains_filter if opts.toolchains_filter is not None else True
@@ -179,13 +179,13 @@ def get_version():
179179
exit(-1)
180180

181181
if opts.verbose_test_configuration_only:
182-
print "MUTs configuration in %s:" % ('auto-detected' if opts.auto_detect else opts.muts_spec_filename)
182+
print("MUTs configuration in %s:" % ('auto-detected' if opts.auto_detect else opts.muts_spec_filename))
183183
if MUTs:
184-
print print_muts_configuration_from_json(MUTs, platform_filter=opts.general_filter_regex)
185-
print
186-
print "Test specification in %s:" % ('auto-detected' if opts.auto_detect else opts.test_spec_filename)
184+
print(print_muts_configuration_from_json(MUTs, platform_filter=opts.general_filter_regex))
185+
print()
186+
print("Test specification in %s:" % ('auto-detected' if opts.auto_detect else opts.test_spec_filename))
187187
if test_spec:
188-
print print_test_configuration_from_json(test_spec)
188+
print(print_test_configuration_from_json(test_spec))
189189
exit(0)
190190

191191
if get_module_avail('mbed_lstools'):
@@ -201,16 +201,16 @@ def get_version():
201201
report_exporter = ReportExporter(ResultExporterType.JUNIT_OPER)
202202
report_exporter.report_to_file(test_results, opts.report_junit_file_name)
203203
else:
204-
print "Unknown interoperability test scope name: '%s'" % (opts.operability_checks)
205-
print "Available test scopes: %s" % (','.join(["'%s'" % n for n in test_scope]))
204+
print("Unknown interoperability test scope name: '%s'" % (opts.operability_checks))
205+
print("Available test scopes: %s" % (','.join(["'%s'" % n for n in test_scope])))
206206

207207
exit(0)
208208

209209
# Verbose test specification and MUTs configuration
210210
if MUTs and opts.verbose:
211-
print print_muts_configuration_from_json(MUTs)
211+
print(print_muts_configuration_from_json(MUTs))
212212
if test_spec and opts.verbose:
213-
print print_test_configuration_from_json(test_spec)
213+
print(print_test_configuration_from_json(test_spec))
214214

215215
if opts.only_build_tests:
216216
# We are skipping testing phase, and suppress summary

tools/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def main():
312312

313313
# Print memory map summary on screen
314314
if build_report:
315-
print
315+
print()
316316
print(print_build_memory_usage(build_report))
317317

318318
print_report_exporter = ReportExporter(ResultExporterType.PRINT, package="build")

tools/test_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,11 +1461,11 @@ def get_avail_tests_summary_table(cols=None, result_summary=True, join_delim=','
14611461
def progress_bar(percent_progress, saturation=0):
14621462
""" This function creates progress bar with optional simple saturation mark
14631463
"""
1464-
step = int(percent_progress / 2) # Scale by to (scale: 1 - 50)
1464+
step = percent_progress // 2 # Scale by to (scale: 1 - 50)
14651465
str_progress = '#' * step + '.' * int(50 - step)
14661466
c = '!' if str_progress[38] == '.' else '|'
14671467
if saturation > 0:
1468-
saturation = saturation / 2
1468+
saturation = saturation // 2
14691469
str_progress = str_progress[:saturation] + c + str_progress[saturation:]
14701470
return str_progress
14711471

@@ -1517,7 +1517,7 @@ def singletest_in_cli_mode(single_test):
15171517
# Returns True if no build failures of the test projects or their dependencies
15181518
return status
15191519

1520-
class TestLogger():
1520+
class TestLogger(object):
15211521
""" Super-class for logging and printing ongoing events for test suite pass
15221522
"""
15231523
def __init__(self, store_log=True):

tools/test_exporters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
PRINT='Print_Exporter')
3030

3131

32-
class ReportExporter():
32+
class ReportExporter(object):
3333
""" Class exports extended test result Python data structure to
3434
different formats like HTML, JUnit XML.
3535

tools/tests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
"""
17+
from past.builtins import cmp
1718
from tools.paths import *
1819
from argparse import ArgumentTypeError
1920
from tools.utils import columnate
@@ -857,7 +858,7 @@
857858
TEST_GROUPS = {}
858859
GROUPS.update(TEST_GROUPS)
859860

860-
class Test:
861+
class Test(object):
861862
DEFAULTS = {
862863
#'mcu': None,
863864
'description': None,

0 commit comments

Comments
 (0)