woob.tools.application.base

class Application(option_parser=None)[source]

Bases: object

Base application.

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

APPNAME = ''

Application name

OLD_APPNAME = ''
CONFIG = {}

Default configuration dict (can only contain key/values)

STORAGE = {}

Default storage tree

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

Description

VERSION = None

Version

COPYRIGHT = None

Copyright

DEBUG_FILTER = 2

Verbosity of DEBUG

stdin = <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>
stdout = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
stderr = <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>
create_woob()[source]
add_application_options(group)[source]

Overload this method if your application needs extra options.

These options will be displayed in an option group.

handle_application_options()[source]

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

CONFDIR = None

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

guess_encoding(stdio=None)[source]
deinit()[source]
create_storage(path=None, klass=None, localonly=False)[source]

Create a storage object.

Parameters:
  • path (str) – An optional specific path (default: None)

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

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

Return type:

woob.tools.storage.IStorage

load_config(path=None, klass=None)[source]

Load a configuration file and get his object.

Parameters:
Return type:

woob.tools.config.iconfig.IConfig

main(argv)[source]

Main method

Called by run

load_backends(caps=None, names=None, exclude=None, *args, **kwargs)[source]
bcall_error_handler(backend, error, backtrace)[source]

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=())[source]

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 (str) – Default message asking to enable the debug mode (default: 'Use --debug option to print backtraces')

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

parse_args(args)[source]
classmethod create_default_logger()[source]
classmethod setup_logging(level, handlers)[source]
setup_ipversion()[source]
create_logging_file_handler(filename)[source]
classmethod run(args=None)[source]

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()