Code Duplication    Length = 38-41 lines in 2 locations

db_sync_tool/remote/transfer.py 2 locations

@@ 96-136 (lines=41) @@
93
        sys.stdout.write('\r')
94
95
96
def put_origin_database_dump(origin_path):
97
    """
98
    Uploading the origin database dump file
99
    :param origin_path: String
100
    :return:
101
    """
102
    if mode.get_sync_mode() == mode.SyncMode.PROXY:
103
        _subject = output.Subject.LOCAL
104
    else:
105
        _subject = output.Subject.ORIGIN
106
107
    output.message(
108
        _subject,
109
        'Uploading database dump',
110
        True
111
    )
112
    helper.check_and_create_dump_dir(mode.Client.TARGET, helper.get_dump_dir(mode.Client.TARGET))
113
114
    if not system.config['dry_run']:
115
        _localpath = origin_path + database_utility.database_dump_file_name + '.tar.gz'
116
        _remotepath = helper.get_dump_dir(mode.Client.TARGET) + '/'
117
118
        if system.config['use_rsync']:
119
            rsync.run_rsync_command(
120
                remote_client=mode.Client.TARGET,
121
                origin_path=_localpath,
122
                target_path=_remotepath,
123
                target_ssh=system.config[mode.Client.TARGET]['user'] + '@' + system.config[mode.Client.TARGET]['host']
124
            )
125
        else:
126
            #
127
            # Download speed problems
128
            # https://github.com/paramiko/paramiko/issues/60
129
            #
130
            sftp = get_sftp_client(client.ssh_client_target)
131
            sftp.put(origin_path + database_utility.database_dump_file_name + '.tar.gz',
132
                     helper.get_dump_dir(mode.Client.TARGET) + database_utility.database_dump_file_name + '.tar.gz',
133
                     upload_status)
134
            sftp.close()
135
            if not system.config['mute']:
136
                print('')
137
138
139
@@ 40-77 (lines=38) @@
37
        system.check_target_configuration()
38
39
40
def get_origin_database_dump(target_path):
41
    """
42
    Downloading the origin database dump files
43
    :param target_path: String
44
    :return:
45
    """
46
    output.message(
47
        output.Subject.ORIGIN,
48
        'Downloading database dump',
49
        True
50
    )
51
    if mode.get_sync_mode() != mode.SyncMode.PROXY:
52
        helper.check_and_create_dump_dir(mode.Client.TARGET, target_path)
53
54
    if not system.config['dry_run']:
55
        _remotepath = helper.get_dump_dir(mode.Client.ORIGIN) + database_utility.database_dump_file_name + '.tar.gz'
56
        _localpath = target_path
57
58
        if system.config['use_rsync']:
59
            rsync.run_rsync_command(
60
                remote_client=mode.Client.ORIGIN,
61
                origin_path=_remotepath,
62
                target_path=_localpath,
63
                origin_ssh=system.config[mode.Client.ORIGIN]['user'] + '@' + system.config[mode.Client.ORIGIN]['host']
64
            )
65
        else:
66
            #
67
            # Download speed problems
68
            # https://github.com/paramiko/paramiko/issues/60
69
            #
70
            sftp = get_sftp_client(client.ssh_client_origin)
71
            sftp.get(helper.get_dump_dir(mode.Client.ORIGIN) + database_utility.database_dump_file_name + '.tar.gz',
72
                     target_path + database_utility.database_dump_file_name + '.tar.gz', download_status)
73
            sftp.close()
74
            if not system.config['mute']:
75
                print('')
76
77
    utility.remove_origin_database_dump()
78
79
80
def download_status(sent, size):