You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

module_copy_shell.py 2.4KB

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