db-sync-tool-kmi 2.11.6__py3-none-any.whl → 3.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. db_sync_tool/__main__.py +7 -252
  2. db_sync_tool/cli.py +733 -0
  3. db_sync_tool/database/process.py +94 -111
  4. db_sync_tool/database/utility.py +339 -121
  5. db_sync_tool/info.py +1 -1
  6. db_sync_tool/recipes/drupal.py +87 -12
  7. db_sync_tool/recipes/laravel.py +7 -6
  8. db_sync_tool/recipes/parsing.py +102 -0
  9. db_sync_tool/recipes/symfony.py +17 -28
  10. db_sync_tool/recipes/typo3.py +33 -54
  11. db_sync_tool/recipes/wordpress.py +13 -12
  12. db_sync_tool/remote/client.py +206 -71
  13. db_sync_tool/remote/file_transfer.py +303 -0
  14. db_sync_tool/remote/rsync.py +18 -15
  15. db_sync_tool/remote/system.py +2 -3
  16. db_sync_tool/remote/transfer.py +51 -47
  17. db_sync_tool/remote/utility.py +29 -30
  18. db_sync_tool/sync.py +52 -28
  19. db_sync_tool/utility/config.py +367 -0
  20. db_sync_tool/utility/config_resolver.py +573 -0
  21. db_sync_tool/utility/console.py +779 -0
  22. db_sync_tool/utility/exceptions.py +32 -0
  23. db_sync_tool/utility/helper.py +155 -148
  24. db_sync_tool/utility/info.py +53 -20
  25. db_sync_tool/utility/log.py +55 -31
  26. db_sync_tool/utility/logging_config.py +410 -0
  27. db_sync_tool/utility/mode.py +85 -150
  28. db_sync_tool/utility/output.py +122 -51
  29. db_sync_tool/utility/parser.py +33 -53
  30. db_sync_tool/utility/pure.py +93 -0
  31. db_sync_tool/utility/security.py +79 -0
  32. db_sync_tool/utility/system.py +277 -194
  33. db_sync_tool/utility/validation.py +2 -9
  34. db_sync_tool_kmi-3.0.2.dist-info/METADATA +99 -0
  35. db_sync_tool_kmi-3.0.2.dist-info/RECORD +44 -0
  36. {db_sync_tool_kmi-2.11.6.dist-info → db_sync_tool_kmi-3.0.2.dist-info}/WHEEL +1 -1
  37. db_sync_tool_kmi-2.11.6.dist-info/METADATA +0 -276
  38. db_sync_tool_kmi-2.11.6.dist-info/RECORD +0 -34
  39. {db_sync_tool_kmi-2.11.6.dist-info → db_sync_tool_kmi-3.0.2.dist-info}/entry_points.txt +0 -0
  40. {db_sync_tool_kmi-2.11.6.dist-info → db_sync_tool_kmi-3.0.2.dist-info/licenses}/LICENSE +0 -0
  41. {db_sync_tool_kmi-2.11.6.dist-info → db_sync_tool_kmi-3.0.2.dist-info}/top_level.txt +0 -0
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env python3
2
- # -*- coding: future_fstrings -*-
3
2
 
4
3
  """
5
4
  Drupal script
@@ -7,15 +6,48 @@ Drupal script
7
6
 
8
7
  import json
9
8
  from db_sync_tool.utility import mode, system, helper, output
9
+ from db_sync_tool.utility.exceptions import ParsingError
10
+ from db_sync_tool.recipes.parsing import ( # noqa: F401 (re-export)
11
+ parse_drupal_drush_credentials,
12
+ )
10
13
 
11
14
 
12
15
  def check_configuration(client):
16
+ """
17
+ Checking Drupal database configuration.
18
+ First tries to parse settings.php directly, falls back to Drush if needed.
19
+ :param client: String
20
+ :return:
21
+ """
22
+ cfg = system.get_typed_config()
23
+ _path = cfg.get_client(client).path
24
+
25
+ # Try direct settings.php parsing first
26
+ try:
27
+ _db_config = parse_settings_php(client, _path)
28
+ if _db_config and _db_config.get('name') and _db_config.get('host'):
29
+ output.message(
30
+ output.host_to_subject(client),
31
+ 'Parsed database config from settings.php',
32
+ True
33
+ )
34
+ system.set_database_config(client, helper.clean_db_config(_db_config))
35
+ return
36
+ except Exception:
37
+ pass
38
+
39
+ # Fall back to Drush
40
+ check_configuration_drush(client)
41
+
42
+
43
+ def check_configuration_drush(client):
13
44
  """
