Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers module_copy_mbed.py Source File

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 
00018 from shutil import copy
00019 from host_test_plugins import HostTestPluginBase
00020 from time import sleep
00021 
00022 
00023 class HostTestPluginCopyMethod_Mbed(HostTestPluginBase):
00024 
00025     def generic_mbed_copy(self, image_path, destination_disk):
00026         """ Generic mbed copy method for "mbed enabled" devices.
00027             It uses standard python shuitl function to copy
00028             image_file (target specific binary) to device's disk.
00029         """
00030         result = True
00031         if not destination_disk.endswith('/') and not destination_disk.endswith('\\'):
00032             destination_disk += '/'
00033         try:
00034             copy(image_path, destination_disk)
00035         except Exception, e:
00036             self.print_plugin_error("shutil.copy('%s', '%s')"% (image_path, destination_disk))
00037             self.print_plugin_error("Error: %s"% str(e))
00038             result = False
00039         return result
00040 
00041     # Plugin interface
00042     name = 'HostTestPluginCopyMethod_Mbed'
00043     type = 'CopyMethod'
00044     stable = True
00045     capabilities = ['shutil', 'default']
00046     required_parameters = ['image_path', 'destination_disk', 'program_cycle_s']
00047 
00048     def setup(self, *args, **kwargs):
00049         """ Configure plugin, this function should be called before plugin execute() method is used.
00050         """
00051         return True
00052 
00053     def execute(self, capability, *args, **kwargs):
00054         """ Executes capability by name.
00055             Each capability may directly just call some command line
00056             program or execute building pythonic function
00057         """
00058         result = False
00059         if self.check_parameters(capability, *args, **kwargs) is True:
00060             # Capability 'default' is a dummy capability
00061             if capability == 'shutil':
00062                 image_path = kwargs['image_path']
00063                 destination_disk = kwargs['destination_disk']
00064                 program_cycle_s = kwargs['program_cycle_s']
00065                 # Wait for mount point to be ready
00066                 self.check_mount_point_ready(destination_disk)  # Blocking
00067                 result = self.generic_mbed_copy(image_path, destination_disk)
00068 
00069                 # Allow mbed to cycle
00070                 sleep(program_cycle_s)
00071 
00072         return result
00073 
00074 
00075 def load_plugin ():
00076     """ Returns plugin available in this module
00077     """
00078     return HostTestPluginCopyMethod_Mbed()