Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Alchemy Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
Alchemy Viewer
Alchemy Viewer
Commits
83f2f43e
Commit
83f2f43e
authored
8 years ago
by
Oz Linden
Browse files
Options
Downloads
Patches
Plain Diff
convert run_build_tests to use argparse rather than optparse
parent
a0c18425
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
indra/cmake/run_build_test.py
+22
-22
22 additions, 22 deletions
indra/cmake/run_build_test.py
with
22 additions
and
22 deletions
indra/cmake/run_build_test.py
+
22
−
22
View file @
83f2f43e
...
@@ -52,10 +52,11 @@
...
@@ -52,10 +52,11 @@
import
signal
import
signal
import
subprocess
import
subprocess
def
main
(
command
,
libpath
=
[],
vars
=
{}):
def
main
(
command
,
arguments
=
[],
libpath
=
[],
vars
=
{}):
"""
Pass:
"""
Pass:
command is a sequence (e.g. a list) of strings. The first item in the list
command is the command to be executed
must be the command name, the rest are its arguments.
argument is a sequence (e.g. a list) of strings to be passed to command
libpath is a sequence of directory pathnames. These will be appended to
libpath is a sequence of directory pathnames. These will be appended to
the platform-specific dynamic library search path environment variable.
the platform-specific dynamic library search path environment variable.
...
@@ -112,11 +113,13 @@ def main(command, libpath=[], vars={}):
...
@@ -112,11 +113,13 @@ def main(command, libpath=[], vars={}):
print
"
%s=%s
"
%
(
key
,
value
)
print
"
%s=%s
"
%
(
key
,
value
)
os
.
environ
.
update
(
dict
([(
str
(
key
),
str
(
value
))
for
key
,
value
in
vars
.
iteritems
()]))
os
.
environ
.
update
(
dict
([(
str
(
key
),
str
(
value
))
for
key
,
value
in
vars
.
iteritems
()]))
# Run the child process.
# Run the child process.
print
"
Running: %s
"
%
"
"
.
join
(
command
)
command_list
=
[
command
]
command_list
.
extend
(
arguments
)
print
"
Running: %s
"
%
"
"
.
join
(
command_list
)
# Make sure we see all relevant output *before* child-process output.
# Make sure we see all relevant output *before* child-process output.
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
try
:
try
:
return
subprocess
.
call
(
command
)
return
subprocess
.
call
(
command
_list
)
except
OSError
as
err
:
except
OSError
as
err
:
# If the caller is trying to execute a test program that doesn't
# If the caller is trying to execute a test program that doesn't
# exist, we want to produce a reasonable error message rather than a
# exist, we want to produce a reasonable error message rather than a
...
@@ -304,21 +307,18 @@ def get_windows_table():
...
@@ -304,21 +307,18 @@ def get_windows_table():
return
_windows_table
return
_windows_table
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
from
optparse
import
OptionParser
import
argparse
parser
=
OptionParser
(
usage
=
"
usage: %prog [options] command args...
"
)
parser
=
argparse
.
ArgumentParser
()
# We want optparse support for the options we ourselves handle -- but we
parser
.
add_argument
(
"
-D
"
,
"
--define
"
,
dest
=
"
vars
"
,
default
=
[],
action
=
"
append
"
,
# DO NOT want it looking at options for the executable we intend to run,
metavar
=
"
VAR=value
"
,
# rejecting them as invalid because we don't define them. So configure the
help
=
"
Add VAR=value to the env variables defined
"
)
# parser to stop looking for options as soon as it sees the first
parser
.
add_argument
(
"
-l
"
,
"
--libpath
"
,
dest
=
"
libpath
"
,
default
=
[],
action
=
"
append
"
,
# positional argument (traditional Unix syntax).
metavar
=
"
DIR
"
,
parser
.
disable_interspersed_args
()
help
=
"
Add DIR to the platform-dependent DLL search path
"
)
parser
.
add_option
(
"
-D
"
,
"
--define
"
,
dest
=
"
vars
"
,
default
=
[],
action
=
"
append
"
,
parser
.
add_argument
(
"
command
"
)
metavar
=
"
VAR=value
"
,
parser
.
add_argument
(
'
args
'
,
nargs
=
argparse
.
REMAINDER
)
help
=
"
Add VAR=value to the env variables defined
"
)
args
=
parser
.
parse_args
()
parser
.
add_option
(
"
-l
"
,
"
--libpath
"
,
dest
=
"
libpath
"
,
default
=
[],
action
=
"
append
"
,
metavar
=
"
DIR
"
,
help
=
"
Add DIR to the platform-dependent DLL search path
"
)
opts
,
args
=
parser
.
parse_args
()
# What we have in opts.vars is a list of strings of the form "VAR=value"
# What we have in opts.vars is a list of strings of the form "VAR=value"
# or possibly just "VAR". What we want is a dict. We can build that dict by
# or possibly just "VAR". What we want is a dict. We can build that dict by
# constructing a list of ["VAR", "value"] pairs -- so split each
# constructing a list of ["VAR", "value"] pairs -- so split each
...
@@ -326,8 +326,8 @@ def get_windows_table():
...
@@ -326,8 +326,8 @@ def get_windows_table():
# "VAR=some=user=string"). To handle the case of just "VAR", append "" to
# "VAR=some=user=string"). To handle the case of just "VAR", append "" to
# the list returned by split(), then slice off anything after the pair we
# the list returned by split(), then slice off anything after the pair we
# want.
# want.
rc
=
main
(
command
=
args
,
libpath
=
opt
s
.
libpath
,
rc
=
main
(
command
=
args
.
command
,
arguments
=
args
.
args
,
libpath
=
arg
s
.
libpath
,
vars
=
dict
([(
pair
.
split
(
'
=
'
,
1
)
+
[
""
])[:
2
]
for
pair
in
opt
s
.
vars
]))
vars
=
dict
([(
pair
.
split
(
'
=
'
,
1
)
+
[
""
])[:
2
]
for
pair
in
arg
s
.
vars
]))
if
rc
not
in
(
None
,
0
):
if
rc
not
in
(
None
,
0
):
print
>>
sys
.
stderr
,
"
Failure running: %s
"
%
"
"
.
join
(
args
)
print
>>
sys
.
stderr
,
"
Failure running: %s
"
%
"
"
.
join
(
args
)
print
>>
sys
.
stderr
,
"
Error %s: %s
"
%
(
rc
,
translate_rc
(
rc
))
print
>>
sys
.
stderr
,
"
Error %s: %s
"
%
(
rc
,
translate_rc
(
rc
))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment