Merge "Add command structure to example code"
This commit is contained in:
@@ -61,7 +61,7 @@ def get_open_fds():
|
|||||||
return [d.replace('\000', '|') for d in procs_list]
|
return [d.replace('\000', '|') for d in procs_list]
|
||||||
|
|
||||||
|
|
||||||
def make_transport(opts):
|
def run_transport(opts):
|
||||||
"""Create a transport given some options."""
|
"""Create a transport given some options."""
|
||||||
|
|
||||||
# Certificate verification - defaults to True
|
# Certificate verification - defaults to True
|
||||||
@@ -74,18 +74,22 @@ def make_transport(opts):
|
|||||||
verify=verify,
|
verify=verify,
|
||||||
user_agent=USER_AGENT,
|
user_agent=USER_AGENT,
|
||||||
)
|
)
|
||||||
return trans
|
print("transport: %s" % trans)
|
||||||
|
if opts.os_url:
|
||||||
|
print(trans.get(opts.os_url).text)
|
||||||
|
return
|
||||||
|
|
||||||
|
COMMANDS = {'transport': run_transport}
|
||||||
|
|
||||||
|
|
||||||
def run(opts):
|
def run(opts):
|
||||||
|
if opts.debug:
|
||||||
print("start fds: %s" % get_open_fds())
|
print("start fds: %s" % get_open_fds())
|
||||||
|
|
||||||
# Set up common client transport
|
# Run
|
||||||
trans = make_transport(opts)
|
COMMANDS[opts.command](opts)
|
||||||
|
|
||||||
# Do something interesting here?
|
|
||||||
print("transport: %s" % trans)
|
|
||||||
|
|
||||||
|
if opts.debug:
|
||||||
print("end fds: %s" % get_open_fds())
|
print("end fds: %s" % get_open_fds())
|
||||||
|
|
||||||
|
|
||||||
@@ -190,6 +194,11 @@ def option_parser():
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
help='show tracebacks on errors',
|
help='show tracebacks on errors',
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'command',
|
||||||
|
choices=list(COMMANDS),
|
||||||
|
help='Command to run.',
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ from examples import common
|
|||||||
|
|
||||||
|
|
||||||
def do_transport(opts):
|
def do_transport(opts):
|
||||||
trans = common.make_transport(opts)
|
trans = common.run_transport(opts)
|
||||||
|
|
||||||
# Get the version data from the auth URL
|
# Get the version data from the auth URL
|
||||||
resp = trans.get(opts.os_auth_url).json()
|
resp = trans.get(opts.os_auth_url).json()
|
||||||
|
|||||||
Reference in New Issue
Block a user