Skip to content

Commit 43e036d

Browse files
committed
Move to argparse from optparse
1 parent 52a7f64 commit 43e036d

File tree

6 files changed

+95
-90
lines changed

6 files changed

+95
-90
lines changed

tools/build.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,115 +42,115 @@
4242
# Parse Options
4343
parser = get_default_options_parser()
4444

45-
parser.add_option("--source", dest="source_dir",
45+
parser.add_argument("--source", dest="source_dir",
4646
default=None, help="The source (input) directory", action="append")
4747

48-
parser.add_option("--build", dest="build_dir",
48+
parser.add_argument("--build", dest="build_dir",
4949
default=None, help="The build (output) directory")
5050

51-
parser.add_option("--no-archive", dest="no_archive", action="store_true",
51+
parser.add_argument("--no-archive", dest="no_archive", action="store_true",
5252
default=False, help="Do not produce archive (.ar) file, but rather .o")
5353

5454
# Extra libraries
55-
parser.add_option("-r", "--rtos",
55+
parser.add_argument("-r", "--rtos",
5656
action="store_true",
5757
dest="rtos",
5858
default=False,
5959
help="Compile the rtos")
6060

61-
parser.add_option("--rpc",
61+
parser.add_argument("--rpc",
6262
action="store_true",
6363
dest="rpc",
6464
default=False,
6565
help="Compile the rpc library")
6666

67-
parser.add_option("-e", "--eth",
67+
parser.add_argument("-e", "--eth",
6868
action="store_true", dest="eth",
6969
default=False,
7070
help="Compile the ethernet library")
7171

72-
parser.add_option("-U", "--usb_host",
72+
parser.add_argument("-U", "--usb_host",
7373
action="store_true",
7474
dest="usb_host",
7575
default=False,
7676
help="Compile the USB Host library")
7777

78-
parser.add_option("-u", "--usb",
78+
parser.add_argument("-u", "--usb",
7979
action="store_true",
8080
dest="usb",
8181
default=False,
8282
help="Compile the USB Device library")
8383

84-
parser.add_option("-d", "--dsp",
84+
parser.add_argument("-d", "--dsp",
8585
action="store_true",
8686
dest="dsp",
8787
default=False,
8888
help="Compile the DSP library")
8989

90-
parser.add_option("-F", "--fat",
90+
parser.add_argument("-F", "--fat",
9191
action="store_true",
9292
dest="fat",
9393
default=False,
9494
help="Compile FS and SD card file system library")
9595

96-
parser.add_option("-b", "--ublox",
96+
parser.add_argument("-b", "--ublox",
9797
action="store_true",
9898
dest="ublox",
9999
default=False,
100100
help="Compile the u-blox library")
101101

102-
parser.add_option("", "--cpputest",
102+
parser.add_argument( "--cpputest",
103103
action="store_true",
104104
dest="cpputest_lib",
105105
default=False,
106106
help="Compiles 'cpputest' unit test library (library should be on the same directory level as mbed repository)")
107107

108-
parser.add_option("-D", "",
108+
parser.add_argument("-D",
109109
action="append",
110110
dest="macros",
111111
help="Add a macro definition")
112112

113-
parser.add_option("-S", "--supported-toolchains",
113+
parser.add_argument("-S", "--supported-toolchains",
114114
action="store_true",
115115
dest="supported_toolchains",
116116
default=False,
117117
help="Displays supported matrix of MCUs and toolchains")
118118

119-
parser.add_option('-f', '--filter',
119+
parser.add_argument('-f', '--filter',
120120
dest='general_filter_regex',
121121
default=None,
122122
help='For some commands you can use filter to filter out results')
123123

124-
parser.add_option("", "--cppcheck",
124+
parser.add_argument("--cppcheck",
125125
action="store_true",
126126
dest="cppcheck_validation",
127127
default=False,
128128
help="Forces 'cppcheck' static code analysis")
129129

130-
parser.add_option("-j", "--jobs", type="int", dest="jobs",
130+
parser.add_argument("-j", "--jobs", type=int, dest="jobs",
131131
default=0, help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
132-
parser.add_option("-N", "--artifact-name", dest="artifact_name",
132+
parser.add_argument("-N", "--artifact-name", dest="artifact_name",
133133
default=None, help="The built project's name")
134134

135-
parser.add_option("-v", "--verbose",
135+
parser.add_argument("-v", "--verbose",
136136
action="store_true",
137137
dest="verbose",
138138
default=False,
139139
help="Verbose diagnostic output")
140140

141-
parser.add_option("--silent",
141+
parser.add_argument("--silent",
142142
action="store_true",
143143
dest="silent",
144144
default=False,
145145
help="Silent diagnostic output (no copy, compile notification)")
146146

147-
parser.add_option("-x", "--extra-verbose-notifications",
147+
parser.add_argument("-x", "--extra-verbose-notifications",
148148
action="store_true",
149149
dest="extra_verbose_notify",
150150
default=False,
151151
help="Makes compiler more verbose, CI friendly.")
152152

153-
(options, args) = parser.parse_args()
153+
options = parser.parse_args()
154154

155155
# Only prints matrix of supported toolchains
156156
if options.supported_toolchains:

tools/detect_targets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,24 @@
4242
# Parse Options
4343
parser = get_default_options_parser()
4444

45-
parser.add_option("-S", "--supported-toolchains",
45+
parser.add_argument("-S", "--supported-toolchains",
4646
action="store_true",
4747
dest="supported_toolchains",
4848
default=False,
4949
help="Displays supported matrix of targets and toolchains")
5050

51-
parser.add_option('-f', '--filter',
51+
parser.add_argument('-f', '--filter',
5252
dest='general_filter_regex',
5353
default=None,
5454
help='Filter targets')
5555

56-
parser.add_option("-v", "--verbose",
56+
parser.add_argument("-v", "--verbose",
5757
action="store_true",
5858
dest="verbose",
5959
default=False,
6060
help="Verbose diagnostic output")
6161

62-
(options, args) = parser.parse_args()
62+
options = parser.parse_args()
6363

6464
# Only prints matrix of supported toolchains
6565
if options.supported_toolchains:

tools/get_config.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@
3636
if __name__ == '__main__':
3737
# Parse Options
3838
parser = get_default_options_parser(add_clean=False, add_options=False)
39-
parser.add_option("--source", dest="source_dir",
39+
parser.add_argument("--source", dest="source_dir",
4040
default=None, help="The source (input) directory", action="append")
41-
parser.add_option("--prefix", dest="prefix", action="append",
41+
parser.add_argument("--prefix", dest="prefix", action="append",
4242
default=None, help="Restrict listing to parameters that have this prefix")
43-
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
43+
parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
4444
default=False, help="Verbose diagnostic output")
4545

46-
(options, args) = parser.parse_args()
46+
options = parser.parse_args()
4747

4848
for path in options.source_dir :
4949
if not isdir(path) :

tools/make.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,133 +50,133 @@
5050
if __name__ == '__main__':
5151
# Parse Options
5252
parser = get_default_options_parser()
53-
parser.add_option("-p",
54-
type="int",
53+
parser.add_argument("-p",
54+
type=int,
5555
dest="program",
5656
help="The index of the desired test program: [0-%d]" % (len(TESTS)-1))
5757

58-
parser.add_option("-n",
58+
parser.add_argument("-n",
5959
dest="program_name",
6060
help="The name of the desired test program")
6161

62-
parser.add_option("-j", "--jobs",
63-
type="int",
62+
parser.add_argument("-j", "--jobs",
63+
type=int,
6464
dest="jobs",
6565
default=0,
6666
help="Number of concurrent jobs. Default: 0/auto (based on host machine's number of CPUs)")
6767

68-
parser.add_option("-v", "--verbose",
68+
parser.add_argument("-v", "--verbose",
6969
action="store_true",
7070
dest="verbose",
7171
default=False,
7272
help="Verbose diagnostic output")
7373

74-
parser.add_option("--silent",
74+
parser.add_argument("--silent",
7575
action="store_true",
7676
dest="silent",
7777
default=False,
7878
help="Silent diagnostic output (no copy, compile notification)")
7979

80-
parser.add_option("-D", "",
80+
parser.add_argument("-D",
8181
action="append",
8282
dest="macros",
8383
help="Add a macro definition")
8484

85-
parser.add_option("-S", "--supported-toolchains",
85+
parser.add_argument("-S", "--supported-toolchains",
8686
action="store_true",
8787
dest="supported_toolchains",
8888
default=False,
8989
help="Displays supported matrix of MCUs and toolchains")
9090

91-
parser.add_option('-f', '--filter',
91+
parser.add_argument('-f', '--filter',
9292
dest='general_filter_regex',
9393
default=None,
9494
help='For some commands you can use filter to filter out results')
9595

9696
# Local run
97-
parser.add_option("--automated", action="store_true", dest="automated",
97+
parser.add_argument("--automated", action="store_true", dest="automated",
9898
default=False, help="Automated test")
99-
parser.add_option("--host", dest="host_test",
99+
parser.add_argument("--host", dest="host_test",
100100
default=None, help="Host test")
101-
parser.add_option("--extra", dest="extra",
101+
parser.add_argument("--extra", dest="extra",
102102
default=None, help="Extra files")
103-
parser.add_option("--peripherals", dest="peripherals",
103+
parser.add_argument("--peripherals", dest="peripherals",
104104
default=None, help="Required peripherals")
105-
parser.add_option("--dep", dest="dependencies",
105+
parser.add_argument("--dep", dest="dependencies",
106106
default=None, help="Dependencies")
107-
parser.add_option("--source", dest="source_dir",
107+
parser.add_argument("--source", dest="source_dir",
108108
default=None, help="The source (input) directory", action="append")
109-
parser.add_option("--duration", type="int", dest="duration",
109+
parser.add_argument("--duration", type=int, dest="duration",
110110
default=None, help="Duration of the test")
111-
parser.add_option("--build", dest="build_dir",
111+
parser.add_argument("--build", dest="build_dir",
112112
default=None, help="The build (output) directory")
113-
parser.add_option("-N", "--artifact-name", dest="artifact_name",
113+
parser.add_argument("-N", "--artifact-name", dest="artifact_name",
114114
default=None, help="The built project's name")
115-
parser.add_option("-d", "--disk", dest="disk",
115+
parser.add_argument("-d", "--disk", dest="disk",
116116
default=None, help="The mbed disk")
117-
parser.add_option("-s", "--serial", dest="serial",
117+
parser.add_argument("-s", "--serial", dest="serial",
118118
default=None, help="The mbed serial port")
119-
parser.add_option("-b", "--baud", type="int", dest="baud",
119+
parser.add_argument("-b", "--baud", type=int, dest="baud",
120120
default=None, help="The mbed serial baud rate")
121-
parser.add_option("-L", "--list-tests", action="store_true", dest="list_tests",
121+
parser.add_argument("-L", "--list-tests", action="store_true", dest="list_tests",
122122
default=False, help="List available tests in order and exit")
123123

124124
# Ideally, all the tests with a single "main" thread can be run with, or
125125
# without the rtos, eth, usb_host, usb, dsp, fat, ublox
126-
parser.add_option("--rtos",
126+
parser.add_argument("--rtos",
127127
action="store_true", dest="rtos",
128128
default=False, help="Link with RTOS library")
129129

130-
parser.add_option("--rpc",
130+
parser.add_argument("--rpc",
131131
action="store_true", dest="rpc",
132132
default=False, help="Link with RPC library")
133133

134-
parser.add_option("--eth",
134+
parser.add_argument("--eth",
135135
action="store_true", dest="eth",
136136
default=False,
137137
help="Link with Ethernet library")
138138

139-
parser.add_option("--usb_host",
139+
parser.add_argument("--usb_host",
140140
action="store_true",
141141
dest="usb_host",
142142
default=False,
143143
help="Link with USB Host library")
144144

145-
parser.add_option("--usb",
145+
parser.add_argument("--usb",
146146
action="store_true",
147147
dest="usb",
148148
default=False,
149149
help="Link with USB Device library")
150150

151-
parser.add_option("--dsp",
151+
parser.add_argument("--dsp",
152152
action="store_true",
153153
dest="dsp",
154154
default=False,
155155
help="Link with DSP library")
156156

157-
parser.add_option("--fat",
157+
parser.add_argument("--fat",
158158
action="store_true",
159159
dest="fat",
160160
default=False,
161161
help="Link with FS ad SD card file system library")
162162

163-
parser.add_option("--ublox",
163+
parser.add_argument("--ublox",
164164
action="store_true",
165165
dest="ublox",
166166
default=False,
167167
help="Link with U-Blox library")
168168

169-
parser.add_option("--testlib",
169+
parser.add_argument("--testlib",
170170
action="store_true",
171171
dest="testlib",
172172
default=False,
173173
help="Link with mbed test library")
174174

175175
# Specify a different linker script
176-
parser.add_option("-l", "--linker", dest="linker_script",
176+
parser.add_argument("-l", "--linker", dest="linker_script",
177177
default=None, help="use the specified linker script")
178178

179-
(options, args) = parser.parse_args()
179+
options = parser.parse_args()
180180

181181
# Only prints matrix of supported toolchains
182182
if options.supported_toolchains:

0 commit comments

Comments
 (0)