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

db_sync_tool.recipes.drupal   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 28
dl 0
loc 53
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A get_database_setting() 0 21 2
A check_configuration() 0 18 1
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
    _os = helper.check_os(client).strip()
19
    _path = system.config[client]['path']
20
21
    _db_config = {
22
        'name': get_database_setting(client, 'database', _path, _os),
23
        'host': get_database_setting(client, 'host', _path, _os),
24
        'password': get_database_setting(client, 'password', _path, _os),
25
        'port': get_database_setting(client, 'port', _path, _os),
26
        'user': get_database_setting(client, 'username', _path, _os),
27
    }
28
29
    system.config[client]['db'] = _db_config
30
31
32
def get_database_setting(client, name, file, os):
0 ignored issues
show
Comprehensibility Bug introduced by
os is re-defining a name which is already available in the outer-scope (previously defined on line 5).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
Coding Style Naming introduced by
Argument name "os" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
33
    """
34
    Parsing a single database variable from the settings.php file
35
    :param client: String
36
    :param name: String
37
    :param file: String
38
    :param os: String
39
    :return:
40
    """
41
    if os == 'Darwin':
0 ignored issues
show
unused-code introduced by
Unnecessary "else" after "return"
Loading history...
42
        return mode.run_command(
43
            helper.get_command(client, 'perl') + ' -nle "print $& while m{(?<=\'' + name + '\' => ).*(?=,)}g" ' + file + '| head -n 1',
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (135/100).

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

Loading history...
44
            client,
45
            True
46
        ).replace('"', '').replace('\'', '').replace('\n', '')
47
    else:
48
        return mode.run_command(
49
            helper.get_command(client, 'grep') + f' -Po "(?<=\'{name}\' => ).*(?=,)" {file}',
50
            client,
51
            True
52
        ).replace('"', '').replace('\'', '').replace('\n', '')
53
0 ignored issues
show
coding-style introduced by
Trailing newlines
Loading history...
54