Mbed Host Tests
module_copy_mbed.py
Go to the documentation of this file.
1"""
2mbed SDK
3Copyright (c) 2011-2015 ARM Limited
4
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
8
9 http://www.apache.org/licenses/LICENSE-2.0
10
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.
16
17Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
18"""
19
20import os
21from shutil import copy
22from .host_test_plugins import HostTestPluginBase
23
24
25class HostTestPluginCopyMethod_Mbed(HostTestPluginBase):
26 """ Generic flashing method for mbed-enabled devices (by copy)
27 """
28
29 def __init__(self):
30 """ ctor
31 """
32 HostTestPluginBase.__init__(self)
33
34 def generic_mbed_copy(self, image_path, destination_disk):
35 """! Generic mbed copy method for "mbed enabled" devices.
36
37 @param image_path Path to binary file to be flashed
38 @param destination_disk Path to destination (mbed mount point)
39
40 @details It uses standard python shutil function to copy image_file (target specific binary) to device's disk.
41
42 @return Returns True if copy (flashing) was successful
43 """
44 result = True
45 if not destination_disk.endswith('/') and not destination_disk.endswith('\\'):
46 destination_disk += '/'
47 try:
48 copy(image_path, destination_disk)
49 except Exception as e:
50 self.print_plugin_error("shutil.copy('%s', '%s')"% (image_path, destination_disk))
51 self.print_plugin_error("Error: %s"% str(e))
52 result = False
53 return result
54
55 # Plugin interface
56 name = 'HostTestPluginCopyMethod_Mbed'
57 type = 'CopyMethod'
58 stable = True
59 capabilities = ['shutil', 'default']
60 required_parameters = ['image_path', 'destination_disk']
61
62 def setup(self, *args, **kwargs):
63 """ Configure plugin, this function should be called before plugin execute() method is used.
64 """
65 return True
66
67 def execute(self, capability, *args, **kwargs):
68 """! Executes capability by name.
69 @details Each capability may directly just call some command line program or execute building pythonic function
70 @return Returns True if 'capability' operation was successful
71 """
72 if not kwargs['image_path']:
73 self.print_plugin_error("Error: image path not specified")
74 return False
75
76 if not kwargs['destination_disk']:
77 self.print_plugin_error("Error: destination disk not specified")
78 return False
79
80 # This optional parameter can be used if TargetID is provided (-t switch)
81 target_id = kwargs.get('target_id', None)
82 pooling_timeout = kwargs.get('polling_timeout', 60)
83
84 result = False
85 if self.check_parameters(capability, *args, **kwargs):
86 # Capability 'default' is a dummy capability
87 if kwargs['image_path'] and kwargs['destination_disk']:
88 if capability == 'shutil':
89 image_path = os.path.normpath(kwargs['image_path'])
90 destination_disk = os.path.normpath(kwargs['destination_disk'])
91 # Wait for mount point to be ready
92 # if mount point changed according to target_id use new mount point
93 # available in result (_, destination_disk) of check_mount_point_ready
94 mount_res, destination_disk = self.check_mount_point_ready(destination_disk, target_id=self.target_id, timeout=pooling_timeout) # Blocking
95 if mount_res:
96 result = self.generic_mbed_copy(image_path, destination_disk)
97 return result
98
99
101 """ Returns plugin available in this module
102 """
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 generic_mbed_copy(self, image_path, destination_disk)
Generic mbed copy method for "mbed enabled" devices.
def execute(self, capability, *args, **kwargs)
Executes capability by name.