14
45
  Checking Drupal database configuration with Drush
15
46
  :param client: String
16
47
  :return:
17
48
  """
18
- _path = system.config[client]['path']
49
+ cfg = system.get_typed_config()
50
+ _path = cfg.get_client(client).path
19
51
 
20
52
  # Check Drush version
21
53
  _raw_version = mode.run_command(
@@ -38,24 +70,67 @@ def check_configuration(client):
38
70
  client,
39
71
  True
40
72
  )
73
+ if not stdout:
74
+ raise ParsingError('Failed to read Drupal configuration via drush')
41
75
 
42
76
  _db_config = parse_database_credentials(json.loads(stdout))
43
77
 
44
- system.config[client]['db'] = _db_config
78
+ system.set_database_config(client, helper.clean_db_config(_db_config))
45
79
 
46
80
 
47
- def parse_database_credentials(db_credentials):
81
+ def parse_settings_php(client, path):
48
82
  """
49
- Parsing database credentials to needed format
50
- :param db_credentials: Dictionary
51
- :return: Dictionary
83
+ Parse database credentials directly from settings.php
84
+ :param client: String
85
+ :param path: String
86
+ :return: Dictionary or None
52
87
  """
53
88
  _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'],
89
+ 'name': get_setting_value(client, 'database', path),
90
+ 'host': get_setting_value(client, 'host', path),
91
+ 'password': get_setting_value(client, 'password', path),
92
+ 'port': get_setting_value(client, 'port', path) or 3306,
93
+ 'user': get_setting_value(client, 'username', path),
59
94
  }
60
95
 
61
96
  return _db_config
97
+
98
+
99
+ def get_setting_value(client, key, path):
100
+ """
101
+ Extract a single value from Drupal settings.php
102
+ Handles both 'key' => 'value' and 'key' => "value" formats
103
+ :param client: String
104
+ :param key: String
105
+ :param path: String
106
+ :return: String
107
+ """
108
+ # Try single quotes first, then double quotes
109
+ cmd_result = mode.run_command(
110
+ helper.get_command(client, 'sed') +
111
+ f' -n "s/.*\'{key}\' *=> *[\'\\"]\\([^\'\\"]*\\)[\'\\"].*/\\1/p" {path} | head -1',
112
+ client,
113
+ True
114
+ )
115
+ result = cmd_result.strip() if cmd_result else ''
116
+
117
+ # For numeric values like port (without quotes)
118
+ if not result:
119
+ cmd_result = mode.run_command(
120
+ helper.get_command(client, 'sed') +
121
+ f' -n "s/.*\'{key}\' *=> *\\([0-9]*\\).*/\\1/p" {path} | head -1',
122
+ client,
123
+ True
124
+ )
125
+ result = cmd_result.strip() if cmd_result else ''
126
+
127
+ return result
128
+
129
+
130
+ def parse_database_credentials(db_credentials):
131
+ """
132
+ Parsing database credentials to needed format
133
+ :param db_credentials: Dictionary
134
+ :return: Dictionary
135
+ """
136
+ return parse_drupal_drush_credentials(db_credentials)
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env python3
2
- # -*- coding: future_fstrings -*-
3
2
 
4
3
  """
5
4
  Laravel script
@@ -13,15 +12,16 @@ def check_configuration(client):
13
12
  :param client: String
14
13
  :return:
15
14
  """
16
- _path = system.config[client]['path']
15
+ cfg = system.get_typed_config()
16
+ _path = cfg.get_client(client).path
17
17
 
18
- system.config[client]['db'] = {
18
+ system.set_database_config(client, helper.clean_db_config({
19
19
  'name': get_database_parameter(client, 'DB_DATABASE', _path),
20
20
  'host': get_database_parameter(client, 'DB_HOST', _path),
21
21
  'password': get_database_parameter(client, 'DB_PASSWORD', _path),
22
22
  'port': get_database_parameter(client, 'DB_PORT', _path),
23
23
  'user': get_database_parameter(client, 'DB_USERNAME', _path),
24
- }
24
+ }))
25
25
 
26
26
 
27
27
  def get_database_parameter(client, name, file):
@@ -33,8 +33,9 @@ def get_database_parameter(client, name, file):
33
33
  :param file: String
34
34
  :return:
35
35
  """
