Conditions | 7 |
Total Lines | 56 |
Code Lines | 36 |
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:
1 | #!/usr/bin/env python3 |
||
13 | def create_origin_database_dump(): |
||
14 | """ |
||
15 | Creating the origin database dump file |
||
16 | :return: |
||
17 | """ |
||
18 | if not mode.is_import(): |
||
19 | parser.get_database_configuration(mode.Client.ORIGIN) |
||
20 | database_utility.generate_database_dump_filename() |
||
21 | helper.check_and_create_dump_dir(mode.Client.ORIGIN, |
||
22 | helper.get_dump_dir(mode.Client.ORIGIN)) |
||
23 | |||
24 | _dump_file_path = helper.get_dump_dir( |
||
25 | mode.Client.ORIGIN) + database_utility.database_dump_file_name |
||
26 | |||
27 | _database_version = database_utility.get_database_version(mode.Client.ORIGIN) |
||
28 | output.message( |
||
29 | output.Subject.ORIGIN, |
||
30 | f'Creating database dump {output.CliFormat.BLACK}{_dump_file_path}{output.CliFormat.ENDC}', |
||
|
|||
31 | True |
||
32 | ) |
||
33 | |||
34 | _mysqldump_options = '--no-tablespaces ' |
||
35 | # Remove --no-tablespaces option for mysql < 5.6 |
||
36 | # @ToDo: Better option handling |
||
37 | if not _database_version is None: |
||
38 | if _database_version[0] == database_utility.DatabaseSystem.MYSQL and \ |
||
39 | semantic_version.Version(_database_version[1]) < semantic_version.Version('5.6.0'): |
||
40 | _mysqldump_options = '' |
||
41 | |||
42 | # Adding additional where clause to sync only selected rows |
||
43 | if system.config['where'] != '': |
||
44 | _where = system.config['where'] |
||
45 | _mysqldump_options = _mysqldump_options + f'--where=\'{_where}\' ' |
||
46 | |||
47 | # Adding additional mysqldump options |
||
48 | # see https://dev.mysql.com/doc/refman/8.0/en/mysqldump.html#mysqldump-option-summary |
||
49 | if system.config['additional_mysqldump_options'] != '': |
||
50 | _additional = system.config['additional_mysqldump_options'] |
||
51 | _mysqldump_options = _mysqldump_options + f'{_additional} ' |
||
52 | |||
53 | # Run mysql dump command, e.g. |
||
54 | # mysqldump --no-tablespaces -u'db' -p'db' -h'db1' -P'3306' 'db' > /tmp/_db_08-10-2021_07-00.sql |
||
55 | mode.run_command( |
||
56 | helper.get_command(mode.Client.ORIGIN, 'mysqldump') + ' ' + _mysqldump_options + |
||
57 | database_utility.generate_mysql_credentials(mode.Client.ORIGIN) + ' \'' + |
||
58 | system.config[mode.Client.ORIGIN]['db']['name'] + '\' ' + |
||
59 | database_utility.generate_ignore_database_tables() + |
||
60 | database_utility.get_database_tables() + |
||
61 | ' > ' + _dump_file_path, |
||
62 | mode.Client.ORIGIN, |
||
63 | skip_dry_run=True |
||
64 | ) |
||
65 | |||
66 | database_utility.check_database_dump(mode.Client.ORIGIN, _dump_file_path) |
||
67 | database_utility.count_tables(mode.Client.ORIGIN, _dump_file_path) |
||
68 | prepare_origin_database_dump() |
||
69 | |||
223 |
This check looks for lines that are too long. You can specify the maximum line length.