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