How to use the moler.cmd.unix.genericunix.GenericUnixCommand function in moler

To help you get started, we’ve selected a few moler examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nokia / moler / moler / cmd / unix / ntpq.py View on Github external
# -*- coding: utf-8 -*-
"""
Ntpq command module.
"""

__author__ = 'Sylwester Golonka'
__copyright__ = 'Copyright (C) 2018, Nokia'
__email__ = 'sylwester.golonka@nokia.com'

import re
from moler.cmd.unix.genericunix import GenericUnixCommand
from moler.exceptions import ParsingDone


class Ntpq(GenericUnixCommand):
    def __init__(self, connection, options=None, prompt=None, new_line_chars=None):
        super(Ntpq, self).__init__(connection, prompt, new_line_chars)
        self.options = options
        self.headers = []
        self.row_nr = 0

    def build_command_string(self):
        cmd = "ntpq"
        if self.options:
            cmd = "{} {}".format(cmd, self.options)
        return cmd

    def on_new_line(self, line, is_full_line):
        if is_full_line:
            try:
                self._parse_tab_details(line)
github nokia / moler / moler / cmd / unix / history.py View on Github external
# -*- coding: utf-8 -*-
"""
History command module.
"""

__author__ = 'Marcin Szlapa'
__copyright__ = 'Copyright (C) 2019, Nokia'
__email__ = 'marcin.szlapa@nokia.com'

from moler.cmd.unix.genericunix import GenericUnixCommand
from moler.exceptions import ParsingDone
from moler.helpers import convert_to_number
import re


class History(GenericUnixCommand):
    """Unix command history."""

    def __init__(self, connection, prompt=None, newline_chars=None, runner=None):
        """
        Unix command history.
        :param connection: moler connection to device, terminal when command is executed
        :param prompt: expected prompt sending by device after command execution
        :param newline_chars: Characters to split lines
        :param runner: Runner to run command
        """
        super(History, self).__init__(connection=connection, prompt=prompt, newline_chars=newline_chars,
                                      runner=runner)

    def build_command_string(self):
        """
        Build command string from parameters passed to object.
github nokia / moler / moler / cmd / unix / mkdir.py View on Github external
# -*- coding: utf-8 -*-
"""
Mkdir command module.
"""
__author__ = 'Sylwester Golonka'
__copyright__ = 'Copyright (C) 2018, Nokia'
__email__ = 'sylwester.golonka@nokia.com'

from moler.cmd.unix.genericunix import GenericUnixCommand
from moler.exceptions import CommandFailure
from moler.exceptions import ParsingDone
import re


class Mkdir(GenericUnixCommand):
    def __init__(self, connection, path, options=None, prompt=None, new_line_chars=None):
        super(Mkdir, self).__init__(connection, prompt=prompt, new_line_chars=new_line_chars)
        self.path = path
        self.options = options
        self.ret_required = False

    def build_command_string(self):
        cmd = "mkdir"
        if self.options:
            cmd = "{} {} {}".format(cmd, self.path, self.options)
        else:
            cmd = "{} {}".format(cmd, self.path)
        return cmd

    def on_new_line(self, line, is_full_line):
        if is_full_line:
github nokia / moler / moler / cmd / unix / sed.py View on Github external
Sed command module.
"""

__author__ = 'Agnieszka Bylica, Marcin Usielski'
__copyright__ = 'Copyright (C) 2018-2019, Nokia'
__email__ = 'agnieszka.bylica@nokia.com, marcin.usielski@nokia.com'


import re

from moler.cmd.unix.genericunix import GenericUnixCommand
from moler.exceptions import CommandFailure
from moler.exceptions import ParsingDone


class Sed(GenericUnixCommand):

    def __init__(self, connection, input_files, prompt=None, newline_chars=None, runner=None, options=None,
                 scripts=None, script_files=None, output_file=None):
        super(Sed, self).__init__(connection=connection, prompt=prompt, newline_chars=newline_chars, runner=runner)

        # Parameters defined by calling the command
        self.options = options            # string or None
        self.scripts = scripts            # list of strings or None
        self.script_files = script_files  # list of strings or None
        self.input_files = input_files    # list of strings
        self.output_file = output_file    # string or None

        self._is_input_file()

        # Other parameters
        self.current_ret['RESULT'] = list()
github nokia / moler / moler / cmd / unix / cp.py View on Github external
# -*- coding: utf-8 -*-
"""
Cp command module.
"""

__author__ = 'Julia Patacz, Marcin Usielski'
__copyright__ = 'Copyright (C) 2018-2019, Nokia'
__email__ = 'julia.patacz@nokia.com, marcin.usielski@nokia.com'


