Passed
Push — master ( b54d65...97311e )
by Konrad
08:59
created

db_sync_tool.recipes.drupal.get_database_setting()   A

Complexity

Conditions 2

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 21
rs 9.8
c 0
b 0
f 0
cc 2
nop 4
1
#!/usr/bin/env python3
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# -*- coding: future_fstrings -*-
3
4
import json
5
from db_sync_tool.utility import mode, system, helper, output
6
7
8
def check_configuration(client):
9
    """
10
    Checking Drupal database configuration with Drush
11
    :param client: String
12
    :return:
13
    """
14
    _path = system.config[client]['path']
15
16
    _raw_version = mode.run_command(
17
        f'{helper.get_command(client, "drush")} status --fields=drush-version --format=string -r {_path}',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (106/100).

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

Loading history...
18
        client,
19
        True
20
    )
21
    print(_raw_version)
22
    output.message(
23
        output.host_to_subject(client),
24
        f'Drush version: {_raw_version}',
25
        True
26
    )
27
28
    stdout = mode.run_command(
29
        f'{helper.get_command(client, "drush")} core-status --pipe '
30
        f'--fields=db-hostname,db-username,db-password,db-name,db-port '
31
        f'-r {_path}',
32
        client,
33
        True
34
    )
35
36
    _db_config = parse_database_credentials(json.loads(stdout))
37
38
    system.config[client]['db'] = _db_config
39
40
41
def parse_database_credentials(db_credentials):
42
    """
43
    Parsing database credentials to needed format
44
    :param db_credentials: Dictionary
45
    :return: Dictionary
46
    """
47
    _db_config = {
48
        'name': db_credentials['db-name'],
49
        'host': db_credentials['db-hostname'],
50
        'password': db_credentials['db-password'],
51
        'port': db_credentials['db-port'],
52
        'user': db_credentials['db-username'],
53
    }
54
55
    return _db_config
56