wasp_general.command package¶
Submodules¶
wasp_general.command.command module¶
-
class
wasp_general.command.command.WCommand(*command_tokens)[source]¶ Bases:
wasp_general.command.command.WCommandProtoBasic WCommandProto implementation
-
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.WCommandProtoPrototype 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
WCommandSelectorobject is used.-
exec(*command_tokens, **command_env)[source]¶ WCommandProto.exec()implementation
-
match(*command_tokens, **command_env)[source]¶ WCommandProto.match()implementation
-
-
class
wasp_general.command.command.WCommandPrioritizedSelector(default_priority=30)[source]¶ Bases:
wasp_general.command.command.WCommandSelectorThis 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)
-
-
class
wasp_general.command.command.WCommandProto[source]¶ Bases:
objectPrototype 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
-
-
class
wasp_general.command.command.WCommandSelector[source]¶ Bases:
objectThis class store command and selects suitable command for the given tokens.
-
class
wasp_general.command.command.WCommandSet(command_selector=None, tracked_vars=None)[source]¶ Bases:
objectClass 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:
ExceptionException that is raised when no suitable command was found during
WCommandSet.exec()method
-
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()methodParameters: var_name – target variable name Returns: anything
-
exception
-
class
wasp_general.command.command.WReduceCommand(selector, *reduce_tokens)[source]¶ Bases:
wasp_general.command.command.WCommandAliasCommand 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
-
wasp_general.command.context module¶
-
class
wasp_general.command.context.WCommandContext(base_command, context_adapter)[source]¶ Bases:
wasp_general.command.command.WCommandProtoCommand that can be adapted by a context
-
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
-
-
class
wasp_general.command.context.WCommandContextAdapter(context_specifications)[source]¶ Bases:
objectAdapter 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
-
-
class
wasp_general.command.context.WContext(context_name, context_value=None, linked_context=None)[source]¶ Bases:
wasp_general.command.context.WContextProtoWContextProtoimplementation-
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
-
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
-
class
EnumArgumentHelper(enum_cls)[source]¶ Bases:
wasp_general.command.enhanced.ArgumentCastingHelper
-
class
FlagArgumentCastingHelper[source]¶ Bases:
wasp_general.command.enhanced.ArgumentCastingHelperProto
-
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
-
class
-
class
wasp_general.command.enhanced.WCommandArgumentParser(*argument_descriptors, relationships=None)[source]¶ Bases:
object
-
class
wasp_general.command.enhanced.WCommandArgumentRelationship(relationship, *argument_names)[source]¶ Bases:
object
wasp_general.command.proto module¶
wasp_general.command.result module¶
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.WCommandSimple 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
WTemplateResultCommandwas constructed with tokens like “foo”, “bar” then only “foo bar” command will be matched. (Note. For example, ifWCommandobject 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: - command_tokens – same as command_tokens in
WCommandProto.match()andWCommandProto.exec()methods (so asWCommand._exec()) - command_env – same as command_env in
WCommandProto.match()andWCommandProto.exec()methods (so asWCommand._exec())
Returns: WCommandResultTemplate
- command_tokens – same as command_tokens in
-