add expected_prompt parameter
cd command module.
"""
-__author__ = 'Michal Ernst, Marcin Usielski'
-__copyright__ = 'Copyright (C) 2018, Nokia'
-__email__ = 'michal.ernst@nokia.com, marcin.usielski@nokia.com'
+__author__ = 'Michal Ernst, Marcin Usielski, Tomasz Krol'
+__copyright__ = 'Copyright (C) 2018-2019, Nokia'
+__email__ = 'michal.ernst@nokia.com, marcin.usielski@nokia.com, tomasz.krol@nokia.com'
-from re import compile, escape, IGNORECASE
+from moler.exceptions import ParsingDone
from moler.cmd.unix.genericunix import GenericUnixCommand
+from moler.cmd.commandtextualgeneric import CommandTextualGeneric
class Cd(GenericUnixCommand):
- def __init__(self, connection, path=None, prompt=None, newline_chars=None, runner=None):
+ def __init__(self, connection, path=None, prompt=None, newline_chars=None, runner=None, expected_prompt=None):
+ """
+ :param connection: moler connection to device
+ :param prompt: start prompt (on system where command cd starts)
+ :param path: path to directory
+ :param expected_prompt: Prompt after change directory
+ :param newline_chars: Characters to split lines
+ :param runner: Runner to run command
+ """
super(Cd, self).__init__(connection=connection, prompt=prompt, newline_chars=newline_chars, runner=runner)
# Parameters defined by calling the command
@@ -22,6 +31,7 @@ class Cd(GenericUnixCommand):
# command parameters
self.ret_required = False
+ self._re_expected_prompt = CommandTextualGeneric._calculate_prompt(expected_prompt) # Expected prompt on device
def build_command_string(self):
cmd = "cd"
@@ -29,6 +39,20 @@ class Cd(GenericUnixCommand):
cmd = "{} {}".format(cmd, self.path)
return cmd
+ def on_new_line(self, line, is_full_line):
+ if self._re_expected_prompt is not None:
+ try:
+ self._is_target_prompt(line)
+ except ParsingDone:
+ pass # line has been fully parsed by one of above parse-methods
+ else:
+ super(Cd, self).on_new_line(line, is_full_line)
+
+ def _is_target_prompt(self, line):
+ if self._regex_helper.search_compiled(self._re_expected_prompt, line):
+ if not self.done():
+ self.set_result({})
+ raise ParsingDone
# -----------------------------------------------------------------------------
# Following documentation is required for library CI.
@@ -37,6 +61,7 @@ class Cd(GenericUnixCommand):
# path is Optional.Path for Unix cd command
# -----------------------------------------------------------------------------
+
COMMAND_OUTPUT_ver_execute = """
host:~ # cd /home/ute/
host:/home/ute #
@@ -46,3 +71,13 @@ COMMAND_KWARGS_ver_execute = {'path': '/home/ute'}
COMMAND_RESULT_ver_execute = {
}
+
+COMMAND_OUTPUT_ver_expected_prompt = """
+host:~ # cd /home/ute/test
+host:/home/ute/test #
+"""
+
+COMMAND_KWARGS_ver_expected_prompt = {'path': '/home/ute/test', 'expected_prompt': r'host:/home/ute/test #\s+'}
+
+COMMAND_RESULT_ver_expected_prompt = {
+}
