| Conditions | 1 |
| Total Lines | 81 |
| Code Lines | 75 |
| 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 |
||
| 29 | def get_arguments(args): |
||
| 30 | """ |
||
| 31 | Parses and returns script arguments |
||
| 32 | :param args: |
||
| 33 | :return: |
||
| 34 | """ |
||
| 35 | parser = argparse.ArgumentParser(prog='file_sync_tool', description='A tool for automatic file synchronization from and to host systems.') |
||
| 36 | parser.add_argument('-f', '--config-file', |
||
| 37 | help='Path to configuration file', |
||
| 38 | required=False, |
||
| 39 | type=str) |
||
| 40 | parser.add_argument('-v', '--verbose', |
||
| 41 | help='Enable extended console output', |
||
| 42 | required=False, |
||
| 43 | action='store_true') |
||
| 44 | parser.add_argument('-m', '--mute', |
||
| 45 | help='Mute console output', |
||
| 46 | required=False, |
||
| 47 | action='store_true') |
||
| 48 | parser.add_argument('-o', '--host-file', |
||
| 49 | help='Using an additional hosts file for merging hosts information with the configuration file', |
||
| 50 | required=False, |
||
| 51 | type=str) |
||
| 52 | parser.add_argument('-th', '--target-host', |
||
| 53 | help='SSH host to target system', |
||
| 54 | required=False, |
||
| 55 | type=str) |
||
| 56 | parser.add_argument('-tu', '--target-user', |
||
| 57 | help='SSH user for target system', |
||
| 58 | required=False, |
||
| 59 | type=str) |
||
| 60 | parser.add_argument('-tpw', '--target-password', |
||
| 61 | help='SSH password for target system', |
||
| 62 | required=False, |
||
| 63 | type=str) |
||
| 64 | parser.add_argument('-tk', '--target-key', |
||
| 65 | help='File path to SSH key for target system', |
||
| 66 | required=False, |
||
| 67 | type=str) |
||
| 68 | parser.add_argument('-tpo', '--target-port', |
||
| 69 | help='SSH port for target system', |
||
| 70 | required=False, |
||
| 71 | type=int) |
||
| 72 | parser.add_argument('-oh', '--origin-host', |
||
| 73 | help='SSH host to origin system', |
||
| 74 | required=False, |
||
| 75 | type=str) |
||
| 76 | parser.add_argument('-ou', '--origin-user', |
||
| 77 | help='SSH user for origin system', |
||
| 78 | required=False, |
||
| 79 | type=str) |
||
| 80 | parser.add_argument('-opw', '--origin-password', |
||
| 81 | help='SSH password for origin system', |
||
| 82 | required=False, |
||
| 83 | type=str) |
||
| 84 | parser.add_argument('-ok', '--origin-key', |
||
| 85 | help='File path to SSH key for origin system', |
||
| 86 | required=False, |
||
| 87 | type=str) |
||
| 88 | parser.add_argument('-opo', '--origin-port', |
||
| 89 | help='SSH port for origin system', |
||
| 90 | required=False, |
||
| 91 | type=int) |
||
| 92 | parser.add_argument('-fo', '--files-origin', |
||
| 93 | help='File path for origin source of file sync', |
||
| 94 | required=False, |
||
| 95 | type=str) |
||
| 96 | parser.add_argument('-ft', '--files-target', |
||
| 97 | help='File path for target destination of file sync', |
||
| 98 | required=False, |
||
| 99 | type=str) |
||
| 100 | parser.add_argument('-fe', '--files-exclude', |
||
| 101 | help='Excludes for file sync', |
||
| 102 | required=False, |
||
| 103 | type=str) |
||
| 104 | parser.add_argument('-fop', '--files-option', |
||
| 105 | help='Additional rsync options', |
||
| 106 | required=False, |
||
| 107 | type=str) |
||
| 108 | |||
| 109 | return parser.parse_args(helper.dict_to_args(args)) |
||
| 110 | |||
| 175 |