Conditions | 10 |
Total Lines | 53 |
Code Lines | 34 |
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 |
||
38 | def import_database_dump(): |
||
39 | """ |
||
40 | Importing the selected database dump file |
||
41 | :return: |
||
42 | """ |
||
43 | if not system.config['is_same_client'] and not mode.is_import(): |
||
44 | prepare_target_database_dump() |
||
45 | |||
46 | if system.config['clear_database']: |
||
47 | output.message( |
||
48 | output.Subject.TARGET, |
||
49 | 'Clearing database before import', |
||
50 | True |
||
51 | ) |
||
52 | clear_database(mode.Client.TARGET) |
||
53 | |||
54 | if not system.config['keep_dump'] and not system.config['is_same_client']: |
||
55 | output.message( |
||
56 | output.Subject.TARGET, |
||
57 | 'Importing database dump', |
||
58 | True |
||
59 | ) |
||
60 | |||
61 | if not mode.is_import(): |
||
62 | _dump_path = helper.get_dump_dir(mode.Client.TARGET) + database_utility.database_dump_file_name |
||
63 | else: |
||
64 | _dump_path = system.config['import'] |
||
65 | |||
66 | if not system.config['yes']: |
||
67 | _host_name = helper.get_ssh_host_name(mode.Client.TARGET, True) if mode.is_remote(mode.Client.TARGET) else 'local' |
||
68 | |||
69 | helper.confirm( |
||
70 | output.message( |
||
71 | output.Subject.TARGET, |
||
72 | f'Are you sure, you want to import the dump file into {_host_name} database?', |
||
73 | False |
||
74 | ), |
||
75 | True |
||
76 | ) |
||
77 | |||
78 | database_utility.check_database_dump(mode.Client.TARGET, _dump_path) |
||
79 | |||
80 | import_database_dump_file(mode.Client.TARGET, _dump_path) |
||
81 | |||
82 | if 'after_dump' in system.config['target']: |
||
83 | _after_dump = system.config['target']['after_dump'] |
||
84 | output.message( |
||
85 | output.Subject.TARGET, |
||
86 | f'Importing after_dump file {output.CliFormat.BLACK}{_after_dump}{output.CliFormat.ENDC}', |
||
87 | True |
||
88 | ) |
||
89 | |||
90 | import_database_dump_file(mode.Client.TARGET, _after_dump) |
||
91 | |||
165 |