l.s.scripts : package documentation

Part of lp.services

Library functions for use in all scripts.
Module base No module docstring; 4/4 classes, 2/3 functions documented
Package interfaces No package docstring; 1/1 modules documented
Module logger Logging setup for scripts.
Package model Undocumented
Package tests No package docstring; 8/10 modules documented

From the __init__.py module:

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 db_options Add and handle default database connection options on the command line
Function execute_zcml_for_scripts Execute the zcml rooted at launchpad/script.zcml
def dummy_logger_options(parser):
Add dummy --verbose and --quiet options to parser.
def logger(options=None, name=None):

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()
def logger_options(parser, default=logging.INFO, milliseconds=False):
Add the --verbose, --quiet & --ms options to an optparse.OptionParser.

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.

def execute_zcml_for_scripts(use_web_security=False):
Execute the zcml rooted at launchpad/script.zcml

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.

def db_options(parser):

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
API Documentation for Launchpad, generated by pydoctor at 2018-02-23 00:00:09.