3Copyright (c) 2011-2018 ARM Limited
5Licensed under the Apache License, Version 2.0 (the "License");
6you may not use this file except in compliance with the License.
7You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11Unless required by applicable law or agreed to
in writing, software
12distributed under the License
is distributed on an
"AS IS" BASIS,
13WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied.
14See the License
for the specific language governing permissions
and
15limitations under the License.
17Author: Przemyslaw Wirkus <Przemyslaw.Wirkus
@arm.com>
21from shutil import copy
22from .host_test_plugins import HostTestPluginBase
25class HostTestPluginCopyMethod_MPS2(HostTestPluginBase):
28 name =
'HostTestPluginCopyMethod_MPS2'
31 capabilities = [
'mps2']
32 required_parameters = [
'image_path',
'destination_disk']
37 HostTestPluginBase.__init__(self)
40 """! mps2 copy method for "mbed enabled" devices.
41 This copies the file on the MPS2 keeping the same extension but
42 renaming it "mbed.extension"
43 @param image_path Path to file to be copied
44 @param destination_disk Path to destination (mbed mount point)
46 @details this uses shutil copy to copy the file.
48 @return Returns
True if copy (flashing) was successful
52 _, extension = os.path.splitext(image_path);
53 destination_path = os.path.join(destination_disk,
"mbed" + extension)
55 copy(image_path, destination_path)
57 if os.name ==
'posix':
58 result = self.
run_command(
'sync -f %s' % destination_path, shell=
True)
59 except Exception
as e:
66 def setup(self, *args, **kwargs):
67 """ Configure plugin, this function should be called before plugin execute() method is used.
71 def execute(self, capability, *args, **kwargs):
72 """! Executes capability by name.
73 @details Each capability may directly just call some command line program
or execute building pythonic function
74 @return Returns
True if 'capability' operation was successful
78 if not kwargs[
'image_path']:
82 if not kwargs[
'destination_disk']:
87 target_id = kwargs.get(
'target_id',
None)
88 pooling_timeout = kwargs.get(
'polling_timeout', 60)
93 if kwargs[
'image_path']
and kwargs[
'destination_disk']:
94 if capability ==
'mps2':
95 image_path = os.path.normpath(kwargs[
'image_path'])
96 destination_disk = os.path.normpath(kwargs[
'destination_disk'])
100 result, destination_disk = self.
check_mount_point_ready(destination_disk, target_id=target_id, timeout=pooling_timeout)
102 result = self.
mps2_copy(image_path, destination_disk)
107 """ Returns plugin available in this module
def run_command(self, cmd, shell=True)
Runs command from command line.
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.
def print_plugin_error(self, text)
Interface helper methods - overload only if you need to have custom behaviour.
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...
def mps2_copy(self, image_path, destination_disk)
mps2 copy method for "mbed enabled" devices.
def execute(self, capability, *args, **kwargs)
Executes capability by name.
def setup(self, *args, **kwargs)