db_sync_tool.remote.system   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 18
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A run_ssh_command_by_client() 0 11 2
A run_ssh_command() 0 20 4
1
#!/usr/bin/env python3
2
# -*- coding: future_fstrings -*-
3
4
"""
5
System script
6
"""
7
8
import sys
9
from db_sync_tool.utility import mode, output, helper
10
from db_sync_tool.remote import client as remote_client
11
12
13
def run_ssh_command_by_client(client, command):
14
    """
15
    Running origin ssh command
16
    :param client: String
17
    :param command: String
18
    :return:
19
    """
20
    if client == mode.Client.ORIGIN:
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
21
        return run_ssh_command(command, remote_client.ssh_client_origin, client)
22
    else:
23
        return run_ssh_command(command, remote_client.ssh_client_target, client)
24
25
26
def run_ssh_command(command, ssh_client=remote_client.ssh_client_origin, client=None):
27
    """
28
    Running ssh command
29
    :param command: String
30
    :param ssh_client:
31
    :param client: String
32
    :return:
33
    """
34
    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...
35
    exit_status = stdout.channel.recv_exit_status()
36
37
    err = stderr.read().decode()
38
39
    if err and exit_status != 0:
40
        helper.run_script(client=client, script='error')
41
        sys.exit(output.message(output.Subject.ERROR, err, False))
42
    elif err:
43
        output.message(output.Subject.WARNING, err, True)
44
45
    return stdout
46