from moler.cmd.unix.genericunix import GenericUnixCommand
from moler.exceptions import CommandFailure


class Cp(GenericUnixCommand):
    def __init__(self, connection, src, dst, options=None, prompt=None, newline_chars=None, runner=None):
        super(Cp, self).__init__(connection=connection, prompt=prompt, newline_chars=newline_chars, runner=runner)

        self.src = src
        self.dst = dst
        self.options = options
        self.ret_required = False

        # self._reg_fail = compile(r'(cp\: cannot access)')

    def build_command_string(self):
        if self.options:
            cmd = "{} {} {} {}".format("cp", self.options, self.src, self.dst)
        else:
            cmd = "{} {} {}".format("cp", self.src, self.dst)
        return cmd
github nokia / moler / moler / cmd / unix / mv.py View on Github external
# -*- coding: utf-8 -*-
"""
Mv command module.
"""

__author__ = 'Maciej Malczyk'
__copyright__ = 'Copyright (C) 2018, Nokia'
__email__ = 'maciej.malczyk@nokia.com'
import re
from moler.cmd.unix.genericunix import GenericUnixCommand
from moler.exceptions import CommandFailure, ParsingDone


class Mv(GenericUnixCommand):
    def __init__(self, connection, src, dst, options=None, prompt=None, new_line_chars=None):
        super(Mv, self).__init__(connection, prompt=prompt, new_line_chars=new_line_chars)

        self.src = src
        self.dst = dst
        self.options = options
        self.ret_required = False

    def build_command_string(self):
        return "{} {} {} {}".format("mv", self.src, self.dst, self.options) if self.options else "{} {} {}" \
            .format("mv", self.src, self.dst)

    def on_new_line(self, line, is_full_line):
        if self._cmd_output_started:
            try:
                self._parse_errors(line)
github nokia / moler / moler / cmd / unix / genericunix.py View on Github external
def is_failure_indication(self, line):
        """
        Method to detect if passed line contains part indicating failure of command

        :param line: Line from command output on device
        :return: Match object if find regex in line, None otherwise.
        """
        if self._re_fail:
            return self._regex_helper.search_compiled(GenericUnixCommand._re_fail, line)
        return None
github nokia / moler / moler / cmd / unix / date.py View on Github external
# -*- coding: utf-8 -*-
"""
Date command module.
"""

__author__ = 'Tomasz Krol, Michal Ernst'
__copyright__ = 'Copyright (C) 2018-2019, Nokia'
__email__ = 'tomasz.krol@nokia.com, michal.ernst@nokia.com'

import re

from moler.cmd.unix.genericunix import GenericUnixCommand


class Date(GenericUnixCommand):
    def __init__(self, connection, options=None, date_table_output=True, prompt=None, newline_chars=None, runner=None):
        super(Date, self).__init__(connection=connection, prompt=prompt, newline_chars=newline_chars, runner=runner)

        self.ret_required = False
        self.options = options
        self.date_table_output = date_table_output

    def build_command_string(self):
        cmd = "date"

        if self.options:
            cmd = "{} {}".format(cmd, self.options)

        if self.date_table_output:
            cmd = """{} \
'+DATE:%t%t%d-%m-%Y%n\
github nokia / moler / moler / cmd / unix / genericunix.py View on Github external
def on_new_line(self, 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

        :param line: Line to parse, new lines are trimmed
        :param is_full_line:  False for chunk of line; True on full line (NOTE: new line character removed)
        :return: None
        """
        if is_full_line and self.is_failure_indication(line):
            self.set_exception(CommandFailure(self, "command failed in line '{}'".format(line)))
        return super(GenericUnixCommand, self).on_new_line(line, is_full_line)
github nokia / moler / moler / cmd / unix / df.py View on Github external
"""
Df command module.
"""

__author__ = 'Yeshu Yang'
__copyright__ = 'Copyright (C) 2018, Nokia'
__email__ = 'yeshu.yang@nokia.com'

import re

from moler.cmd.unix.genericunix import GenericUnixCommand
from moler.cmd.converterhelper import ConverterHelper
from moler.exceptions import ParsingDone


class Df(GenericUnixCommand):

    def __init__(self, connection, prompt=None, new_line_chars=None):
        super(Df, self).__init__(connection, prompt, new_line_chars)
        self._converter_helper = ConverterHelper()

    def build_command_string(self):
        cmd = "df -BM -T -P"
        return cmd

    def on_new_line(self, line, is_full_line):
        if is_full_line:
            try:
                self._parse_filesystem_line(line)
            except ParsingDone:
                pass
        return super(Df, self).on_new_line(line, is_full_line)