Passed
Push — master ( ffbe9f...5c3c8b )
by Konrad
01:19
created

run_ssh_command_by_client()   A

Complexity

Conditions 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 3
nop 2
1
#!/usr/bin/env python3
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# -*- coding: utf-8 -*-
3
4
import sys
5
from db_sync_tool.utility import mode, output
6
from db_sync_tool.remote import client as remote_client
7
8
9
def run_ssh_command_by_client(client, command):
0 ignored issues
show
Unused Code introduced by
Either all return statements in a function should return an expression, or none of them should.
Loading history...
10
    """
11
    Running origin ssh command
12
    :param client: String
13
    :param command: String
14
    :return:
15
    """
16
    if client == mode.Client.ORIGIN:
0 ignored issues
show
unused-code introduced by
Unnecessary "elif" after "return"
Loading history...
17
        return run_ssh_command(command, remote_client.ssh_client_origin)
18
    elif client == mode.Client.TARGET:
19
        return run_ssh_command(command, remote_client.ssh_client_target)
20
21
22
def run_ssh_command(command, ssh_client=remote_client.ssh_client_origin):
23
    """
24
    Running ssh command
25
    :param command: String
26
    :param ssh_client:
27
    :return:
28
    """
29
    stdin, stdout, stderr = ssh_client.exec_command(command)
0 ignored issues
show
Unused Code introduced by
The variable stdin seems to be unused.
Loading history...
30
    exit_status = stdout.channel.recv_exit_status()
31
32
    err = stderr.read().decode()
33
34
    if err and 0 != exit_status:
0 ignored issues
show
introduced by
Comparison should be exit_status != 0
Loading history...
35
        sys.exit(output.message(output.Subject.ERROR, err, False))
36
    elif err:
37
        output.message(output.Subject.WARNING, err, True)
38
39
    return stdout
0 ignored issues
show
Coding Style introduced by
Final newline missing
Loading history...