BA
/
BaBoRo1
Embed:
(wiki syntax)
Show/hide line numbers
module_copy_shell.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 import os 00020 from os.path import join, basename 00021 from time import sleep 00022 00023 from .host_test_plugins import HostTestPluginBase 00024 00025 class HostTestPluginCopyMethod_Shell(HostTestPluginBase): 00026 00027 # Plugin interface 00028 name = 'HostTestPluginCopyMethod_Shell' 00029 type = 'CopyMethod' 00030 stable = True 00031 capabilities = ['shell', 'cp', 'copy', 'xcopy'] 00032 required_parameters = ['image_path', 'destination_disk', 'program_cycle_s'] 00033 00034 def setup(self, *args, **kwargs): 00035 """ Configure plugin, this function should be called before plugin execute() method is used. 00036 """ 00037 return True 00038 00039 def execute(self, capability, *args, **kwargs): 00040 """ Executes capability by name. 00041 Each capability may directly just call some command line 00042 program or execute building pythonic function 00043 """ 00044 result = False 00045 if self.check_parameters(capability, *args, **kwargs) is True: 00046 image_path = kwargs['image_path'] 00047 destination_disk = kwargs['destination_disk'] 00048 program_cycle_s = kwargs['program_cycle_s'] 00049 # Wait for mount point to be ready 00050 self.check_mount_point_ready(destination_disk) # Blocking 00051 # Prepare correct command line parameter values 00052 image_base_name = basename(image_path) 00053 destination_path = join(destination_disk, image_base_name) 00054 if capability == 'shell': 00055 if os.name == 'nt': capability = 'copy' 00056 elif os.name == 'posix': capability = 'cp' 00057 if capability == 'cp' or capability == 'copy' or capability == 'copy': 00058 copy_method = capability 00059 cmd = [copy_method, image_path, destination_path] 00060 if os.name == 'posix': 00061 result = self.run_command(cmd, shell=False) 00062 result = self.run_command(["sync"]) 00063 else: 00064 result = self.run_command(cmd) 00065 00066 # Allow mbed to cycle 00067 sleep(program_cycle_s) 00068 00069 return result 00070 00071 00072 def load_plugin (): 00073 """ Returns plugin available in this module 00074 """ 00075 return HostTestPluginCopyMethod_Shell()
Generated on Tue Jul 12 2022 12:22:13 by
