Mbed Host Tests
mbedflsh.py
Go to the documentation of this file.
1 """
2 mbed SDK
3 Copyright (c) 2011-2016 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 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
18 """
19 
20 import sys
21 import optparse
22 
23 
24 from . import host_tests_plugins
25 
26 
28  """! Creates simple command line parser
29  """
30  parser = optparse.OptionParser()
31 
32  parser.add_option('-f', '--file',
33  dest='filename',
34  help='File to flash onto mbed device')
35 
36  parser.add_option("-d", "--disk",
37  dest="disk",
38  help="Target disk (mount point) path. Example: F:, /mnt/MBED",
39  metavar="DISK_PATH")
40 
41  copy_methods_str = "Plugin support: " + ', '.join(host_tests_plugins.get_plugin_caps('CopyMethod'))
42 
43  parser.add_option("-c", "--copy",
44  dest="copy_method",
45  default='shell',
46  help="Copy (flash the target) method selector. " + copy_methods_str,
47  metavar="COPY_METHOD")
48 
49  parser.add_option('', '--plugins',
50  dest='list_plugins',
51  default=False,
52  action="store_true",
53  help='Prints registered plugins and exits')
54 
55  parser.add_option('', '--version',
56  dest='version',
57  default=False,
58  action="store_true",
59  help='Prints package version and exits')
60 
61  parser.description = """Flash mbed devices from command line.""" \
62  """This module is using build in to mbed-host-tests plugins used for flashing mbed devices"""
63  parser.epilog = """Example: mbedflsh -d E: -f /path/to/file.bin"""
64 
65  (opts, args) = parser.parse_args()
66  return (opts, args)
67 
68 
69 def main():
70  """! Function wrapping flashing (copy) plugin
71  @details USers can use mbedflsh command to flash mbeds from command line
72  """
73  errorlevel_flag = 0
74  (opts, args) = cmd_parser_setup()
75 
76  if opts.version:
77  import pkg_resources # part of setuptools
78  version = pkg_resources.require("mbed-host-tests")[0].version
79  print(version)
80  sys.exit(0)
81  elif opts.list_plugins: # --plugins option
82  host_tests_plugins.print_plugin_info()
83  sys.exit(0)
84  else:
85  pass
86 
87  if opts.filename:
88  print("mbedflsh: opening file %s..."% opts.filename)
89  result = host_tests_plugins.call_plugin('CopyMethod',
90  opts.copy_method,
91  image_path=opts.filename,
92  destination_disk=opts.disk)
93  errorlevel_flag = result == True
94 
95  return errorlevel_flag
def main()
Function wrapping flashing (copy) plugin.
Definition: mbedflsh.py:69
def cmd_parser_setup()
Creates simple command line parser.
Definition: mbedflsh.py:27