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