36
- return mode.run_command(
36
+ result = mode.run_command(
37
37
  helper.get_command(client, 'grep') + f' {name} {file} | cut -d \'=\' -f2',
38
38
  client,
39
39
  True
40
- ).replace('\n', '')
40
+ )
41
+ return result.replace('\n', '') if result else ''
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ Pure parsing functions for framework configuration files.
5
+
6
+ This module contains parsing functions with minimal dependencies,
7
+ allowing proper unit testing and code coverage measurement.
8
+ Only depends on utility/exceptions.py which has no other project dependencies.
9
+
10
+ Functions here are imported and used by the framework recipe modules.
11
+ """
12
+
13
+ from urllib.parse import urlparse, unquote
14
+ from db_sync_tool.utility.exceptions import ParsingError
15
+
16
+
17
+ def parse_symfony_database_url(db_credentials: str) -> dict:
18
+ """
19
+ Parse Symfony DATABASE_URL format into database config dict.
20
+
21
+ Format: DATABASE_URL=mysql://user:password@host:port/dbname?options
22
+
23
+ :param db_credentials: DATABASE_URL string
24
+ :return: Dictionary with db_type, user, password, host, port, name
25
+ :raises ParsingError: If format doesn't match expected pattern
26
+ """
27
+ db_credentials = str(db_credentials).replace('\\n\'', '')
28
+
29
+ # Remove DATABASE_URL= prefix if present
30
+ if db_credentials.startswith('DATABASE_URL='):
31
+ url = db_credentials[len('DATABASE_URL='):]
32
+ else:
33
+ url = db_credentials
34
+
35
+ parsed = urlparse(url)
36
+
37
+ # Validate required components (password is required for database connections)
38
+ if not all([parsed.scheme, parsed.username, parsed.hostname, parsed.port, parsed.path]):
39
+ raise ParsingError('Mismatch of expected database credentials')
40
+
41
+ # Password is required
42
+ if parsed.password is None:
43
+ raise ParsingError('Mismatch of expected database credentials')
44
+
45
+ # Extract database name from path (remove leading /)
46
+ dbname = parsed.path.lstrip('/')
47
+ if not dbname:
48
+ raise ParsingError('Mismatch of expected database credentials')
49
+
50
+ # These are validated as non-None above, but mypy can't infer that
51
+ assert parsed.username is not None
52
+ assert parsed.password is not None
53
+ assert parsed.hostname is not None
54
+
55
+ return {
56
+ 'db_type': parsed.scheme,
57
+ 'user': unquote(parsed.username),
58
+ 'password': unquote(parsed.password),
59
+ 'host': parsed.hostname,
60
+ 'port': str(parsed.port),
61
+ 'name': dbname,
62
+ }
63
+
64
+
65
+ def parse_drupal_drush_credentials(db_credentials: dict) -> dict:
66
+ """
67
+ Parse Drupal Drush core-status output into database config dict.
68
+
69
+ :param db_credentials: Dictionary from Drush JSON output
70
+ :return: Dictionary with name, host, password, port, user
71
+ """
72
+ return {
73
+ 'name': db_credentials['db-name'],
74
+ 'host': db_credentials['db-hostname'],
75
+ 'password': db_credentials['db-password'],
76
+ 'port': db_credentials['db-port'],
77
+ 'user': db_credentials['db-username'],
78
+ }
79
+
80
+
81
+ def parse_typo3_database_credentials(db_credentials: dict) -> dict:
82
+ """
83
+ Parse TYPO3 LocalConfiguration.php DB array into database config dict.
84
+
85
+ Handles both TYPO3 v8+ (Connections/Default) and TYPO3 v7- formats.
86
+
87
+ :param db_credentials: Dictionary from LocalConfiguration DB section
88
+ :return: Dictionary with name, host, password, port, user
89
+ """
90
+ # Distinguish between database config scheme of TYPO3 v8+ and TYPO3 v7-
91
+ if 'Connections' in db_credentials:
92
+ _db_config = dict(db_credentials['Connections']['Default'])
93
+ _db_config['name'] = _db_config['dbname']
94
+ else:
95
+ _db_config = dict(db_credentials)
96
+ _db_config['user'] = _db_config['username']
97
+ _db_config['name'] = _db_config['database']
98
+
99
+ if 'port' not in _db_config:
100
+ _db_config['port'] = 3306
101
+
102
+ return _db_config
@@ -1,14 +1,14 @@
1
1
  #!/usr/bin/env python3
2
- # -*- coding: future_fstrings -*-
3
2
 
4
3
  """
