'help': "impersonate USER, and default context to `userv'." })]:
OPTPARSE.add_option(short, long, **props)
+def parse_options():
+ """
+ Parse the main command-line options, returning the positional arguments.
+ """
+ global OPTS
+ OPTS, args = OPTPARSE.parse_args()
+ ## It's tempting to load the configuration here. Don't do that. Some
+ ## contexts will want to check that the command line was handled properly
+ ## upstream before believing it for anything, such as executing arbitrary
+ ## Python code.
+ return args
+
###--------------------------------------------------------------------------
### CGI dispatch.
## issuing redirects in the early setup phase fails because we don't know
## the script name. So package the setup here.
def cgi_setup(ctx = 'cgi-noauth'):
- global OPTS
if OPTS: return
OPTPARSE.context = ctx
- OPTS, args = OPTPARSE.parse_args()
+ args = parse_options()
if args: raise U.ExpectedError, (500, 'Unexpected arguments to CGI')
CONF.loadconfig(OPTS.config)
D.opendb()
## `USERV_USER' environment variable.
with cli_errors():
- OPTS, args = OPTPARSE.parse_args()
+ args = parse_options()
if not args or args[0] != 'userv':
raise U.ExpectedError, (500, 'missing userv token')
CONF.loadconfig(OPTS.config)
def ssh_setup():
"""Extract and parse the client's request from where SSH left it."""
- global OPTS
- OPTS, args = OPTPARSE.parse_args()
+ args = parse_options()
CONF.loadconfig(OPTS.config)
cmd = SL.split(ENV['SSH_ORIGINAL_COMMAND'])
if args: raise U.ExpectedError, (500, 'Unexpected arguments via SSH')
## as we are.
with cli_errors():
- OPTS, args = OPTPARSE.parse_args()
+ args = parse_options()
CONF.loadconfig(OPTS.config)
CGI.SSLP = OPTS.sslp
ctx = OPTS.context