wasp_general.command package

Submodules

wasp_general.command.command module

class wasp_general.command.command.WCommand(*command_tokens)[source]

Bases: wasp_general.command.command.WCommandProto

Basic WCommandProto implementation

command()[source]

Return command tokens

Returns:tuple of str
exec(*command_tokens, **command_env)[source]

WCommandProto.exec() implementation

(throws RuntimeError if tokens are invalid, and calls WCommand._exec() method)

match(*command_tokens, **command_env)[source]

WCommandProto.match() implementation

class wasp_general.command.command.WCommandAlias(selector)[source]

Bases: wasp_general.command.command.WCommandProto

Prototype for command, that doesn’t do anything useful itself, but it helps to run a modified command and to return its result. For getting any useful result a WCommandSelector object is used.

exec(*command_tokens, **command_env)[source]

WCommandProto.exec() implementation

match(*command_tokens, **command_env)[source]

WCommandProto.match() implementation

mutate_command_tokens(*command_tokens)[source]

Modify the input command so it can be called from the command selector

Parameters:command_tokens
Returns:
selector()[source]

Return original command selector

Returns:WCommandSelector
class wasp_general.command.command.WCommandPrioritizedSelector(default_priority=30)[source]

Bases: wasp_general.command.command.WCommandSelector

This class has priority for every stored commands. Command with lower priority value will be selected first.

add(command_obj)[source]

WCommandSelector.add() redefinition (sets default priority for the given command)

add_prioritized(command_obj, priority)[source]

Add command with the specified priority

Parameters:
  • command_obj – command to add
  • priority – command priority
Returns:

None

class wasp_general.command.command.WCommandProto[source]

Bases: object

Prototype for a single command. Command tokens are string, where each token is a part of the command name or is the command parameter. Tokens are generated from a string, each token is separated by space (if space is a part of the token, then it must be quoted). Any command may require some additional parameters that are generated from environment with which this command will be checked and/or called. This extra parameters calls command environment

exec(*command_tokens, **command_env)[source]

Execute valid command (that represent as tokens)

Parameters:
  • command_tokens – command to execute
  • command_env – command environment
Returns:

WCommandResultProto

static join_tokens(*command_tokens)[source]

Join tokens into a single string

Parameters:command_tokens – tokens to join
Returns:str
match(*command_tokens, **command_env)[source]

Checks whether this command can be called with the given tokens. Return True - if tokens match this command, False - otherwise

Parameters:
  • command_tokens – command to check
  • command_env – command environment
Returns:

bool

static split_command(command_str)[source]

Split command string into command tokens

Parameters:command_str – command to split
Returns:tuple of str
class wasp_general.command.command.WCommandSelector[source]

Bases: object

This class store command and selects suitable command for the given tokens.

add(command_obj)[source]

Add command to selector

Parameters:command_obj – command to add
Returns:None
select(*command_tokens, **command_env)[source]

Select suitable command, that matches the given tokens. Each new command to check is fetched with this object iterator (WCommandSelector.__iter__())

Parameters:
  • command_tokens – command
  • command_env – command environment
Returns:

WCommandProto

class wasp_general.command.command.WCommandSet(command_selector=None, tracked_vars=None)[source]

Bases: object

Class wraps routine of execution command from a command group. This class is able to keep command environment variables from previous commands results to use them in a future commands calls. Only those variables whose names were specified in a constructor will be kept.

exception NoCommandFound[source]

Bases: Exception

Exception that is raised when no suitable command was found during WCommandSet.exec() method

commands()[source]

Return used command selector

Returns:WCommandSelector
exec(command_str, **command_env)[source]

Execute the given command (command will be split into tokens, every space that is a part of a token must be quoted)

Parameters:
  • command_str – command to execute
  • command_env – command environment
Returns:

WCommandResultProto

has_var(var_name)[source]

Return True - if a environment variable with a specified name is kept by this command set. Otherwise - False is returned

Parameters:var_name – variable name to check
Returns:bool
tracked_vars()[source]

Return variables names that are kept (tracked) by this command set

Returns:tuple of str
var_value(var_name)[source]

Return value of environment variable that is kept by this command set.

Note:No checks are made if there is a such variable. It implies that there is a such variable.

