woob.tools.application.base

class woob.tools.application.base.Application(option_parser=None)

Bases: object

Base application.

This class can be herited to have some common code within woob applications.

APPNAME = ''

Application name

CONFDIR = None

Configuration and work directory (if None, use the Woob instance one)

CONFIG = {}

Default configuration dict (can only contain key/values)

COPYRIGHT = None

Copyright

DEBUG_FILTER = 2

Verbosity of DEBUG

DESCRIPTION = None

Description

OLD_APPNAME = ''
STORAGE = {}

Default storage tree

SYNOPSIS = 'Usage: %prog [-h] [-dqv] [-b backends] ...\n %prog [--help] [--version]'
VERSION = None

Version

add_application_options(group)

Overload this method if your application needs extra options.

These options will be displayed in an option group.

bcall_error_handler(backend, error, backtrace)

Handler for an exception inside the CallErrors exception.

This method can be overridden to support more exceptions types.

bcall_errors_handler(errors, debugmsg='Use --debug option to print backtraces', ignore=())

Handler for the CallErrors exception.

It calls bcall_error_handler for each error.

Parameters
  • errors (woob.core.bcall.CallErrors) – Object containing errors from backends

  • debugmsg (basestring) – Default message asking to enable the debug mode

  • ignore (tuple[Exception]) – Exceptions to ignore

classmethod create_default_logger()
create_logging_file_handler(filename)
create_storage(path=None, klass=None, localonly=False)

Create a storage object.

Parameters
  • path (str) – An optional specific path

  • klass (woob.tools.storage.IStorage) – What class to instance

  • localonly (bool) – If True, do not set it on the Woob object.

Return type

woob.tools.storage.IStorage

create_woob()
deinit()
guess_encoding(stdio=None)
handle_application_options()

Overload this method in your application if you want to handle options defined in add_application_options.

load_backends(caps=None, names=None, exclude=None, *args, **kwargs)
load_config(path=None, klass=None)

Load a configuration file and get his object.

Parameters
Return type

woob.tools.config.iconfig.IConfig

main(argv)

Main method

Called by run

parse_args(args)
classmethod run(args=None)

This static method can be called to run the application.

It creates the application object, handles options, setups logging, calls the main() method, and catches common exceptions.

You can’t do anything after this call, as it always finishes with a call to sys.exit().

For example:

>>> from woob.application.myapplication import MyApplication
>>> MyApplication.run()
classmethod setup_logging(level, handlers)
setup_nss()
stderr = <_io.TextIOWrapper name='<stderr>' mode='w' encoding='UTF-8'>
stdin = <_io.TextIOWrapper name='<stdin>' mode='r' encoding='UTF-8'>
stdout = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>