db_sync_tool.recipes.wordpress   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 19
dl 0
loc 46
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A get_database_setting() 0 15 1
A check_configuration() 0 18 2
1
#!/usr/bin/env python3
2
# -*- coding: future_fstrings -*-
3
4
"""
5
Wordpress script
6
"""
7
8
from db_sync_tool.utility import mode, system, helper
9
10
11
def check_configuration(client):
12
    """
13
    Checking Drupal database configuration
14
    :param client: String
15
    :return:
16
    """
17
    _path = system.config[client]['path']
18
19
    _db_config = {
20
        'name': get_database_setting(client, 'DB_NAME', system.config[client]['path']),
21
        'host': get_database_setting(client, 'DB_HOST', system.config[client]['path']),
22
        'password': get_database_setting(client, 'DB_PASSWORD', system.config[client]['path']),
23
        'port': get_database_setting(client, 'DB_PORT', system.config[client]['path'])
24
        if get_database_setting(client, 'DB_PORT', system.config[client]['path']) != '' else 3306,
0 ignored issues
show
Coding Style introduced by
Wrong continued indentation (add 8 spaces).
Loading history...
25
        'user': get_database_setting(client, 'DB_USER', system.config[client]['path']),
26
    }
27
28
    system.config[client]['db'] = helper.clean_db_config(_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') +
42
        f' -n "s/define( *\'{name}\', *\'\([^\']*\)\'.*/\\1/p" {file}',
0 ignored issues
show
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...
43
        client,
44
        True
45
    ).replace('\n', '')
46