For any doubt - use WCommandSet.has_var() method

Parameters:var_name – target variable name
Returns:anything
class wasp_general.command.command.WReduceCommand(selector, *reduce_tokens)[source]

Bases: wasp_general.command.command.WCommandAlias

Command that creates subsection from a command selector. The command will be matched to command tokens only if the first token matches to one of reduce tokens (section name/aliases) and the command selector has command for remaining tokens. Command execution works the same way. The command will be executed from the command selector without the first token and only if the first token matches to one of reduce tokens.

mutate_command_tokens(*command_tokens)[source]

WCommandAlias.mutate_command_tokens() implementation

reduce_tokens()[source]

Return section names (aliases)

Returns:tuple of str

wasp_general.command.context module

class wasp_general.command.context.WCommandContext(base_command, context_adapter)[source]

Bases: wasp_general.command.command.WCommandProto

Command that can be adapted by a context

adapter()[source]

Return command adapter

Returns:WCommandAdapter
exec(*command_tokens, command_context=None, **command_env)[source]

Execute command

Parameters:
  • command_tokens – command tokens to execute
  • command_context – command context
  • command_env – command environment
Returns:

WCommandResultProto

match(*command_tokens, command_context=None, **command_env)[source]

Match command

Parameters:
  • command_tokens – command tokens to check
  • command_context – command context
  • command_env – command environment
Returns:

bool

original_command()[source]

Return source command

Returns:WCommandProto
class wasp_general.command.context.WCommandContextAdapter(context_specifications)[source]

Bases: object

Adapter is used for command tokens modification

adapt(*command_tokens, command_context=None, **command_env)[source]

Adapt the given command tokens with this adapter

Parameters:
  • command_tokens – command tokens to adapt
  • command_context – context
  • command_env – command environment
Returns:

list of str

match(command_context=None, **command_env)[source]

Check if context request is compatible with adapters specification. True - if compatible, False - otherwise

Parameters:
  • command_context – context to check
  • command_env – command environment
Returns:

bool

specification()[source]

Return adapter specification

Returns:WContextProto or None
class wasp_general.command.context.WContext(context_name, context_value=None, linked_context=None)[source]

Bases: wasp_general.command.context.WContextProto

WContextProto implementation

context_name()[source]

WContextProto.context_name() implementation

context_value()[source]

WContextProto.context_value() implementation

classmethod export_context(context)[source]

Export the specified context to be capable context transferring

Parameters:context – context to export
Returns:tuple
classmethod import_context(context)[source]

Import context to corresponding WContextProto object (WContext.export_context() reverse operation)

Parameters:context – context to import
Returns:WContext
linked_context()[source]

WContextProto.linked_context() implementation

classmethod specification(*context_specs)[source]

Return linked context as adapter specification (is used by WCommandContextAdapter)

Parameters:context_specs – context names
Returns:WContext
class wasp_general.command.context.WContextComposer[source]

Bases: wasp_general.composer.WComposerProto

compose(obj_spec)[source]
decompose(obj)[source]
class wasp_general.command.context.WContextProto[source]

Bases: object

Represent context configuration

context_name()[source]

Return this context name

Returns:str
context_value()[source]

Return this context value (can be None)

Returns:str or None
linked_context()[source]

Return link to ‘parent’/’higher’ context

Returns:WContextProto or None

wasp_general.command.enhanced module

class wasp_general.command.enhanced.WCommandArgumentDescriptor(argument_name, required=False, flag_mode=False, multiple_values=False, help_info=None, meta_var=None, default_value=None, casting_helper=None)[source]

Bases: object

class ArgumentCastingHelper(casting_fn=None, validate_fn=None, error_message=None)[source]

Bases: wasp_general.command.enhanced.ArgumentCastingHelperProto

cast(argument_name, argument_value)[source]
casting_function()[source]
error_message()[source]
validate_function()[source]
class ArgumentCastingHelperProto[source]

Bases: object

cast(argument_name, argument_value)[source]
class DataSizeArgumentHelper[source]

Bases: wasp_general.command.enhanced.ArgumentCastingHelper

static cast_string(value)[source]
class EnumArgumentHelper(enum_cls)[source]

