file_sync_tool.transfer.process.transfer_files()   B
last analyzed

Complexity

Conditions 6

Size

Total Lines 48
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 33
nop 0
dl 0
loc 48
rs 8.1546
c 0
b 0
f 0
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 'exclude' not in config:
22
                config['exclude'] = []
23
24
            if mode.get_sync_mode() == mode.SyncMode.PROXY:
25
                # Proxy mode: Transferring from origin to local and from local to target
26
                utility.generate_temp_dir_name()
27
                helper.check_and_create_dump_dir(mode.Client.LOCAL, utility.temp_data_dir)
28
                synchronize(
29
                    origin_path=config[mode.Client.ORIGIN],
30
                    target_path=utility.temp_data_dir,
31
                    exclude=config['exclude'],
32
                    pseudo_client=mode.Client.ORIGIN
33
                )
34
                synchronize(
35
                    origin_path=f'{utility.temp_data_dir}/*',
36
                    target_path=config[mode.Client.TARGET],
37
                    exclude=config['exclude'],
38
                    pseudo_client=mode.Client.TARGET
39
                )
40
                utility.remove_temporary_dir()
41
            elif mode.get_sync_mode() == mode.SyncMode.SYNC_REMOTE:
42
                synchronize(
43
                    origin_path=config[mode.Client.ORIGIN],
44
                    target_path=config[mode.Client.TARGET],
45
                    exclude=config['exclude'],
46
                    client=mode.Client.ORIGIN,
47
                    force_remote=True
48
                )
49
            else:
50
                synchronize(
51
                    origin_path=config[mode.Client.ORIGIN],
52
                    target_path=config[mode.Client.TARGET],
53
                    exclude=config['exclude']
54
                )
55
    else:
56
        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...
57
58
59
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...
60
    """
61
    Using rsync command to synchronize files between systems
62
    :param origin_path: String
63
    :param target_path: String
64
    :param exclude: List
65
    :param client: String
66
    :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...
67
    :param force_remote: Boolean
68
    :return:
69
    """
70
    _remote_client = None
71
    if force_remote:
72
        remote_client.load_ssh_client_origin()
73
        _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...
74
        _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...
75
    elif mode.is_remote(mode.Client.ORIGIN) and pseudo_client != mode.Client.TARGET:
76
        _remote_client = mode.Client.ORIGIN
77
        _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...
78
        _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...
79
    elif mode.is_remote(mode.Client.TARGET) and pseudo_client != mode.Client.ORIGIN:
80
        _remote_client = mode.Client.TARGET
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}[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...
83
    elif not mode.is_remote(mode.Client.TARGET) and not mode.is_remote(mode.Client.ORIGIN):
84
        _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...
85
        _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...
86
87
    _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...
88
    _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...
89
90
    if not system.config['mute']:
91
        print(
92
            f'{_origin_subject}'
93
            f'{_origin_name}'
94
            f'{output.CliFormat.BLACK}{origin_path}{output.CliFormat.ENDC}'
95
        )
96
97
        print(
98
            f'{_target_subject}'
99
            f'{_target_name}'
100
            f'{output.CliFormat.BLACK}{target_path}{output.CliFormat.ENDC}'
101
        )
102
103
    _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...
104
    _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...
105
106
    _output = mode.run_command(
107
        f'{utility.get_password_environment(_remote_client)}rsync {utility.get_options()} '
108
        f'{utility.get_authorization(_remote_client)} {utility.get_excludes(exclude)}'
109
        f'{_origin_user_host}{origin_path} {_target_user_host}{target_path}',
110
        client,
111
        True
112
    )
113
    utility.read_stats(_output)
114
0 ignored issues
show
coding-style introduced by
Trailing newlines
Loading history...
115