Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed-os/tools/host_tests/host_tests_plugins/module_copy_smart.py@0:02dd72d1d465, 2018-04-24 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 24 11:45:18 2018 +0000
- Revision:
- 0:02dd72d1d465
BaBoRo_test2 - backup 1
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| borlanic | 0:02dd72d1d465 | 1 | """ |
| borlanic | 0:02dd72d1d465 | 2 | mbed SDK |
| borlanic | 0:02dd72d1d465 | 3 | Copyright (c) 2011-2013 ARM Limited |
| borlanic | 0:02dd72d1d465 | 4 | |
| borlanic | 0:02dd72d1d465 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
| borlanic | 0:02dd72d1d465 | 6 | you may not use this file except in compliance with the License. |
| borlanic | 0:02dd72d1d465 | 7 | You may obtain a copy of the License at |
| borlanic | 0:02dd72d1d465 | 8 | |
| borlanic | 0:02dd72d1d465 | 9 | http://www.apache.org/licenses/LICENSE-2.0 |
| borlanic | 0:02dd72d1d465 | 10 | |
| borlanic | 0:02dd72d1d465 | 11 | Unless required by applicable law or agreed to in writing, software |
| borlanic | 0:02dd72d1d465 | 12 | distributed under the License is distributed on an "AS IS" BASIS, |
| borlanic | 0:02dd72d1d465 | 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| borlanic | 0:02dd72d1d465 | 14 | See the License for the specific language governing permissions and |
| borlanic | 0:02dd72d1d465 | 15 | limitations under the License. |
| borlanic | 0:02dd72d1d465 | 16 | """ |
| borlanic | 0:02dd72d1d465 | 17 | |
| borlanic | 0:02dd72d1d465 | 18 | import os |
| borlanic | 0:02dd72d1d465 | 19 | import sys |
| borlanic | 0:02dd72d1d465 | 20 | from os.path import join, basename, exists, abspath, dirname |
| borlanic | 0:02dd72d1d465 | 21 | from time import sleep |
| borlanic | 0:02dd72d1d465 | 22 | from host_test_plugins import HostTestPluginBase |
| borlanic | 0:02dd72d1d465 | 23 | |
| borlanic | 0:02dd72d1d465 | 24 | sys.path.append(abspath(join(dirname(__file__), "../../../"))) |
| borlanic | 0:02dd72d1d465 | 25 | import tools.test_api |
| borlanic | 0:02dd72d1d465 | 26 | |
| borlanic | 0:02dd72d1d465 | 27 | class HostTestPluginCopyMethod_Smart(HostTestPluginBase): |
| borlanic | 0:02dd72d1d465 | 28 | |
| borlanic | 0:02dd72d1d465 | 29 | # Plugin interface |
| borlanic | 0:02dd72d1d465 | 30 | name = 'HostTestPluginCopyMethod_Smart' |
| borlanic | 0:02dd72d1d465 | 31 | type = 'CopyMethod' |
| borlanic | 0:02dd72d1d465 | 32 | stable = True |
| borlanic | 0:02dd72d1d465 | 33 | capabilities = ['smart'] |
| borlanic | 0:02dd72d1d465 | 34 | required_parameters = ['image_path', 'destination_disk', 'target_mcu'] |
| borlanic | 0:02dd72d1d465 | 35 | |
| borlanic | 0:02dd72d1d465 | 36 | def setup(self, *args, **kwargs): |
| borlanic | 0:02dd72d1d465 | 37 | """ Configure plugin, this function should be called before plugin execute() method is used. |
| borlanic | 0:02dd72d1d465 | 38 | """ |
| borlanic | 0:02dd72d1d465 | 39 | return True |
| borlanic | 0:02dd72d1d465 | 40 | |
| borlanic | 0:02dd72d1d465 | 41 | def execute(self, capability, *args, **kwargs): |
| borlanic | 0:02dd72d1d465 | 42 | """ Executes capability by name. |
| borlanic | 0:02dd72d1d465 | 43 | Each capability may directly just call some command line |
| borlanic | 0:02dd72d1d465 | 44 | program or execute building pythonic function |
| borlanic | 0:02dd72d1d465 | 45 | """ |
| borlanic | 0:02dd72d1d465 | 46 | result = False |
| borlanic | 0:02dd72d1d465 | 47 | if self.check_parameters(capability, *args, **kwargs) is True: |
| borlanic | 0:02dd72d1d465 | 48 | image_path = kwargs['image_path'] |
| borlanic | 0:02dd72d1d465 | 49 | destination_disk = kwargs['destination_disk'] |
| borlanic | 0:02dd72d1d465 | 50 | target_mcu = kwargs['target_mcu'] |
| borlanic | 0:02dd72d1d465 | 51 | # Wait for mount point to be ready |
| borlanic | 0:02dd72d1d465 | 52 | self.check_mount_point_ready(destination_disk) # Blocking |
| borlanic | 0:02dd72d1d465 | 53 | # Prepare correct command line parameter values |
| borlanic | 0:02dd72d1d465 | 54 | image_base_name = basename(image_path) |
| borlanic | 0:02dd72d1d465 | 55 | destination_path = join(destination_disk, image_base_name) |
| borlanic | 0:02dd72d1d465 | 56 | if capability == 'smart': |
| borlanic | 0:02dd72d1d465 | 57 | if os.name == 'posix': |
| borlanic | 0:02dd72d1d465 | 58 | cmd = ['cp', image_path, destination_path] |
| borlanic | 0:02dd72d1d465 | 59 | result = self.run_command(cmd, shell=False) |
| borlanic | 0:02dd72d1d465 | 60 | |
| borlanic | 0:02dd72d1d465 | 61 | cmd = ['sync'] |
| borlanic | 0:02dd72d1d465 | 62 | result = self.run_command(cmd, shell=False) |
| borlanic | 0:02dd72d1d465 | 63 | elif os.name == 'nt': |
| borlanic | 0:02dd72d1d465 | 64 | cmd = ['copy', image_path, destination_path] |
| borlanic | 0:02dd72d1d465 | 65 | result = self.run_command(cmd, shell=True) |
| borlanic | 0:02dd72d1d465 | 66 | |
| borlanic | 0:02dd72d1d465 | 67 | # Give the OS and filesystem time to settle down |
| borlanic | 0:02dd72d1d465 | 68 | sleep(3) |
| borlanic | 0:02dd72d1d465 | 69 | |
| borlanic | 0:02dd72d1d465 | 70 | platform_name_filter = [target_mcu] |
| borlanic | 0:02dd72d1d465 | 71 | muts_list = {} |
| borlanic | 0:02dd72d1d465 | 72 | |
| borlanic | 0:02dd72d1d465 | 73 | remount_complete = False |
| borlanic | 0:02dd72d1d465 | 74 | |
| borlanic | 0:02dd72d1d465 | 75 | for i in range(0, 60): |
| borlanic | 0:02dd72d1d465 | 76 | print('Looking for %s with MBEDLS' % target_mcu) |
| borlanic | 0:02dd72d1d465 | 77 | muts_list = tools.test_api.get_autodetected_MUTS_list(platform_name_filter=platform_name_filter) |
| borlanic | 0:02dd72d1d465 | 78 | |
| borlanic | 0:02dd72d1d465 | 79 | if 1 in muts_list: |
| borlanic | 0:02dd72d1d465 | 80 | mut = muts_list[1] |
| borlanic | 0:02dd72d1d465 | 81 | destination_disk = mut['disk'] |
| borlanic | 0:02dd72d1d465 | 82 | destination_path = join(destination_disk, image_base_name) |
| borlanic | 0:02dd72d1d465 | 83 | |
| borlanic | 0:02dd72d1d465 | 84 | if mut['mcu'] == 'LPC1768' or mut['mcu'] == 'LPC11U24': |
| borlanic | 0:02dd72d1d465 | 85 | if exists(destination_disk) and exists(destination_path): |
| borlanic | 0:02dd72d1d465 | 86 | remount_complete = True |
| borlanic | 0:02dd72d1d465 | 87 | break; |
| borlanic | 0:02dd72d1d465 | 88 | else: |
| borlanic | 0:02dd72d1d465 | 89 | if exists(destination_disk) and not exists(destination_path): |
| borlanic | 0:02dd72d1d465 | 90 | remount_complete = True |
| borlanic | 0:02dd72d1d465 | 91 | break; |
| borlanic | 0:02dd72d1d465 | 92 | |
| borlanic | 0:02dd72d1d465 | 93 | sleep(1) |
| borlanic | 0:02dd72d1d465 | 94 | |
| borlanic | 0:02dd72d1d465 | 95 | if remount_complete: |
| borlanic | 0:02dd72d1d465 | 96 | print('Remount complete') |
| borlanic | 0:02dd72d1d465 | 97 | else: |
| borlanic | 0:02dd72d1d465 | 98 | print('Remount FAILED') |
| borlanic | 0:02dd72d1d465 | 99 | |
| borlanic | 0:02dd72d1d465 | 100 | if exists(destination_disk): |
| borlanic | 0:02dd72d1d465 | 101 | print('Disk exists') |
| borlanic | 0:02dd72d1d465 | 102 | else: |
| borlanic | 0:02dd72d1d465 | 103 | print('Disk does not exist') |
| borlanic | 0:02dd72d1d465 | 104 | |
| borlanic | 0:02dd72d1d465 | 105 | if exists(destination_path): |
| borlanic | 0:02dd72d1d465 | 106 | print('Image exists') |
| borlanic | 0:02dd72d1d465 | 107 | else: |
| borlanic | 0:02dd72d1d465 | 108 | print('Image does not exist') |
| borlanic | 0:02dd72d1d465 | 109 | |
| borlanic | 0:02dd72d1d465 | 110 | result = None |
| borlanic | 0:02dd72d1d465 | 111 | |
| borlanic | 0:02dd72d1d465 | 112 | |
| borlanic | 0:02dd72d1d465 | 113 | return result |
| borlanic | 0:02dd72d1d465 | 114 | |
| borlanic | 0:02dd72d1d465 | 115 | def load_plugin(): |
| borlanic | 0:02dd72d1d465 | 116 | """ Returns plugin available in this module |
| borlanic | 0:02dd72d1d465 | 117 | """ |
| borlanic | 0:02dd72d1d465 | 118 | return HostTestPluginCopyMethod_Smart() |