Bases: wasp_general.command.enhanced.ArgumentCastingHelper

cast_string(value)[source]
class FlagArgumentCastingHelper[source]

Bases: wasp_general.command.enhanced.ArgumentCastingHelperProto

cast(argument_name, argument_value)[source]
class FloatArgumentCastingHelper(validate_fn=None, error_message=None)[source]

Bases: wasp_general.command.enhanced.ArgumentCastingHelper

class IntegerArgumentCastingHelper(base=10, validate_fn=None, error_message=None)[source]

Bases: wasp_general.command.enhanced.ArgumentCastingHelper

class RegExpArgumentHelper(regexp)[source]

Bases: wasp_general.command.enhanced.ArgumentCastingHelper

cast_string(value)[source]
re()[source]
validate_function()[source]
class StringArgumentCastingHelper(validate_fn=None, error_message=None)[source]

Bases: wasp_general.command.enhanced.ArgumentCastingHelper

argument_name()[source]
cast(argument_name, argument_value)[source]
casting_helper()[source]
default_value()[source]
flag_mode()[source]
help_info()[source]
meta_var()[source]
multiple_values()[source]
required()[source]
class wasp_general.command.enhanced.WCommandArgumentParser(*argument_descriptors, relationships=None)[source]

Bases: object

arguments_help()[source]
descriptors()[source]
parse(*command_tokens)[source]
classmethod reduce_tokens(command_tokens, argument_descriptors, previous_result=None)[source]
relationships()[source]
exception wasp_general.command.enhanced.WCommandArgumentParsingError[source]

Bases: Exception

class wasp_general.command.enhanced.WCommandArgumentRelationship(relationship, *argument_names)[source]

Bases: object

class Relationship[source]

Bases: enum.Enum

An enumeration.

conflict = 1
one_of = 3
requirement = 2
arguments()[source]
relationship()[source]
class wasp_general.command.enhanced.WEnhancedCommand(command, *argument_descriptors, relationships=None)[source]

Bases: wasp_general.command.command.WCommandProto

argument_descriptors()[source]
arguments_help()[source]
command_help()[source]
command_token()[source]
exec(*command_tokens, **command_env)[source]
match(*command_tokens, **command_env)[source]
parser()[source]
relationships()[source]

wasp_general.command.proto module

class wasp_general.command.proto.WCommandResultProto[source]

Bases: object

environment()[source]

wasp_general.command.result module

class wasp_general.command.result.WCommandEnv(**command_env)[source]

Bases: wasp_general.command.proto.WCommandResultProto

environment()[source]
class wasp_general.command.result.WExceptionResult(message, exc, traceback, **command_env)[source]

Bases: wasp_general.command.result.WCommandEnv

exception()[source]
message()[source]
traceback()[source]
class wasp_general.command.result.WPlainCommandResult(result, **command_env)[source]

Bases: wasp_general.command.result.WCommandEnv

classmethod error(message, **command_env)[source]

wasp_general.command.template_command module

class wasp_general.command.template_command.WCommandResultTemplate(template, **command_env)[source]

Bases: wasp_general.command.result.WPlainCommandResult, wasp_general.template.WTemplateRenderer

class wasp_general.command.template_command.WTemplateResultCommand(template, *command_tokens, template_context=None)[source]

Bases: wasp_general.command.command.WCommand

Simple command that returns “template-result”, that can be “rendered” to str object later. In most time, this and derived classes return static template, which result is the same. The only requirement for execution of this command is to full command match. If WTemplateResultCommand was constructed with tokens like “foo”, “bar” then only “foo bar” command will be matched. (Note. For example, if WCommand object was constructed with tokens: “foo”, “bar”, then any of the following commands will be matched: “foo bar”, “foo bar 1”, “foo bar 2 3”.)

match(*command_tokens, **command_env)[source]

same as WCommand.meth() method, but checks for extra arguments also (no extra arguments is allowed)

result_template(*command_tokens, **command_env)[source]

Generate template result. command_tokens and command_env arguments are used for template detailing

Parameters:
Returns:

WCommandResultTemplate

template()[source]

Return template object (that will be used in result)

Returns:WTemplate
template_context()[source]

Return context with which template will be rendered

Returns:dict

Module contents