Module | debsync | Functions related to the import of Debbugs bugs into Malone. |
Package | ftests | No package docstring; 3/4 modules documented |
Module | garbo | Database garbage collection. |
Module | librarian_apache_log_parser | Undocumented |
Module | logger | Logging setup for scripts. |
Module | loghandlers | Backport of Python 2.6 logging handlers. |
Module | mlistimport | Import mailing list information. |
Module | oops | Module docstring goes here. |
Module | runlaunchpad | No module docstring; 1/6 classes, 5/8 functions documented |
Module | scriptmonitor | Monitor whether scripts have run between specified time periods. |
Module | sfremoteproductfinder | Utilities for the sfremoteproductfinder cronscript |
Module | sort_sql | Sort SQL dumps. |
Package | tests | No package docstring; 9/11 modules documented |
Module | updateremoteproduct | Update Product.remote_product using BugWatch information. |
From the __init__.py module:
Class | BufferLogger | A logger that logs to a StringIO object. |
Class | FakeLogger | Emulates a proper logger, just printing everything out the given file. |
Class | QuietFakeLogger | Extra quiet FakeLogger. |
Class | WatchedFileHandler | A handler for logging to a file, which watches the file |
Function | logger | Return a logging instance with standard setup. |
Function | logger_options | Add the --verbose and --quiet 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 |
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 canonical.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.
>>> 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 canonical.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) 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. dbname, dbhost and dbuser are also propagated to lp.dbname, lp.dbhost and lp.dbuser. This ensures that all systems will be using the requested connection details.
To test, we first need to store the current values so we can reset them later.
>>> dbname, dbhost, dbuser = lp.dbname, lp.dbhost, lp.dbuser
Ensure that command line options propagate to where we say they do
>>> parser = OptionParser() >>> db_options(parser) >>> options, args = parser.parse_args( ... ['--dbname=foo', '--host=bar', '--user=baz']) >>> options.dbname, lp.dbname, config.database.dbname ('foo', 'foo', 'foo') >>> (options.dbhost, lp.dbhost, config.database.dbhost) ('bar', 'bar', 'bar') >>> (options.dbuser, lp.dbuser) ('baz', 'baz')
Make sure that the default user is None
>>> parser = OptionParser() >>> db_options(parser) >>> options, args = parser.parse_args([]) >>> options.dbuser, lp.dbuser (None, None)
Reset config
>>> lp.dbname, lp.dbhost, lp.dbuser = dbname, dbhost, dbuser