| Conditions | 12 |
| Total Lines | 68 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like db_sync_tool.database.process.import_database_dump() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | #!/usr/bin/env python3 |
||
| 60 | def import_database_dump(): |
||
| 61 | """ |
||
| 62 | Importing the selected database dump file |
||
| 63 | :return: |
||
| 64 | """ |
||
| 65 | if not system.config['is_same_client'] and not mode.is_import(): |
||
| 66 | prepare_target_database_dump() |
||
| 67 | |||
| 68 | if system.config['clear_database']: |
||
| 69 | output.message( |
||
| 70 | output.Subject.TARGET, |
||
| 71 | 'Clearing database before import', |
||
| 72 | True |
||
| 73 | ) |
||
| 74 | clear_database(mode.Client.TARGET) |
||
| 75 | |||
| 76 | database_utility.truncate_tables() |
||
| 77 | |||
| 78 | if not system.config['keep_dump'] and not mode.is_dump(): |
||
| 79 | |||
| 80 | database_utility.get_database_version(mode.Client.TARGET) |
||
| 81 | |||
| 82 | output.message( |
||
| 83 | output.Subject.TARGET, |
||
| 84 | 'Importing database dump', |
||
| 85 | True |
||
| 86 | ) |
||
| 87 | |||
| 88 | if not mode.is_import(): |
||
| 89 | _dump_path = helper.get_dump_dir( |
||
| 90 | mode.Client.TARGET) + database_utility.database_dump_file_name |
||
| 91 | else: |
||
| 92 | _dump_path = system.config['import'] |
||
| 93 | |||
| 94 | if not system.config['yes']: |
||
| 95 | _host_name = helper.get_ssh_host_name(mode.Client.TARGET, True) if mode.is_remote( |
||
| 96 | mode.Client.TARGET) else 'local' |
||
| 97 | |||
| 98 | helper.confirm( |
||
| 99 | output.message( |
||
| 100 | output.Subject.TARGET, |
||
| 101 | f'Are you sure, you want to import the dump file into {_host_name} database?', |
||
| 102 | False |
||
| 103 | ), |
||
| 104 | True |
||
| 105 | ) |
||
| 106 | |||
| 107 | database_utility.check_database_dump(mode.Client.TARGET, _dump_path) |
||
| 108 | |||
| 109 | import_database_dump_file(mode.Client.TARGET, _dump_path) |
||
| 110 | |||
| 111 | if 'after_dump' in system.config['target']: |
||
| 112 | _after_dump = system.config['target']['after_dump'] |
||
| 113 | output.message( |
||
| 114 | output.Subject.TARGET, |
||
| 115 | f'Importing after_dump file {output.CliFormat.BLACK}{_after_dump}{output.CliFormat.ENDC}', |
||
| 116 | True |
||
| 117 | ) |
||
| 118 | import_database_dump_file(mode.Client.TARGET, _after_dump) |
||
| 119 | |||
| 120 | if 'post_sql' in system.config['target']: |
||
| 121 | output.message( |
||
| 122 | output.Subject.TARGET, |
||
| 123 | f'Running addition post sql commands', |
||
| 124 | True |
||
| 125 | ) |
||
| 126 | for _sql_command in system.config['target']['post_sql']: |
||
| 127 | database_utility.run_database_command(mode.Client.TARGET, _sql_command, True) |
||
| 128 | |||
| 209 |
This check looks for lines that are too long. You can specify the maximum line length.