Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
module_copy_mbed.py
00001 """ 00002 mbed SDK 00003 Copyright (c) 2011-2013 ARM Limited 00004 00005 Licensed under the Apache License, Version 2.0 (the "License"); 00006 you may not use this file except in compliance with the License. 00007 You may obtain a copy of the License at 00008 00009 http://www.apache.org/licenses/LICENSE-2.0 00010 00011 Unless required by applicable law or agreed to in writing, software 00012 distributed under the License is distributed on an "AS IS" BASIS, 00013 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 See the License for the specific language governing permissions and 00015 limitations under the License. 00016 """ 00017 from __future__ import print_function 00018 00019 from shutil import copy 00020 from .host_test_plugins import HostTestPluginBase 00021 from time import sleep 00022 00023 00024 class HostTestPluginCopyMethod_Mbed(HostTestPluginBase): 00025 00026 def generic_mbed_copy(self, image_path, destination_disk): 00027 """ Generic mbed copy method for "mbed enabled" devices. 00028 It uses standard python shuitl function to copy 00029 image_file (target specific binary) to device's disk. 00030 """ 00031 result = True 00032 if not destination_disk.endswith('/') and not destination_disk.endswith('\\'): 00033 destination_disk += '/' 00034 try: 00035 copy(image_path, destination_disk) 00036 except Exception as e: 00037 self.print_plugin_error("shutil.copy('%s', '%s')"% (image_path, destination_disk)) 00038 self.print_plugin_error("Error: %s"% str(e)) 00039 result = False 00040 return result 00041 00042 # Plugin interface 00043 name = 'HostTestPluginCopyMethod_Mbed' 00044 type = 'CopyMethod' 00045 stable = True 00046 capabilities = ['shutil', 'default'] 00047 required_parameters = ['image_path', 'destination_disk', 'program_cycle_s'] 00048 00049 def setup(self, *args, **kwargs): 00050 """ Configure plugin, this function should be called before plugin execute() method is used. 00051 """ 00052 return True 00053 00054 def execute(self, capability, *args, **kwargs): 00055 """ Executes capability by name. 00056 Each capability may directly just call some command line 00057 program or execute building pythonic function 00058 """ 00059 result = False 00060 if self.check_parameters(capability, *args, **kwargs) is True: 00061 # Capability 'default' is a dummy capability 00062 if capability == 'shutil': 00063 image_path = kwargs['image_path'] 00064 destination_disk = kwargs['destination_disk'] 00065 program_cycle_s = kwargs['program_cycle_s'] 00066 # Wait for mount point to be ready 00067 self.check_mount_point_ready(destination_disk) # Blocking 00068 result = self.generic_mbed_copy(image_path, destination_disk) 00069 00070 # Allow mbed to cycle 00071 sleep(program_cycle_s) 00072 00073 return result 00074 00075 00076 def load_plugin (): 00077 """ Returns plugin available in this module 00078 """ 00079 return HostTestPluginCopyMethod_Mbed()
Generated on Tue Jul 12 2022 14:24:28 by
