moler.cmd package

Subpackages

Submodules

moler.cmd.commandchangingprompt module

Generic command class for commands change prompt

class moler.cmd.commandchangingprompt.CommandChangingPrompt(connection, prompt, expected_prompt, newline_chars=None, runner=None, set_timeout=None, set_prompt=None, target_newline='n', allowed_newline_after_prompt=False, prompt_after_login=None)

Bases: moler.cmd.commandtextualgeneric.CommandTextualGeneric

Base class for textual commands to change prompt.

build_command_string()

Returns string with command constructed with parameters of object.

Returns:String with command.
on_new_line(line, is_full_line)

Parses the output of the command.

Parameters:
  • line – Line to process, can be only part of line. New line chars are removed from line.
  • is_full_line – True if line had new line chars, False otherwise
Returns:

None

moler.cmd.commandtextualgeneric module

Generic class for all command with textual output.

class moler.cmd.commandtextualgeneric.CommandTextualGeneric(connection, prompt=None, newline_chars=None, runner=None)

Bases: moler.command.Command

Base class for textual commands.

break_cmd(silent=False, force=False)

Send ctrl+c to device to break command execution.

Parameters:
  • silent – set False to log info the break is not sent
  • force – set True to break cmd even if the command does not run
Returns:

None

break_exec_regex

Getter for break_exec_regex

Returns:Regex object or None
build_command_string()

Returns string with command constructed with parameters of object.

Returns:String with command.
cancel()

Called by framework to cancel the command.

Returns:False if already cancelled or already done, True otherwise.
command_string

Getter for command_string.

Returns:String with command_string.
data_received(data, recv_time)

Called by framework when any data are sent by device.

Parameters:
  • data – List of strings sent by device.
  • recv_time – time stamp with the moment when the data was read from connection. Time is given as datetime.datetime instance.
Returns:

None.

has_any_result()

Checks if any result was already set by command.

Returns:True if current_ret has collected any data. Otherwise False.
has_endline_char(line)

Method to check if line has chars of new line at the right side.

Parameters:line – String to check.
Returns:True if any new line char was found, False otherwise.
is_end_of_cmd_output(line)

Checks if end of command is reached.

Parameters:line – Line from device.
Returns:True if end of command is reached, False otherwise.
on_done()

Callback called by framework when command is just about to finish.

Returns:None
on_failure()

Callback called by framework when command is just about to finish with failure. Set ret is called.

Returns:None
on_new_line(line, is_full_line)

Method to parse command output. Will be called after line with command echo. Write your own implementation but don’t forget to call on_new_line from base class in most cases.

Parameters:
  • line – Line to parse, new lines are trimmed
  • is_full_line – True if new line character was removed from line, False otherwise
Returns:

None

on_success()

Callback called by framework when command is just about to finish with success. Set ret is called.

Returns:None
on_timeout()

Callback called by framework when timeout occurs.

Returns:None.
send_command()

Sends command string over connection.

Returns:None
send_enter()

Sends enter over connection. :return: None

set_exception(exception)

Set exception object as failure for command object.

Parameters:exception – An exception object to set.
Returns:None.

Module contents

Package for implementing different commands based on Moler Command.

class moler.cmd.RegexHelper

Bases: object

Class to help with working with regular expressions.

get_match()

Returns match object.

Returns:Match object.
group(number)

Returns group from match object.

Parameters:number – Number or name of match object.
Returns:Match object.
groupdict()

Returns groupdict from match object.

Returns:Groupdict from match object.
groups()

Returns groups from match object.

Returns:Groups from match object.
match(pattern, string, flags=0)

Matches for passed pattern in passed string.

Parameters:
  • pattern – Pattern to find. Regular expression.
  • string – String to scan through to find the pattern.
  • flags – Flags for search.
Returns:

Match object.

match_compiled(compiled, string, raise_if_compiled_is_none=False)

Matches for passed pattern in passed string.

Parameters:
  • compiled – Compiled regular expression pattern to find.
  • string – String to scan through to find the pattern.
  • raise_if_compiled_is_none – set True to raise a WrongUsage if compiled is None. If False then return None.
Returns:

Match object.

search(pattern, string, flags=0)

Searches for passed pattern in passed string.

Parameters:
  • pattern – Pattern to find. Regular expression.
  • string – String to scan through to find the pattern.
  • flags – Flags for search.
Returns:

Match object.

search_compiled(compiled, string, raise_if_compiled_is_none=False)

Searches for passed pattern in passed string.

Parameters:
  • compiled – Compiled regular expression pattern to find.
  • string – String to scan through to find the pattern.
  • raise_if_compiled_is_none – set True to raise a WrongUsage if compiled is None. If False then return None.
Returns:

Match object.