Passed
Push — master ( 095056...6f2dac )
by Konrad
01:18
created

file_sync_tool.transfer.process   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 66
dl 0
loc 111
rs 10
c 0
b 0
f 0
wmc 18

2 Functions

Rating   Name   Duplication   Size   Complexity  
B transfer_files() 0 45 5
D synchronize() 0 55 13
1
#!/usr/bin/env python3
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# -*- coding: future_fstrings -*-
3
4
from db_sync_tool.utility import mode, system, output, helper
5
from db_sync_tool.remote import client as remote_client
6
from file_sync_tool.transfer import utility
7
8
9
def transfer_files():
10
    """
11
    Transfering configured files between clients
12
    :return:
13
    """
14
    if 'files' in system.config:
15
        for config in system.config['files']['config']:
16
            output.message(
17
                output.Subject.INFO,
18
                f'Starting rsync file transfer'
0 ignored issues
show
introduced by
Using an f-string that does not have any interpolated variables
Loading history...
19
            )
20
21
            if mode.get_sync_mode() == mode.SyncMode.PROXY:
22
                # Proxy mode: Transferring from origin to local and from local to target
23
                utility.generate_temp_dir_name()
24
                helper.check_and_create_dump_dir(mode.Client.LOCAL, utility.temp_data_dir)
25
                synchronize(
26
                    origin_path=config[mode.Client.ORIGIN],
27
                    target_path=utility.temp_data_dir,
28
                    exclude=config['exclude'],
29
                    pseudo_client=mode.Client.ORIGIN
30
                )
31
                synchronize(
32
                    origin_path=f'{utility.temp_data_dir}/*',
33
                    target_path=config[mode.Client.TARGET],
34
                    exclude=config['exclude'],
35
                    pseudo_client=mode.Client.TARGET
36
                )
37
                utility.remove_temporary_dir()
38
            if mode.get_sync_mode() == mode.SyncMode.SYNC_REMOTE:
39
                synchronize(
40
                    origin_path=config[mode.Client.ORIGIN],
41
                    target_path=config[mode.Client.TARGET],
42
                    exclude=config['exclude'],
43
                    client=mode.Client.ORIGIN,
44
                    force_remote=True
45
                )
46
            else:
47
                synchronize(
48
                    origin_path=config[mode.Client.ORIGIN],
49
                    target_path=config[mode.Client.TARGET],
50
                    exclude=config['exclude']
51
                )
52
    else:
53
        f'{output.Subject.WARNING} No file sync configuration provided'
0 ignored issues
show
Unused Code introduced by
This statement seems to have no effect and could be removed.

This issue is typically triggered when a function that does not have side-effects is called and the return value is discarded:

class SomeClass:
    def __init__(self):
        self._x = 5

    def squared(self):
        return self._x * self._x

some_class = SomeClass()
some_class.squared()        # Flagged, as the return value is not used
print(some_class.squared()) # Ok
Loading history...
54
55
56
def synchronize(origin_path, target_path, exclude, client=mode.Client.LOCAL, pseudo_client=None, force_remote=False):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (117/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
best-practice introduced by
Too many arguments (6/5)
Loading history...
57
    """
58
    Using rsync command to synchronize files between systems
59
    :param origin_path: String
60
    :param target_path: String
61
    :param exclude: List
62
    :param client: String
63
    :param pseudo_client: String Client, which will be forced as remote client. Necessary for proxy transfer.
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (109/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
64
    :param force_remote: Boolean
65
    :return:
66
    """
67
    _remote_client = None
68
    if force_remote:
69
        remote_client.load_ssh_client_origin()
70
        _origin_subject = f'{output.Subject.ORIGIN}{output.CliFormat.BLACK}[REMOTE]{output.CliFormat.ENDC} '
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
71
        _target_subject = f'{output.Subject.TARGET}{output.CliFormat.BLACK}[REMOTE]{output.CliFormat.ENDC} '
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
72
    elif mode.is_remote(mode.Client.ORIGIN) and pseudo_client != mode.Client.TARGET:
73
        _remote_client = mode.Client.ORIGIN
74
        _origin_subject = f'{output.Subject.ORIGIN}{output.CliFormat.BLACK}[REMOTE]{output.CliFormat.ENDC} '
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
75
        _target_subject = f'{output.Subject.TARGET}{output.CliFormat.BLACK}[LOCAL]{output.CliFormat.ENDC} '
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (107/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
76
    elif mode.is_remote(mode.Client.TARGET) and pseudo_client != mode.Client.ORIGIN:
77
        _remote_client = mode.Client.TARGET
78
        _origin_subject = f'{output.Subject.ORIGIN}{output.CliFormat.BLACK}[LOCAL]{output.CliFormat.ENDC} '
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (107/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
79
        _target_subject = f'{output.Subject.TARGET}{output.CliFormat.BLACK}[REMOTE]{output.CliFormat.ENDC} '
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
80
    elif not mode.is_remote(mode.Client.TARGET) and not mode.is_remote(mode.Client.ORIGIN):
81
        _origin_subject = f'{output.Subject.ORIGIN}{output.CliFormat.BLACK}[LOCAL]{output.CliFormat.ENDC} '
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (107/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
82
        _target_subject = f'{output.Subject.TARGET}{output.CliFormat.BLACK}[LOCAL]{output.CliFormat.ENDC} '
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (107/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
83
84
    _origin_name = helper.get_ssh_host_name(mode.Client.ORIGIN, True) if _remote_client == mode.Client.ORIGIN else ''
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (117/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
85
    _target_name = helper.get_ssh_host_name(mode.Client.TARGET, True) if _remote_client == mode.Client.TARGET else ''
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (117/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
86
87
    if not system.config['mute']:
88
        print(
89
            f'{_origin_subject}'
90
            f'{_origin_name}'
91
            f'{output.CliFormat.BLACK}{origin_path}{output.CliFormat.ENDC}'
92
        )
93
94
        print(
95
            f'{_target_subject}'
96
            f'{_target_name}'
97
            f'{output.CliFormat.BLACK}{target_path}{output.CliFormat.ENDC}'
98
        )
99
100
    _origin_user_host = utility.get_host(mode.Client.ORIGIN) if _remote_client == mode.Client.ORIGIN else ''
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
101
    _target_user_host = utility.get_host(mode.Client.TARGET) if _remote_client == mode.Client.TARGET else ''
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (108/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
102
103
    _output = mode.run_command(
104
        f'{utility.get_password_environment(_remote_client)}rsync {utility.get_options()} '
105
        f'{utility.get_authorization(_remote_client)} {utility.get_excludes(exclude)}'
106
        f'{_origin_user_host}{origin_path} {_target_user_host}{target_path}',
107
        client,
108
        True
109
    )
110
    utility.read_stats(_output)
111
0 ignored issues
show
coding-style introduced by
Trailing newlines
Loading history...
112