| Conditions | 13 |
| Total Lines | 96 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 carrierchecker_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 |
||
| 198 | def carrierchecker_main(mcc, mnc, device, |
||
| 199 | download=False, upgrade=True, |
||
| 200 | directory=None, |
||
| 201 | export=False, |
||
| 202 | blitz=False, |
||
| 203 | bundles=False, |
||
| 204 | forced=None, |
||
| 205 | selective=False): |
||
| 206 | """ |
||
| 207 | Wrap around :mod:`bbarchivist.networkutils` carrier checking. |
||
| 208 | |||
| 209 | :param mcc: Country code. |
||
| 210 | :type mcc: int |
||
| 211 | |||
| 212 | :param mnc: Network code. |
||
| 213 | :type mnc: int |
||
| 214 | |||
| 215 | :param device: Device ID (SXX100-#) |
||
| 216 | :type device: str |
||
| 217 | |||
| 218 | :param download: Whether or not to download. Default is false. |
||
| 219 | :type download: bool |
||
| 220 | |||
| 221 | :param upgrade: Whether or not to use upgrade files. Default is false. |
||
| 222 | :type upgrade: bool |
||
| 223 | |||
| 224 | :param directory: Where to store files. Default is local directory. |
||
| 225 | :type directory: str |
||
| 226 | |||
| 227 | :param export: Whether or not to write URLs to a file. Default is false. |
||
| 228 | :type export: bool |
||
| 229 | |||
| 230 | :param blitz: Whether or not to create a blitz package. Default is false. |
||
| 231 | :type blitz: bool |
||
| 232 | |||
| 233 | :param bundles: Whether or not to check software bundles. Default is false. |
||
| 234 | :type bundles: bool |
||
| 235 | |||
| 236 | :param forced: Force a software release. None to go for latest. |
||
| 237 | :type forced: str |
||
| 238 | |||
| 239 | :param selective: Whether or not to exclude Nuance/other dross. Default is false. |
||
| 240 | :type selective: bool |
||
| 241 | """ |
||
| 242 | if mcc is None: |
||
| 243 | print("INVALID MCC!") |
||
| 244 | raise SystemExit |
||
| 245 | elif mnc is None: |
||
| 246 | print("INVALID MNC!") |
||
| 247 | raise SystemExit |
||
| 248 | elif device is None: |
||
| 249 | print("INVALID DEVICE!") |
||
| 250 | raise SystemExit |
||
| 251 | device = device.upper() |
||
| 252 | if directory is None: |
||
| 253 | directory = os.getcwd() |
||
| 254 | data = jsonutils.load_json("devices") |
||
| 255 | model, family, hwid = jsonutils.certchecker_prep(data, device) |
||
| 256 | scriptutils.slim_preamble("CARRIERCHECKER") |
||
| 257 | country, carrier = networkutils.carrier_checker(mcc, mnc) |
||
| 258 | print("COUNTRY: {0}".format(country.upper())) |
||
| 259 | print("CARRIER: {0}".format(carrier.upper())) |
||
| 260 | print("DEVICE: {0}".format(model.upper())) |
||
| 261 | print("VARIANT: {0}".format(device.upper())) |
||
| 262 | print("HARDWARE ID: {0}".format(hwid.upper())) |
||
| 263 | print("\nCHECKING CARRIER...") |
||
| 264 | if bundles: |
||
| 265 | releases = networkutils.available_bundle_lookup(mcc, mnc, hwid) |
||
| 266 | print("\nAVAILABLE BUNDLES:") |
||
| 267 | utilities.lprint(releases) |
||
| 268 | else: |
||
| 269 | npc = networkutils.return_npc(mcc, mnc) |
||
| 270 | swv, osv, radv, files = networkutils.carrier_query(npc, hwid, upgrade, blitz, forced) |
||
| 271 | print("SOFTWARE RELEASE: {0}".format(swv)) |
||
| 272 | print("OS VERSION: {0}".format(osv)) |
||
| 273 | print("RADIO VERSION: {0}".format(radv)) |
||
| 274 | if selective: |
||
| 275 | craplist = jsonutils.load_json("apps_to_remove") |
||
| 276 | files = scriptutils.purge_dross(files, craplist) |
||
| 277 | if export: |
||
| 278 | print("\nEXPORTING...") |
||
| 279 | npc = networkutils.return_npc(mcc, mnc) |
||
| 280 | scriptutils.export_cchecker(files, npc, hwid, osv, radv, swv, upgrade, forced) |
||
| 281 | if download: |
||
| 282 | suffix = "-BLITZ" if blitz else "-{0}".format(family) |
||
| 283 | bardir = os.path.join(directory, "{0}{1}".format(swv, suffix)) |
||
| 284 | if not os.path.exists(bardir): |
||
| 285 | os.makedirs(bardir) |
||
| 286 | if blitz: |
||
| 287 | files = scriptutils.generate_blitz_links(files, osv, radv, swv) |
||
| 288 | print("\nDOWNLOADING...") |
||
| 289 | networkutils.download_bootstrap(files, outdir=bardir) |
||
| 290 | scriptutils.test_bar_files(bardir, files) |
||
| 291 | if blitz: |
||
| 292 | scriptutils.package_blitz(bardir, swv) |
||
| 293 | print("\nFINISHED!!!") |
||
| 294 | |||
| 298 |