|
1
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
|
|
2
|
|
|
# -*- coding: future_fstrings -*- |
|
3
|
|
|
|
|
4
|
|
|
import json |
|
5
|
|
|
from db_sync_tool.utility import mode, system, helper, output |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
def check_configuration(client): |
|
9
|
|
|
""" |
|
10
|
|
|
Checking Drupal database configuration with Drush |
|
11
|
|
|
:param client: String |
|
12
|
|
|
:return: |
|
13
|
|
|
""" |
|
14
|
|
|
_path = system.config[client]['path'] |
|
15
|
|
|
|
|
16
|
|
|
_raw_version = mode.run_command( |
|
17
|
|
|
f'{helper.get_command(client, "drush")} status --fields=drush-version --format=string -r {_path}', |
|
|
|
|
|
|
18
|
|
|
client, |
|
19
|
|
|
True |
|
20
|
|
|
) |
|
21
|
|
|
print(_raw_version) |
|
22
|
|
|
output.message( |
|
23
|
|
|
output.host_to_subject(client), |
|
24
|
|
|
f'Drush version: {_raw_version}', |
|
25
|
|
|
True |
|
26
|
|
|
) |
|
27
|
|
|
|
|
28
|
|
|
stdout = mode.run_command( |
|
29
|
|
|
f'{helper.get_command(client, "drush")} core-status --pipe ' |
|
30
|
|
|
f'--fields=db-hostname,db-username,db-password,db-name,db-port ' |
|
31
|
|
|
f'-r {_path}', |
|
32
|
|
|
client, |
|
33
|
|
|
True |
|
34
|
|
|
) |
|
35
|
|
|
|
|
36
|
|
|
_db_config = parse_database_credentials(json.loads(stdout)) |
|
37
|
|
|
|
|
38
|
|
|
system.config[client]['db'] = _db_config |
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
def parse_database_credentials(db_credentials): |
|
42
|
|
|
""" |
|
43
|
|
|
Parsing database credentials to needed format |
|
44
|
|
|
:param db_credentials: Dictionary |
|
45
|
|
|
:return: Dictionary |
|
46
|
|
|
""" |
|
47
|
|
|
_db_config = { |
|
48
|
|
|
'name': db_credentials['db-name'], |
|
49
|
|
|
'host': db_credentials['db-hostname'], |
|
50
|
|
|
'password': db_credentials['db-password'], |
|
51
|
|
|
'port': db_credentials['db-port'], |
|
52
|
|
|
'user': db_credentials['db-username'], |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return _db_config |
|
56
|
|
|
|