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

db_sync_tool.recipes.wordpress   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 21
dl 0
loc 45
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A get_database_setting() 0 14 1
A check_configuration() 0 17 2
1
#!/usr/bin/env python3
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# -*- coding: utf-8 -*-
3
4
import json
0 ignored issues
show
Unused Code introduced by
The import json seems to be unused.
Loading history...
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 Drupal database configuration
15
    :param client: String
16
    :return:
17
    """
18
    _path = system.config[client]['path']
19
20
    _db_config = {
21
        'name': get_database_setting(client, 'DB_NAME', system.config[client]['path']),
22
        'host': get_database_setting(client, 'DB_HOST', system.config[client]['path']),
23
        'password': get_database_setting(client, 'DB_PASSWORD', system.config[client]['path']),
24
        'port': get_database_setting(client, 'DB_PORT', system.config[client]['path']) if get_database_setting(client, 'DB_PORT', system.config[client]['path']) != '' else 3306,
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (177/100).

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

Loading history...
25
        'user': get_database_setting(client, 'DB_USER', system.config[client]['path']),
26
    }
27
28
    system.config[client]['db'] = _db_config
29
30
31
def get_database_setting(client, name, file):
32
    """
33
    Parsing a single database variable from the wp-config.php file
34
    https://stackoverflow.com/questions/63493645/extract-database-name-from-a-wp-config-php-file
35
    :param client: String
36
    :param name: String
37
    :param file: String
38
    :return:
39
    """
40
    return mode.run_command(
41
        helper.get_command(client, 'sed') + f' -n "s/define( *\'{name}\', *\'\([^\']*\)\'.*/\\1/p" {file}',
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...
Bug introduced by
A suspicious escape sequence \( was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
Bug introduced by
A suspicious escape sequence \) was found. Did you maybe forget to add an r prefix?

Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with r or R are they interpreted as regular expressions.

The escape sequence that was used indicates that you might have intended to write a regular expression.

Learn more about the available escape sequences. in the Python documentation.

Loading history...
42
        client,
43
        True
44
    ).replace('\n', '')
45
0 ignored issues
show
coding-style introduced by
Trailing newlines
Loading history...
46