1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-09-02 03:12:34 +01:00

Add support for Python 3

Add support for running under Python 3, while maintaining compatibility
with Python 2.

See http://python-future.org/compatible_idioms.html for more details
behind these changes.
This commit is contained in:
Sergei Trofimov
2018-05-30 13:58:49 +01:00
committed by Marc Bonnici
parent c3ddb31d4d
commit b3de85455a
53 changed files with 377 additions and 384 deletions

View File

@@ -94,9 +94,9 @@ class CreateWorkloadSubcommand(SubCommand):
self.parser.add_argument('-f', '--force', action='store_true',
help='Create the new workload even if a workload with the specified ' +
'name already exists.')
self.parser.add_argument('-k', '--kind', metavar='KIND', default='basic', choices=create_funcs.keys(),
self.parser.add_argument('-k', '--kind', metavar='KIND', default='basic', choices=list(create_funcs.keys()),
help='The type of workload to be created. The available options ' +
'are: {}'.format(', '.join(create_funcs.keys())))
'are: {}'.format(', '.join(list(create_funcs.keys()))))
def execute(self, state, args): # pylint: disable=R0201
where = args.path or 'local'
@@ -179,7 +179,7 @@ def create_workload(name, kind='basic', where='local', check_name=True, **kwargs
except KeyError:
raise CommandError('Unknown workload type: {}'.format(kind))
print 'Workload created in {}'.format(workload_dir)
print('Workload created in {}'.format(workload_dir))
def create_template_workload(path, name, kind, class_name):

View File

@@ -71,7 +71,7 @@ def list_targets():
output = DescriptionListFormatter()
for target in targets:
output.add_item(target.description or '', target.name)
print output.format_data()
print(output.format_data())
def list_plugins(args, filters):
@@ -80,7 +80,7 @@ def list_plugins(args, filters):
filtered_results = []
for result in results:
passed = True
for k, v in filters.iteritems():
for k, v in filters.items():
if getattr(result, k) != v:
passed = False
break
@@ -95,7 +95,7 @@ def list_plugins(args, filters):
output = DescriptionListFormatter()
for result in sorted(filtered_results, key=lambda x: x.name):
output.add_item(get_summary(result), result.name)
print output.format_data()
print(output.format_data())
def check_platform(plugin, platform):

View File

@@ -24,6 +24,10 @@ from wa.framework.target.manager import TargetManager
from wa.utils.revent import ReventRecorder
if sys.version_info[0] == 3:
raw_input = input
class RecordCommand(Command):
name = 'record'
@@ -146,7 +150,7 @@ class RecordCommand(Command):
if os.path.exists(host_path):
msg = 'Revent file \'{}\' already exists, overwrite? [y/n]'
self.logger.info(msg.format(revent_file_name))
if raw_input('') == 'y':
if input('') == 'y':
os.remove(host_path)
else:
msg = 'Did not pull and overwrite \'{}\''
@@ -222,7 +226,7 @@ class RecordCommand(Command):
if not file_name:
file_name = '{}.revent'.format(self.target.model)
if not output_path:
output_path = os.getcwdu()
output_path = os.getcwd()
return output_path, file_name

View File

@@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import sys
from subprocess import call, Popen, PIPE
from wa import Command
@@ -66,7 +67,11 @@ class ShowCommand(Command):
if which('pandoc'):
p = Popen(['pandoc', '-f', 'rst', '-t', 'man'], stdin=PIPE, stdout=PIPE, stderr=PIPE)
output, _ = p.communicate(rst_output)
if sys.version_info[0] == 3:
output, _ = p.communicate(rst_output.encode(sys.stdin.encoding))
output = output.decode(sys.stdout.encoding)
else:
output, _ = p.communicate(rst_output)
# Make sure to double escape back slashes
output = output.replace('\\', '\\\\\\')
@@ -78,7 +83,7 @@ class ShowCommand(Command):
call('echo "{}" | man -l -'.format(escape_double_quotes(output)), shell=True)
else:
print rst_output
print(rst_output)
def get_target_description(name):