5
4
  Symfony script
6
5
  """
7
6
 
8
- import re
9
- import sys
10
-
11
- from db_sync_tool.utility import mode, system, helper, output
7
+ from db_sync_tool.utility import mode, system, helper
8
+ from db_sync_tool.utility.exceptions import ParsingError
9
+ from db_sync_tool.recipes.parsing import ( # noqa: F401 (re-export)
10
+ parse_symfony_database_url,
11
+ )
12
12
 
13
13
 
14
14
  def check_configuration(client):
@@ -17,7 +17,8 @@ def check_configuration(client):
17
17
  :param client: String
18
18
  :return:
19
19
  """
20
- _path = system.config[client]['path']
20
+ cfg = system.get_typed_config()
21
+ _path = cfg.get_client(client).path
21
22
 
22
23
  # Check for symfony 2.8
23
24
  if 'parameters.yml' in _path:
@@ -31,14 +32,14 @@ def check_configuration(client):
31
32
  # Using for symfony >=3.4
32
33
  else:
33
34
  stdout = mode.run_command(
34
- helper.get_command(client, 'grep') + ' -v "^#" ' + system.config[client][
35
- 'path'] + ' | ' + helper.get_command(client, 'grep') + ' DATABASE_URL',
35
+ helper.get_command(client, 'grep') + ' -v "^#" ' + _path +
36
+ ' | ' + helper.get_command(client, 'grep') + ' DATABASE_URL',
36
37
  client,
37
38
  True
38
39
  )
39
40
  _db_config = parse_database_credentials(stdout)
40
41
 
41
- system.config[client]['db'] = _db_config
42
+ system.set_database_config(client, helper.clean_db_config(_db_config))
42
43
 
43
44
 
44
45
  def parse_database_credentials(db_credentials):
@@ -47,23 +48,10 @@ def parse_database_credentials(db_credentials):
47
48
  :param db_credentials: Dictionary
48
49
  :return: Dictionary
49
50
  """
50
- db_credentials = str(db_credentials).replace('\\n\'','')
51
- # DATABASE_URL=mysql://db-user:1234@db-host:3306/db-name
52
- pattern = r'^DATABASE_URL=(?P<db_type>\w+):\/\/(?P<user>[^:]+):(?P<password>[^@]+)@(?P<host>[^:]+):(?P<port>\d+)\/(?P<name>[^?]+)(?:\?.*)?$'
53
-
54
- match = re.match(pattern, db_credentials)
55
-
56
- if match:
57
- db_config = match.groupdict()
58
- return db_config
59
- else:
60
- sys.exit(
61
- output.message(
62
- output.Subject.ERROR,
63
- 'Mismatch of expected database credentials',
64
- False
65
- )
66
- )
51
+ try:
52
+ return parse_symfony_database_url(db_credentials)
53
+ except (ValueError, ParsingError):
54
+ raise ParsingError('Mismatch of expected database credentials') from None
67
55
 
68
56
 
69
57
  def get_database_parameter(client, name, file):
@@ -75,8 +63,9 @@ def get_database_parameter(client, name, file):
75
63
  :param file: String
76
64
  :return:
77
65
  """
78
- return mode.run_command(
66
+ result = mode.run_command(
79
67
  helper.get_command(client, 'sed') + f' -n -e \'/{name}/ s/.*\\: *//p\' {file}',
80
68
  client,
81
69
  True
82
- ).replace('\n', '')
70
+ )
71
+ return result.replace('\n', '') if result else ''
@@ -1,13 +1,16 @@
1
1
  #!/usr/bin/env python3
2
- # -*- coding: future_fstrings -*-
3
2
 
4
3
  """
5
4
  TYPO3 script
6
5
  """
7
6
 
8
- import json, sys
7
+ import json
9
8
 
10
- from db_sync_tool.utility import mode, system, helper, output
9
+ from db_sync_tool.utility import mode, system, helper
10
+ from db_sync_tool.utility.exceptions import ParsingError
11
+ from db_sync_tool.recipes.parsing import ( # noqa: F401 (re-export)
12
+ parse_typo3_database_credentials,
13
+ )
11
14
 
12
15
 
13
16
  def check_configuration(client):
@@ -16,50 +19,50 @@ def check_configuration(client):
16
19
  :param client: String
17
20
  :return:
