]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/workspace_tools/host_tests/host_tests_plugins/module_copy_shell.py
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / workspace_tools / host_tests / host_tests_plugins / module_copy_shell.py
1 """
2 mbed SDK
3 Copyright (c) 2011-2013 ARM Limited
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9     http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 """
17
18 import os
19 from os.path import join, basename
20 from host_test_plugins import HostTestPluginBase
21
22
23 class HostTestPluginCopyMethod_Shell(HostTestPluginBase):
24
25     # Plugin interface
26     name = 'HostTestPluginCopyMethod_Shell'
27     type = 'CopyMethod'
28     stable = True
29     capabilities = ['shell', 'cp', 'copy', 'xcopy']
30     required_parameters = ['image_path', 'destination_disk']
31
32     def setup(self, *args, **kwargs):
33         """ Configure plugin, this function should be called before plugin execute() method is used.
34         """
35         return True
36
37     def execute(self, capabilitity, *args, **kwargs):
38         """ Executes capability by name.
39             Each capability may directly just call some command line
40             program or execute building pythonic function
41         """
42         result = False
43         if self.check_parameters(capabilitity, *args, **kwargs) is True:
44             image_path = kwargs['image_path']
45             destination_disk = kwargs['destination_disk']
46             # Wait for mount point to be ready
47             self.check_mount_point_ready(destination_disk)  # Blocking
48             # Prepare correct command line parameter values
49             image_base_name = basename(image_path)
50             destination_path = join(destination_disk, image_base_name)
51             if capabilitity == 'shell':
52                 if os.name == 'nt': capabilitity = 'copy'
53                 elif os.name == 'posix': capabilitity = 'cp'
54             if capabilitity == 'cp' or capabilitity == 'copy' or capabilitity == 'copy':
55                 copy_method = capabilitity
56                 cmd = [copy_method, image_path, destination_path]
57                 result = self.run_command(cmd)
58         return result
59
60
61 def load_plugin():
62     """ Returns plugin available in this module
63     """
64     return HostTestPluginCopyMethod_Shell()