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

db_sync_tool.recipes.typo3   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 25
dl 0
loc 53
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A check_configuration() 0 18 1
A parse_database_credentials() 0 21 3
1
#!/usr/bin/env python3
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# -*- coding: utf-8 -*-
3
4
import json
5
import os
0 ignored issues
show
Unused Code introduced by
The import os seems to be unused.
Loading history...
6
import sys
0 ignored issues
show
Unused Code introduced by
The import sys seems to be unused.
Loading history...
7
from subprocess import check_output
0 ignored issues
show
Unused Code introduced by
Unused check_output imported from subprocess
Loading history...
8
9
from db_sync_tool.utility import mode, system, helper, output
0 ignored issues
show
Unused Code introduced by
Unused output imported from db_sync_tool.utility
Loading history...
10
11
12
def check_configuration(client):
13
    """
14
    Checking remote TYPO3 database configuration
15
    :param client: String
16
    :return:
17
    """
18
    _path = system.config[client]['path']
19
20
    stdout = mode.run_command(
21
        helper.get_command(client, 'php') + ' -r "echo json_encode(include \'' + system.config[client][
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (103/100).

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

Loading history...
22
            'path'] + '\');"',
23
        client,
24
        True
25
    )
26
27
    _db_config = parse_database_credentials(json.loads(stdout)['DB'])
28
29
    system.config[client]['db'] = _db_config
30
31
32
def parse_database_credentials(db_credentials):
33
    """
34
    Parsing database credentials to needed format
35
    :param db_credentials: Dictionary
36
    :return: Dictionary
37
    """
38
    #
39
    # Distinguish between database config scheme of TYPO3 v8+ and TYPO3 v7-
40
    #
41
    if 'Connections' in db_credentials:
42
        _db_config = db_credentials['Connections']['Default']
43
        _db_config['name'] = _db_config['dbname']
44
    else:
45
        _db_config = db_credentials
46
        _db_config['user'] = _db_config['username']
47
        _db_config['name'] = _db_config['database']
48
49
    if 'port' not in _db_config:
50
        _db_config['port'] = 3306
51
52
    return _db_config
53