18
21
  """
19
- _path = system.config[client]['path']
22
+ cfg = system.get_typed_config()
23
+ client_cfg = cfg.get_client(client)
24
+ _path = client_cfg.path
20
25
 
21
26
  if 'LocalConfiguration' in _path:
22
27
  stdout = mode.run_command(
23
28
  helper.get_command(client, 'php') + ' -r "echo json_encode(include \'' +
24
- system.config[client][
25
- 'path'] + '\');"',
29
+ _path + '\');"',
26
30
  client,
27
31
  True
28
32
  )
33
+ if not stdout:
34
+ raise ParsingError('Failed to read TYPO3 configuration')
29
35
 
30
36
  _db_config = parse_database_credentials(json.loads(stdout)['DB'])
31
37
  elif '.env' in _path:
32
38
  # Try to parse settings from .env file
39
+ # db_cfg fields can override default env var names if user provides them
40
+ db_cfg = client_cfg.db
33
41
  _db_config = {
34
- 'name': get_database_setting_from_env(client, 'TYPO3_CONF_VARS__DB__Connections__Default__dbname', system.config[client]['path']),
35
- 'host': get_database_setting_from_env(client, 'TYPO3_CONF_VARS__DB__Connections__Default__host', system.config[client]['path']),
36
- 'password': get_database_setting_from_env(client, 'TYPO3_CONF_VARS__DB__Connections__Default__password', system.config[client]['path']),
37
- 'port': get_database_setting_from_env(client, 'TYPO3_CONF_VARS__DB__Connections__Default__port', system.config[client]['path'])
38
- if get_database_setting_from_env(client, 'TYPO3_CONF_VARS__DB__Connections__Default__port',
39
- system.config[client]['path']) != '' else 3306,
40
- 'user': get_database_setting_from_env(client, 'TYPO3_CONF_VARS__DB__Connections__Default__user', system.config[client]['path']),
42
+ 'name': get_database_setting_from_env(client, db_cfg.name or 'TYPO3_CONF_VARS__DB__Connections__Default__dbname', _path),
43
+ 'host': get_database_setting_from_env(client, db_cfg.host or 'TYPO3_CONF_VARS__DB__Connections__Default__host', _path),
44
+ 'password': get_database_setting_from_env(client, db_cfg.password or 'TYPO3_CONF_VARS__DB__Connections__Default__password', _path),
45
+ 'port': get_database_setting_from_env(client, str(db_cfg.port) if db_cfg.port else 'TYPO3_CONF_VARS__DB__Connections__Default__port', _path) or 3306,
46
+ 'user': get_database_setting_from_env(client, db_cfg.user or 'TYPO3_CONF_VARS__DB__Connections__Default__user', _path),
41
47
  }
42
48
  elif 'AdditionalConfiguration.php' in _path:
43
49
  # Try to parse settings from AdditionalConfiguration.php file
44
50
  _db_config = {
45
- 'name': get_database_setting_from_additional_configuration(client, 'dbname', system.config[client]['path']),
46
- 'host': get_database_setting_from_additional_configuration(client, 'host', system.config[client]['path']),
47
- 'password': get_database_setting_from_additional_configuration(client, 'password', system.config[client]['path']),
48
- 'port': get_database_setting_from_additional_configuration(client, 'port', system.config[client]['path'])
49
- if get_database_setting_from_additional_configuration(client, 'port',
50
- system.config[client]['path']) != '' else 3306,
51
- 'user': get_database_setting_from_additional_configuration(client, 'user', system.config[client]['path']),
51
+ 'name': get_database_setting_from_additional_configuration(client, 'dbname', _path),
52
+ 'host': get_database_setting_from_additional_configuration(client, 'host', _path),
53
+ 'password': get_database_setting_from_additional_configuration(client, 'password', _path),
54
+ 'port': get_database_setting_from_additional_configuration(client, 'port', _path)
55
+ if get_database_setting_from_additional_configuration(client, 'port', _path) != '' else 3306,
56
+ 'user': get_database_setting_from_additional_configuration(client, 'user', _path),
52
57
  }
53
58
  else:
54
- sys.exit(
55
- output.message(
56
- output.Subject.ERROR,
57
- f'Can\'t extract database information from given path {system.config[client]["path"]}. Can only extract settings from the following files: LocalConfiguration.php, AdditionalConfiguration.php, .env',
58
- False
59
- )
59
+ raise ParsingError(
60
+ f'Can\'t extract database information from given path {_path}. '
61
+ f'Can only extract settings from the following files: LocalConfiguration.php, '
62
+ f'AdditionalConfiguration.php, .env'
60
63
  )
61
64
 
62
- system.config[client]['db'] = _db_config
65
+ system.set_database_config(client, helper.clean_db_config(_db_config))
63
66
 
64
67
 
65
68
  def parse_database_credentials(db_credentials):
@@ -68,21 +71,7 @@ def parse_database_credentials(db_credentials):
68
71
  :param db_credentials: Dictionary
69
72
  :return: Dictionary
70
73
  """
