Function | dummy_logger_options | Add dummy --verbose and --quiet options to parser . |
Function | logger | Return a logging instance with standard setup. |
Function | logger_options | Add the --verbose, --quiet & --ms options to an optparse.OptionParser. |
Function | execute_zcml_for_scripts | Execute the zcml rooted at launchpad/script.zcml |
Function | db_options | Add and handle default database connection options on the command line |
Return a logging instance with standard setup.
options should be the options as returned by an option parser that has been initilized with logger_options(parser)
>>> from optparse import OptionParser >>> parser = OptionParser() >>> logger_options(parser) >>> options, args = parser.parse_args(['-v', '-v', '-q', '-q', '-q']) >>> log = logger(options) >>> log.debug('Not shown - too quiet')
Cleanup:
>>> from lp.testing import reset_logging >>> reset_logging()
The requested loglevel will end up in the option's loglevel attribute. Note that loglevel is not clamped to any particular range.
The milliseconds parameter specifies the default for the --ms option.
>>> from optparse import OptionParser >>> parser = OptionParser() >>> logger_options(parser) >>> options, args = parser.parse_args(['-v', '-v', '-q', '-qqqqqqq']) >>> options.loglevel > logging.CRITICAL True >>> options.verbose False
>>> parser = OptionParser() >>> logger_options(parser) >>> options, args = parser.parse_args([]) >>> options.loglevel == logging.INFO True >>> options.verbose False
>>> from optparse import OptionParser >>> parser = OptionParser() >>> logger_options(parser, logging.WARNING) >>> options, args = parser.parse_args(['-v']) >>> options.loglevel == logging.INFO True >>> options.verbose True
Cleanup: >>> from lp.testing import reset_logging >>> reset_logging()
As part of the options parsing, the 'log' global variable is updated. This can be used by code too lazy to pass it around as a variable.
If use_web_security is True, the same security policy as the web application uses will be used. Otherwise everything protected by a permission is allowed, and everything else denied.
Add and handle default database connection options on the command line
Adds -d (--database), -H (--host), -p (--port) and -U (--user)
Parsed options provide dbname, dbhost and dbuser attributes.
Generally, scripts will not need this and should instead pull their connection details from launchpad.config.config. The database setup and maintenance tools cannot do this however.
dbname and dbhost are also propagated to config.database.dbname and config.database.dbhost. This ensures that all systems will be using the requested connection details.
Ensure that command line options propagate to where we say they do
>>> from optparse import OptionParser >>> parser = OptionParser() >>> db_options(parser) >>> options, args = parser.parse_args( ... ['--dbname=foo', '--host=bar', '--user=baz', '--port=6432']) >>> options.dbname 'foo' >>> options.dbhost 'bar' >>> options.dbuser 'baz' >>> options.dbport 6432 >>> config.database.rw_main_master 'dbname=foo user=baz host=bar port=6432' >>> config.database.rw_main_slave 'dbname=foo user=baz host=bar port=6432'
Make sure that the default user is None
>>> parser = OptionParser() >>> db_options(parser) >>> options, args = parser.parse_args([]) >>> print options.dbuser None