woob.tools.application.repl

exception NotEnoughArguments[source]

Bases: Exception

exception TooManyArguments[source]

Bases: Exception

exception ArgSyntaxError[source]

Bases: Exception

class ReplApplication[source]

Bases: ConsoleApplication, Cmd

Base application class for Repl applications.

SYNOPSIS = 'Usage: %prog [-dqv] [-b backends] [-cnfs] [command [arguments..]]\n       %prog [--help] [--version]'
DISABLE_REPL = False
EXTRA_FORMATTERS = {}
DEFAULT_FORMATTER = 'multiline'
COMMANDS_FORMATTERS = {}
COLLECTION_OBJECTS = ()

Objects to allow in do_ls / do_cd

woob_commands = {'backends', 'cd', 'condition', 'count', 'formatter', 'logging', 'ls', 'quit', 'select', 'storage'}
hidden_commands = {'EOF'}
property interactive
change_path(split_path)[source]
add_object(obj)[source]
parse_id(id, unique_backend=False)[source]
get_object(_id, method, fields=None, caps=None)[source]
get_object_list(method=None, *args, **kwargs)[source]
unload_backends(*args, **kwargs)[source]
load_backends(*args, **kwargs)[source]
main(argv)[source]

Main method

Called by run

do(function, *args, **kwargs)[source]

Call Woob.do(), passing count and selected fields given by user.

parse_command_args(line, nb, req_n=None)[source]
postcmd(stop, line)[source]

This REPL method is overridden to return None instead of integers to prevent stopping cmdloop().

parseline(line)[source]

This REPL method is overridden to search “short” alias of commands

onecmd(line)[source]

This REPL method is overridden to catch some particular exceptions.

emptyline()[source]

By default, an emptyline repeats the previous command. Overriding this function disables this behaviour.

default(line)[source]

Called on an input line when the command prefix is not recognized.

If this method is not overridden, it prints an error message and returns.

completenames(text, *ignored)[source]
path_completer(arg)[source]
complete(text, state)[source]

Override of the Cmd.complete() method to:

  • add a space at end of proposals

  • display only proposals for words which match the text already written by user.

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

Handler for the CallErrors exception.

get_command_help(command, short=False)[source]
get_commands_doc()[source]
do_quit(arg)[source]

Quit the application.

do_EOF(arg)[source]

Quit the command line interpreter when ^D is pressed.

do_help(arg=None)[source]

help [COMMAND]

List commands, or get information about a command.

complete_backends(text, line, begidx, endidx)[source]
do_storage(line)[source]

storage [ACTION] [BACKEND_NAME]

Manipulation of a backend storage. :rtype: int

  • cat display content of the storage

  • edit edit the storage

  • flush flush storage

do_backends(line)[source]

backends [ACTION] [BACKEND_NAME]…

Select used backends.

ACTION is one of the following (default: list):
  • enable enable given backends

  • disable disable given backends

  • only enable given backends and disable the others

  • list list backends

  • add add a backend

  • register register a new account on a website

  • edit edit a backend

  • remove remove a backend

  • list-modules list modules

complete_logging(text, line, begidx, endidx)[source]
do_logging(line)[source]

logging [LEVEL]

Set logging level.

Availables: debug, info, warning, error. * quiet is an alias for error * default is an alias for warning

do_condition(line)[source]

condition [EXPRESSION | off]

If an argument is given, set the condition expression used to filter the results. See CONDITION section for more details and the expression. If the “off” value is given, conditional filtering is disabled.

If no argument is given, print the current condition expression.

do_count(line)[source]

count [NUMBER | off]

If an argument is given, set the maximum number of results fetched. NUMBER must be at least 1. “off” value disables counting, and allows infinite searches.

If no argument is given, print the current count value.

complete_formatter(text, line, *ignored)[source]
do_formatter(line)[source]

formatter [list | FORMATTER [COMMAND] | option OPTION_NAME [on | off]]

If a FORMATTER is given, set the formatter to use. You can add a COMMAND to apply the formatter change only to a given command.

If the argument is “list”, print the available formatters.

If the argument is “option”, set the formatter options. Valid options are: header, keys. If on/off value is given, set the value of the option. If not, print the current value for the option.

If no argument is given, print the current formatter.

do_select(line)[source]

select [FIELD_NAME]… | “$direct” | “$full”

If an argument is given, set the selected fields. $direct selects all fields loaded in one http request. $full selects all fields using as much http requests as necessary.

If no argument is given, print the currently selected fields.

comp_key(obj)[source]
do_ls(*args, **kwargs)[source]

ls [-d] [-U] [PATH]

List objects in current path. If an argument is given, list the specified path. Use -U option to not sort results. It allows you to use a “fast path” to return results as soon as possible. Use -d option to display information about a collection (and to not display the content of it). It has the same behavior than the well known UNIX “ls” command.

Default is limited to 40 results.

do_cd(line)[source]

cd [PATH]

Follow a path. “..” is a special case and goes up one directory. “” is a special case and goes home.

all_collections()[source]

Get all objects that are collections: regular objects and fake dumb objects.

obj_to_filename(obj, dest=None, default=None)[source]

This method can be used to get a filename from an object, using a mask filled by information of this object.

All patterns are braces-enclosed, and are name of available fields in the object.

Parameters:
  • obj (BaseObject) – object

  • dest (str) – dest given by user (default None) (default: None)

  • default (str) – default file mask (if not given, this is ‘{id}-{title}.{ext}’) (default: None)

Return type:

str

complete_path(text, line, begidx, endidx)[source]
complete_ls(text, line, begidx, endidx)[source]
complete_cd(text, line, begidx, endidx)[source]
set_formatter(name)[source]

Set the current formatter from name.

It returns the name of the formatter which has been really set.

set_formatter_header(string)[source]
start_format(**kwargs)[source]
cached_format(obj)[source]
parse_fields(fields)[source]
format(result, alias=None)[source]
flush()[source]
do_debug(line)[source]

debug

Launch a debug Python shell