71
- #
72
- # Distinguish between database config scheme of TYPO3 v8+ and TYPO3 v7-
73
- #
74
- if 'Connections' in db_credentials:
75
- _db_config = db_credentials['Connections']['Default']
76
- _db_config['name'] = _db_config['dbname']
77
- else:
78
- _db_config = db_credentials
79
- _db_config['user'] = _db_config['username']
80
- _db_config['name'] = _db_config['database']
81
-
82
- if 'port' not in _db_config:
83
- _db_config['port'] = 3306
84
-
85
- return _db_config
74
+ return parse_typo3_database_credentials(db_credentials)
86
75
 
87
76
 
88
77
  def get_database_setting_from_additional_configuration(client, name, file):
@@ -94,12 +83,7 @@ def get_database_setting_from_additional_configuration(client, name, file):
94
83
  :param file: String
95
84
  :return:
96
85
  """
97
- return mode.run_command(
98
- helper.get_command(client, 'sed') +
99
- f' -nE "s/\'{name}\'.*=>.*\'(.*)\'.*$/\\1/p" {file}',
100
- client,
101
- True
102
- ).replace('\n', '').strip()
86
+ return helper.run_sed_command(client, f'"s/\'{name}\'.*=>.*\'(.*)\'.*$/\\1/p" {file}')
103
87
 
104
88
  def get_database_setting_from_env(client, name, file):
105
89
  """
@@ -110,9 +94,4 @@ def get_database_setting_from_env(client, name, file):
110
94
  :param file: String
111
95
  :return:
112
96
  """
113
- return mode.run_command(
114
- helper.get_command(client, 'sed') +
115
- f' -nE "s/{name}=(.*).*$/\\1/p" {file}',
116
- client,
117
- True
118
- ).replace('\n', '').strip()
97
+ return helper.run_sed_command(client, f'"s/{name}=(.*).*$/\\1/p" {file}')
@@ -1,5 +1,4 @@
1
1
  #!/usr/bin/env python3
2
- # -*- coding: future_fstrings -*-
3
2
 
4
3
  """
5
4
  Wordpress script
@@ -10,22 +9,23 @@ from db_sync_tool.utility import mode, system, helper
10
9
 
11
10
  def check_configuration(client):
12
11
  """
13
- Checking Drupal database configuration
12
+ Checking WordPress database configuration
14
13
  :param client: String
15
14
  :return:
16
15
  """
17
- _path = system.config[client]['path']
16
+ cfg = system.get_typed_config()
17
+ _path = cfg.get_client(client).path
18
18
 
19
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,
25
- 'user': get_database_setting(client, 'DB_USER', system.config[client]['path']),
20
+ 'name': get_database_setting(client, 'DB_NAME', _path),
21
+ 'host': get_database_setting(client, 'DB_HOST', _path),
22
+ 'password': get_database_setting(client, 'DB_PASSWORD', _path),
23
+ 'port': get_database_setting(client, 'DB_PORT', _path)
24
+ if get_database_setting(client, 'DB_PORT', _path) != '' else 3306,
25
+ 'user': get_database_setting(client, 'DB_USER', _path),
26
26
  }
27
27
 
28
- system.config[client]['db'] = _db_config
28
+ system.set_database_config(client, helper.clean_db_config(_db_config))
29
29
 
30
30
 
31
31
  def get_database_setting(client, name, file):
@@ -37,9 +37,10 @@ def get_database_setting(client, name, file):
37
37
  :param file: String
38
38
  :return:
39
39
  """
40
- return mode.run_command(
40
+ result = mode.run_command(
41
41
  helper.get_command(client, 'sed') +
42
42
  f' -n "s/define( *\'{name}\', *\'\([^\']*\)\'.*/\\1/p" {file}',
43
43
  client,
44
44
  True
45
- ).replace('\n', '')
45
+ )
46
+ return result.replace('\n', '') if result else ''