| Conditions | 10 |
| Total Lines | 109 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 2 |
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 lazyloader_main() 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 |
||
| 189 | def lazyloader_main(device, osversion, radioversion=None, |
||
| 190 | softwareversion=None, localdir=None, autoloader=False, |
||
| 191 | download=True, altsw=None, core=False): |
||
| 192 | """ |
||
| 193 | Wrap the tools necessary to make one autoloader. |
||
| 194 | |||
| 195 | :param device: Device family to create loader for. |
||
| 196 | :type device: int |
||
| 197 | |||
| 198 | :param osversion: OS version, 10.x.y.zzzz. |
||
| 199 | :type osversion: str |
||
| 200 | |||
| 201 | :param radioversion: Radio version, 10.x.y.zzzz. |
||
| 202 | :type radioversion: str |
||
| 203 | |||
| 204 | :param softwareversion: Software version, 10.x.y.zzzz. |
||
| 205 | :type softwareversion: str |
||
| 206 | |||
| 207 | :param localdir: Working path. Default is local dir. |
||
| 208 | :type localdir: str |
||
| 209 | |||
| 210 | :param autoloader: Whether to run loader. Default is false. Windows-only. |
||
| 211 | :type autoloader: bool |
||
| 212 | |||
| 213 | :param download: Whether to download files. Default is true. |
||
| 214 | :type download: bool |
||
| 215 | |||
| 216 | :param altsw: Radio software release, if not the same as OS. |
||
| 217 | :type altsw: str |
||
| 218 | |||
| 219 | :param core: Whether to create a core/radio loader. Default is false. |
||
| 220 | :type core: bool |
||
| 221 | """ |
||
| 222 | radioversion = scriptutils.return_radio_version(osversion, radioversion) |
||
| 223 | softwareversion, swc = scriptutils.return_sw_checked(softwareversion, osversion) |
||
| 224 | if altsw == "checkme": |
||
| 225 | altsw, altchecked = scriptutils.return_radio_sw_checked(altsw, radioversion) |
||
| 226 | scriptutils.standard_preamble("lazyloader", osversion, softwareversion, radioversion, altsw) |
||
| 227 | print("DEVICE: {0}".format(bbconstants.DEVICES[device])) |
||
| 228 | |||
| 229 | # Make dirs |
||
| 230 | bd_o, bd_r, ld_o, ld_r, zd_o, zd_r = barutils.make_dirs(localdir, osversion, radioversion) |
||
| 231 | osurl = radiourl = None |
||
| 232 | |||
| 233 | # Create download URLs |
||
| 234 | if download: |
||
| 235 | baseurl = networkutils.create_base_url(softwareversion) |
||
| 236 | if altsw: |
||
| 237 | alturl = networkutils.create_base_url(altsw) |
||
| 238 | osurl, radiourl = utilities.generate_lazy_urls(baseurl, osversion, radioversion, device) |
||
| 239 | if altsw: |
||
| 240 | radiourl = radiourl.replace(baseurl, alturl) |
||
| 241 | if core: |
||
| 242 | osurl = osurl.replace(".desktop", "") |
||
| 243 | |||
| 244 | # Check availability of software releases |
||
| 245 | scriptutils.check_sw(baseurl, softwareversion, swc) |
||
| 246 | if altsw: |
||
| 247 | scriptutils.check_radio_sw(alturl, altsw, altchecked) |
||
| 248 | |||
| 249 | # Check availability of OS, radio |
||
| 250 | scriptutils.check_os_single(osurl, osversion, device) |
||
| 251 | radiourl, radioversion = scriptutils.check_radio_single(radiourl, radioversion) |
||
| 252 | dllist = [osurl, radiourl] |
||
| 253 | |||
| 254 | # Download files |
||
| 255 | if download: |
||
| 256 | print("DOWNLOADING...") |
||
| 257 | networkutils.download_bootstrap(dllist, outdir=localdir, workers=2) |
||
| 258 | |||
| 259 | # Test bar files |
||
| 260 | scriptutils.test_bar_files(localdir, dllist) |
||
| 261 | |||
| 262 | # Extract bar files |
||
| 263 | print("EXTRACTING...") |
||
| 264 | barutils.extract_bars(localdir) |
||
| 265 | |||
| 266 | # Test signed files |
||
| 267 | scriptutils.test_signed_files(localdir) |
||
| 268 | |||
| 269 | # Move bar files |
||
| 270 | print("MOVING BAR FILES...") |
||
| 271 | barutils.move_bars(localdir, bd_o, bd_r) |
||
| 272 | |||
| 273 | # Generate loader |
||
| 274 | altradio = radioversion if altsw else None |
||
| 275 | loadergen.generate_lazy_loader(osversion, device, localdir, altradio, core) |
||
| 276 | |||
| 277 | # Test loader |
||
| 278 | suffix = loadergen.format_suffix(bool(altradio), altradio, core) |
||
| 279 | loadername = loadergen.generate_filename(device, osversion, suffix) |
||
| 280 | scriptutils.test_single_loader(loadername) |
||
| 281 | |||
| 282 | # Remove signed files |
||
| 283 | print("REMOVING SIGNED FILES...") |
||
| 284 | barutils.remove_signed_files(localdir) |
||
| 285 | |||
| 286 | # Move loaders |
||
| 287 | print("MOVING LOADERS...") |
||
| 288 | barutils.move_loaders(localdir, ld_o, ld_r, zd_o, zd_r) |
||
| 289 | loadername = os.path.join(ld_o, loadername) |
||
| 290 | |||
| 291 | # Delete empty folders |
||
| 292 | print("REMOVING EMPTY FOLDERS...") |
||
| 293 | barutils.remove_empty_folders(localdir) |
||
| 294 | |||
| 295 | if autoloader: |
||
| 296 | subprocess.call(loadername) |
||
| 297 | print("\nFINISHED!!!") |
||
| 298 | |||
| 303 |