mbed-os
Dependents: cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more
tools/host_tests/host_tests_plugins/module_copy_shell.py@0:b74591d5ab33, 2017-12-11 (annotated)
- Committer:
- be_bryan
- Date:
- Mon Dec 11 17:54:04 2017 +0000
- Revision:
- 0:b74591d5ab33
motor ++
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
be_bryan | 0:b74591d5ab33 | 1 | """ |
be_bryan | 0:b74591d5ab33 | 2 | mbed SDK |
be_bryan | 0:b74591d5ab33 | 3 | Copyright (c) 2011-2013 ARM Limited |
be_bryan | 0:b74591d5ab33 | 4 | |
be_bryan | 0:b74591d5ab33 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
be_bryan | 0:b74591d5ab33 | 6 | you may not use this file except in compliance with the License. |
be_bryan | 0:b74591d5ab33 | 7 | You may obtain a copy of the License at |
be_bryan | 0:b74591d5ab33 | 8 | |
be_bryan | 0:b74591d5ab33 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
be_bryan | 0:b74591d5ab33 | 10 | |
be_bryan | 0:b74591d5ab33 | 11 | Unless required by applicable law or agreed to in writing, software |
be_bryan | 0:b74591d5ab33 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
be_bryan | 0:b74591d5ab33 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
be_bryan | 0:b74591d5ab33 | 14 | See the License for the specific language governing permissions and |
be_bryan | 0:b74591d5ab33 | 15 | limitations under the License. |
be_bryan | 0:b74591d5ab33 | 16 | """ |
be_bryan | 0:b74591d5ab33 | 17 | |
be_bryan | 0:b74591d5ab33 | 18 | import os |
be_bryan | 0:b74591d5ab33 | 19 | from os.path import join, basename |
be_bryan | 0:b74591d5ab33 | 20 | from host_test_plugins import HostTestPluginBase |
be_bryan | 0:b74591d5ab33 | 21 | from time import sleep |
be_bryan | 0:b74591d5ab33 | 22 | |
be_bryan | 0:b74591d5ab33 | 23 | |
be_bryan | 0:b74591d5ab33 | 24 | class HostTestPluginCopyMethod_Shell(HostTestPluginBase): |
be_bryan | 0:b74591d5ab33 | 25 | |
be_bryan | 0:b74591d5ab33 | 26 | # Plugin interface |
be_bryan | 0:b74591d5ab33 | 27 | name = 'HostTestPluginCopyMethod_Shell' |
be_bryan | 0:b74591d5ab33 | 28 | type = 'CopyMethod' |
be_bryan | 0:b74591d5ab33 | 29 | stable = True |
be_bryan | 0:b74591d5ab33 | 30 | capabilities = ['shell', 'cp', 'copy', 'xcopy'] |
be_bryan | 0:b74591d5ab33 | 31 | required_parameters = ['image_path', 'destination_disk', 'program_cycle_s'] |
be_bryan | 0:b74591d5ab33 | 32 | |
be_bryan | 0:b74591d5ab33 | 33 | def setup(self, *args, **kwargs): |
be_bryan | 0:b74591d5ab33 | 34 | """ Configure plugin, this function should be called before plugin execute() method is used. |
be_bryan | 0:b74591d5ab33 | 35 | """ |
be_bryan | 0:b74591d5ab33 | 36 | return True |
be_bryan | 0:b74591d5ab33 | 37 | |
be_bryan | 0:b74591d5ab33 | 38 | def execute(self, capability, *args, **kwargs): |
be_bryan | 0:b74591d5ab33 | 39 | """ Executes capability by name. |
be_bryan | 0:b74591d5ab33 | 40 | Each capability may directly just call some command line |
be_bryan | 0:b74591d5ab33 | 41 | program or execute building pythonic function |
be_bryan | 0:b74591d5ab33 | 42 | """ |
be_bryan | 0:b74591d5ab33 | 43 | result = False |
be_bryan | 0:b74591d5ab33 | 44 | if self.check_parameters(capability, *args, **kwargs) is True: |
be_bryan | 0:b74591d5ab33 | 45 | image_path = kwargs['image_path'] |
be_bryan | 0:b74591d5ab33 | 46 | destination_disk = kwargs['destination_disk'] |
be_bryan | 0:b74591d5ab33 | 47 | program_cycle_s = kwargs['program_cycle_s'] |
be_bryan | 0:b74591d5ab33 | 48 | # Wait for mount point to be ready |
be_bryan | 0:b74591d5ab33 | 49 | self.check_mount_point_ready(destination_disk) # Blocking |
be_bryan | 0:b74591d5ab33 | 50 | # Prepare correct command line parameter values |
be_bryan | 0:b74591d5ab33 | 51 | image_base_name = basename(image_path) |
be_bryan | 0:b74591d5ab33 | 52 | destination_path = join(destination_disk, image_base_name) |
be_bryan | 0:b74591d5ab33 | 53 | if capability == 'shell': |
be_bryan | 0:b74591d5ab33 | 54 | if os.name == 'nt': capability = 'copy' |
be_bryan | 0:b74591d5ab33 | 55 | elif os.name == 'posix': capability = 'cp' |
be_bryan | 0:b74591d5ab33 | 56 | if capability == 'cp' or capability == 'copy' or capability == 'copy': |
be_bryan | 0:b74591d5ab33 | 57 | copy_method = capability |
be_bryan | 0:b74591d5ab33 | 58 | cmd = [copy_method, image_path, destination_path] |
be_bryan | 0:b74591d5ab33 | 59 | if os.name == 'posix': |
be_bryan | 0:b74591d5ab33 | 60 | result = self.run_command(cmd, shell=False) |
be_bryan | 0:b74591d5ab33 | 61 | result = self.run_command(["sync"]) |
be_bryan | 0:b74591d5ab33 | 62 | else: |
be_bryan | 0:b74591d5ab33 | 63 | result = self.run_command(cmd) |
be_bryan | 0:b74591d5ab33 | 64 | |
be_bryan | 0:b74591d5ab33 | 65 | # Allow mbed to cycle |
be_bryan | 0:b74591d5ab33 | 66 | sleep(program_cycle_s) |
be_bryan | 0:b74591d5ab33 | 67 | |
be_bryan | 0:b74591d5ab33 | 68 | return result |
be_bryan | 0:b74591d5ab33 | 69 | |
be_bryan | 0:b74591d5ab33 | 70 | |
be_bryan | 0:b74591d5ab33 | 71 | def load_plugin(): |
be_bryan | 0:b74591d5ab33 | 72 | """ Returns plugin available in this module |
be_bryan | 0:b74591d5ab33 | 73 | """ |
be_bryan | 0:b74591d5ab33 | 74 | return HostTestPluginCopyMethod_Shell() |