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

create_origin_database_dump()   A

Complexity

Conditions 2

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 28
rs 9.45
c 0
b 0
f 0
cc 2
nop 0
1
#!/usr/bin/env python3
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# -*- coding: utf-8 -*-
3
4
from db_sync_tool.utility import parser, mode, system, helper, output
5
from db_sync_tool.database import utility
6
7
8
def create_origin_database_dump():
9
    """
10
    Creating the origin database dump file
11
    :return:
12
    """
13
    if not mode.is_import():
14
        parser.get_database_configuration(mode.Client.ORIGIN)
15
        utility.generate_database_dump_filename()
16
        helper.check_and_create_dump_dir(mode.Client.ORIGIN, helper.get_dump_dir(mode.Client.ORIGIN))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (101/100).

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

Loading history...
17
18
        _dump_file_path = helper.get_dump_dir(mode.Client.ORIGIN) + utility.database_dump_file_name
19
20
        output.message(
21
            output.Subject.ORIGIN,
22
            'Creating database dump',
23
            True
24
        )
25
        mode.run_command(
26
            helper.get_command('origin', 'mysqldump') + ' --no-tablespaces ' +
27
            utility. generate_mysql_credentials('origin') + ' ' +
28
            system.config['origin']['db']['name'] + ' ' +
29
            utility.generate_ignore_database_tables() +
30
            ' > ' + _dump_file_path,
31
            mode.Client.ORIGIN
32
        )
33
34
        utility.check_database_dump(mode.Client.ORIGIN, _dump_file_path)
35
        prepare_origin_database_dump()
36
37
38
def import_database_dump():
39
    """
40
    Importing the selected database dump file
41
    :return:
42
    """
43
    if (not system.option['is_same_client'] and not mode.is_import()):
44
        prepare_target_database_dump()
45
46
    if not system.option['keep_dump'] and not system.option['is_same_client']:
47
        output.message(
48
            output.Subject.TARGET,
49
            'Importing database dump',
50
            True
51
        )
52
53
        if not mode.is_import():
54
           _dump_path = helper.get_dump_dir(mode.Client.TARGET) + utility.database_dump_file_name
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 11 were found.
Loading history...
55
        else:
56
           _dump_path = system.option['import']
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 12 spaces were expected, but 11 were found.
Loading history...
57
58
        utility.check_database_dump(mode.Client.TARGET, _dump_path)
59
        mode.run_command(
60
            helper.get_command('target', 'mysql') + ' ' + utility.generate_mysql_credentials('target') + ' ' +
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (110/100).

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

Loading history...
61
            system.config['target']['db']['name'] + ' < ' + _dump_path,
62
            mode.Client.TARGET
63
        )
64
65
66
def prepare_origin_database_dump():
67
    """
68
    Preparing the origin database dump file by compressing them as .tar.gz
69
    :return:
70
    """
71
    output.message(
72
        output.Subject.ORIGIN,
73
        'Compressing database dump',
74
        True
75
    )
76
    mode.run_command(
77
        helper.get_command(mode.Client.ORIGIN, 'tar') + ' cfvz ' + helper.get_dump_dir(
78
            mode.Client.ORIGIN) + utility.database_dump_file_name + '.tar.gz -C ' + helper.get_dump_dir(
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

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

Loading history...
79
            mode.Client.ORIGIN) + ' ' + utility.database_dump_file_name + ' > /dev/null',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 4 spaces).
Loading history...
80
        mode.Client.ORIGIN
81
    )
82
83
84
def prepare_target_database_dump():
85
    """
86
    Preparing the target database dump by the unpacked .tar.gz file
87
    :return:
88
    """
89
    output.message(output.Subject.TARGET, 'Extracting database dump', True)
90
    mode.run_command(
91
        helper.get_command('target', 'tar') + ' xzf ' + helper.get_dump_dir(
92
            mode.Client.TARGET) + utility.database_dump_file_name + '.tar.gz -C ' + helper.get_dump_dir(
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (104/100).

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

Loading history...
93
            mode.Client.TARGET) + ' > /dev/null',
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 4 spaces).
Loading history...
94
        mode.Client.TARGET
95
    )
96