1
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
|
4
|
|
|
import json |
|
|
|
|
5
|
|
|
import os |
|
|
|
|
6
|
|
|
import sys |
|
|
|
|
7
|
|
|
from subprocess import check_output |
|
|
|
|
8
|
|
|
|
9
|
|
|
from db_sync_tool.utility import mode, system, helper, output |
|
|
|
|
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): |
|
|
|
|
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': |
|
|
|
|
42
|
|
|
return mode.run_command( |
43
|
|
|
helper.get_command(client, 'perl') + ' -nle "print $& while m{(?<=\'' + name + '\' => ).*(?=,)}g" ' + file + '| head -n 1', |
|
|
|
|
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
|
|
|
|
|
|
|
|
54
|
|
|
|