| Conditions | 19 |
| Total Lines | 60 |
| Code Lines | 39 |
| 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 file_sync_tool.utility.helper.extend_config() 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 |
||
| 116 | def extend_config(args): |
||
| 117 | """ |
||
| 118 | Extending optional config |
||
| 119 | :param args: |
||
| 120 | :return: |
||
| 121 | """ |
||
| 122 | config = system.config |
||
| 123 | |||
| 124 | if args is None or not args: |
||
| 125 | return config |
||
| 126 | |||
| 127 | if not args.target_host is None: |
||
| 128 | config['target']['host'] = args.target_host |
||
| 129 | |||
| 130 | if not args.target_user is None: |
||
| 131 | config['target']['user'] = args.target_user |
||
| 132 | |||
| 133 | if not args.target_password is None: |
||
| 134 | config['target']['password'] = args.target_password |
||
| 135 | |||
| 136 | if not args.target_key is None: |
||
| 137 | config['target']['ssh_key'] = args.target_key |
||
| 138 | |||
| 139 | if not args.target_port is None: |
||
| 140 | config['target']['port'] = args.target_port |
||
| 141 | |||
| 142 | if not args.origin_host is None: |
||
| 143 | config['origin']['host'] = args.origin_host |
||
| 144 | |||
| 145 | if not args.origin_user is None: |
||
| 146 | config['origin']['user'] = args.origin_user |
||
| 147 | |||
| 148 | if not args.origin_password is None: |
||
| 149 | config['origin']['password'] = args.origin_password |
||
| 150 | |||
| 151 | if not args.origin_key is None: |
||
| 152 | config['origin']['ssh_key'] = args.origin_key |
||
| 153 | |||
| 154 | if not args.origin_port is None: |
||
| 155 | config['origin']['port'] = args.origin_port |
||
| 156 | |||
| 157 | if not args.files_origin is None: |
||
| 158 | if 'config' not in config['files']: |
||
| 159 | config['files']['config'] = [] |
||
| 160 | config['files']['config'].append({}) |
||
| 161 | config['files']['config'][0]['origin'] = args.files_origin |
||
| 162 | |||
| 163 | if not args.files_target is None: |
||
| 164 | if 'config' not in config['files']: |
||
| 165 | config['files']['config'] = [] |
||
| 166 | config['files']['config'].append({}) |
||
| 167 | config['files']['config'][0]['target'] = args.files_target |
||
| 168 | |||
| 169 | if not args.files_exclude is None: |
||
| 170 | config['files']['config'][0]['exclude'] = args.files_exclude.split(',') |
||
| 171 | |||
| 172 | if not args.files_option is None: |
||
| 173 | config['files']['option'] = args.files_option.split(',') |
||
| 174 | |||
| 175 | return config |
||
| 176 |