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