]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/workspace_tools/host_tests/host_tests_plugins/module_copy_mps2.py
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / workspace_tools / host_tests / host_tests_plugins / module_copy_mps2.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 re
19 from os.path import join
20 from host_test_plugins import HostTestPluginBase
21
22
23 class HostTestPluginCopyMethod_MPS2(HostTestPluginBase):
24
25 # MPS2 specific flashing / binary setup funcitons
26 def mps2_set_board_image_file(self, disk, images_cfg_path, image0file_path, image_name='images.txt'):
27 """ This function will alter image cfg file.
28 Main goal of this function is to change number of images to 1, comment all
29 existing image entries and append at the end of file new entry with test path.
30 @return True when all steps succeed.
31 """
32 MBED_SDK_TEST_STAMP = 'test suite entry'
33 image_path = join(disk, images_cfg_path, image_name)
34 new_file_lines = [] # New configuration file lines (entries)
35
36 # Check each line of the image configuration file
37 try:
38 with open(image_path, 'r') as file:
39 for line in file:
40 if re.search('^TOTALIMAGES', line):
41 # Check number of total images, should be 1
42 new_file_lines.append(re.sub('^TOTALIMAGES:[\t ]*[\d]+', 'TOTALIMAGES: 1', line))
43 elif re.search('; - %s[\n\r]*$'% MBED_SDK_TEST_STAMP, line):
44 # Look for test suite entries and remove them
45 pass # Omit all test suite entries
46 elif re.search('^IMAGE[\d]+FILE', line):
47 # Check all image entries and mark the ';'
48 new_file_lines.append(';' + line) # Comment non test suite lines
49 else:
50 # Append line to new file
51 new_file_lines.append(line)
52 except IOError as e:
53 return False
54
55 # Add new image entry with proper commented stamp
56 new_file_lines.append('IMAGE0FILE: %s ; - %s\r\n'% (image0file_path, MBED_SDK_TEST_STAMP))
57
58 # Write all lines to file
59 try:
60 with open(image_path, 'w') as file:
61 for line in new_file_lines:
62 file.write(line),
63 except IOError:
64 return False
65
66 return True
67
68 def mps2_select_core(self, disk, mobo_config_name=""):
69 """ Function selects actual core
70 """
71 # TODO: implement core selection
72 pass
73
74 def mps2_switch_usb_auto_mounting_after_restart(self, disk, usb_config_name=""):
75 """ Function alters configuration to allow USB MSD to be mounted after restarts
76 """
77 # TODO: implement USB MSD restart detection
78 pass
79
80 # Plugin interface
81 name = 'HostTestPluginCopyMethod_MPS2'
82 type = 'CopyMethod'
83 capabilities = ['mps2']
84 required_parameters = ['image_path', 'destination_disk']
85
86 def setup(self, *args, **kwargs):
87 """ Configure plugin, this function should be called before plugin execute() method is used.
88 """
89 return True
90
91 def execute(self, capabilitity, *args, **kwargs):
92 """ Executes capability by name.
93 Each capability may directly just call some command line
94 program or execute building pythonic function
95 """
96 result = False
97 if self.check_parameters(capabilitity, *args, **kwargs) is True:
98 if capabilitity == 'mps2':
99 # TODO: Implement MPS2 firmware setup here
100 pass
101 return result
102
103
104 def load_plugin():
105 """ Returns plugin available in this module
106 """
107 return HostTestPluginCopyMethod_MPS2()
Imprint / Impressum