module_copy_mps2.py
Go to the documentation of this file.
"""
mbed SDK
Copyright (c) 2011-2018 ARM Limited
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
"""
import os
from shutil import copy
from .host_test_plugins import HostTestPluginBase
class HostTestPluginCopyMethod_MPS2(HostTestPluginBase):
# MPS2 specific flashing / binary setup funcitons
name = 'HostTestPluginCopyMethod_MPS2'
type = 'CopyMethod'
stable = True
capabilities = ['mps2']
required_parameters = ['image_path', 'destination_disk']
def __init__(self):
""" ctor
"""
HostTestPluginBase.__init__(self)
def mps2_copy(self, image_path, destination_disk):
"""! mps2 copy method for "mbed enabled" devices.
This copies the file on the MPS2 keeping the same extension but
renaming it "mbed.extension"
@param image_path Path to file to be copied
@param destination_disk Path to destination (mbed mount point)
@details this uses shutil copy to copy the file.
@return Returns True if copy (flashing) was successful
"""
result = True
# Keep the same extension in the test spec and on the MPS2
_, extension = os.path.splitext(image_path);
destination_path = os.path.join(destination_disk, "mbed" + extension)
try:
copy(image_path, destination_path)
# sync command on mac ignores command line arguments.
if os.name == 'posix':
result = self.run_command('sync -f %s' % destination_path, shell=True)
except Exception as e:
self.print_plugin_error("shutil.copy('%s', '%s')"% (image_path, destination_path))
self.print_plugin_error("Error: %s"% str(e))
result = False
return result
def setup(self, *args, **kwargs):
""" Configure plugin, this function should be called before plugin execute() method is used.
"""
return True
def execute(self, capability, *args, **kwargs):
"""! Executes capability by name.
@details Each capability may directly just call some command line program or execute building pythonic function
@return Returns True if 'capability' operation was successful
"""
if not kwargs['image_path']:
self.print_plugin_error("Error: image path not specified")
return False
if not kwargs['destination_disk']:
self.print_plugin_error("Error: destination disk not specified")
return False
# This optional parameter can be used if TargetID is provided (-t switch)
target_id = kwargs.get('target_id', None)
pooling_timeout = kwargs.get('polling_timeout', 60)
result = False
if self.check_parameters(capability, *args, **kwargs):
# Capability 'default' is a dummy capability
if kwargs['image_path'] and kwargs['destination_disk']:
if capability == 'mps2':
image_path = os.path.normpath(kwargs['image_path'])
destination_disk = os.path.normpath(kwargs['destination_disk'])
# Wait for mount point to be ready
# if mount point changed according to target_id use new mount point
# available in result (_, destination_disk) of check_mount_point_ready
result, destination_disk = self.check_mount_point_ready(destination_disk, target_id=target_id, timeout=pooling_timeout) # Blocking
if result:
result = self.mps2_copy(image_path, destination_disk)
return result
def load_plugin():
""" Returns plugin available in this module
"""
return HostTestPluginCopyMethod_MPS2()
mbed_host_tests.host_tests_plugins.host_test_plugins.HostTestPluginBase
Base class for all plugins used with host tests.
Definition: host_test_plugins.py:32
mbed_host_tests.host_tests_plugins.host_test_plugins.HostTestPluginBase.run_command
def run_command(self, cmd, shell=True)
Runs command from command line.
Definition: host_test_plugins.py:227
mbed_host_tests.host_tests_plugins.module_copy_mps2.HostTestPluginCopyMethod_MPS2.execute
def execute(self, capability, args, kwargs)
Executes capability by name.
Definition: module_copy_mps2.py:71
mbed_host_tests.host_tests_plugins.module_copy_mps2.load_plugin
def load_plugin()
Definition: module_copy_mps2.py:106
mbed_host_tests.host_tests_plugins.module_copy_mps2.HostTestPluginCopyMethod_MPS2.mps2_copy
def mps2_copy(self, image_path, destination_disk)
mps2 copy method for "mbed enabled" devices.
Definition: module_copy_mps2.py:39
mbed_host_tests.host_tests_plugins.module_copy_mps2.HostTestPluginCopyMethod_MPS2
Definition: module_copy_mps2.py:25
mbed_host_tests.host_tests_plugins.module_copy_mps2.HostTestPluginCopyMethod_MPS2.setup
def setup(self, args, kwargs)
Definition: module_copy_mps2.py:66
mbed_host_tests.host_tests_plugins.module_copy_mps2.HostTestPluginCopyMethod_MPS2.__init__
def __init__(self)
Definition: module_copy_mps2.py:34
mbed_host_tests.host_tests_plugins.host_test_plugins.HostTestPluginBase.check_parameters
def check_parameters(self, capability, args, kwargs)
This function should be ran each time we call execute() to check if none of the required parameters i...
Definition: host_test_plugins.py:211
mbed_host_tests.host_tests_plugins.host_test_plugins.HostTestPluginBase.print_plugin_error
def print_plugin_error(self, text)
Interface helper methods - overload only if you need to have custom behaviour.
Definition: host_test_plugins.py:93
mbed_host_tests.host_tests_plugins.host_test_plugins.HostTestPluginBase.check_mount_point_ready
def check_mount_point_ready(self, destination_disk, init_delay=0.2, loop_delay=0.25, target_id=None, timeout=60)
Waits until destination_disk is ready and can be accessed by e.g.
Definition: host_test_plugins.py:116