| Conditions | 3 |
| Total Lines | 55 |
| Code Lines | 49 |
| 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 |
||
| 18 | def grab_args(): |
||
| 19 | """ |
||
| 20 | Parse arguments from argparse/questionnaire. |
||
| 21 | |||
| 22 | Invoke a function with those arguments. |
||
| 23 | """ |
||
| 24 | if getattr(sys, "frozen", False) and len(sys.argv) == 1: |
||
| 25 | questionnaire() |
||
| 26 | else: |
||
| 27 | parser = scriptutils.default_parser("bb-tclscan", "Check for updates for TCL devices") |
||
| 28 | parser.add_argument("prd", help="Only scan one PRD", default=None, nargs="?") |
||
| 29 | parser.add_argument( |
||
| 30 | "-l", |
||
| 31 | "--list", |
||
| 32 | dest="printlist", |
||
| 33 | help="List PRDs in database", |
||
| 34 | action="store_true", |
||
| 35 | default=False) |
||
| 36 | parser.add_argument( |
||
| 37 | "-d", |
||
| 38 | "--download", |
||
| 39 | dest="download", |
||
| 40 | help="Download update, assumes single PRD", |
||
| 41 | action="store_true", |
||
| 42 | default=False) |
||
| 43 | parser.add_argument( |
||
| 44 | "-o", |
||
| 45 | "--ota-version", |
||
| 46 | dest="otaver", |
||
| 47 | help="Query OTA updates from a given version instead of full OS", |
||
| 48 | default=None) |
||
| 49 | parser.add_argument( |
||
| 50 | "-r", |
||
| 51 | "--remote", |
||
| 52 | dest="remote", |
||
| 53 | help="Get latest OTA versions from remote server", |
||
| 54 | action="store_true", |
||
| 55 | default=False) |
||
| 56 | parser.add_argument( |
||
| 57 | "-t", |
||
| 58 | "--device-type", |
||
| 59 | dest="device", |
||
| 60 | help="Scan only one device", |
||
| 61 | default=None, |
||
| 62 | type=utilities.droidlookup_devicetype) |
||
| 63 | parser.add_argument( |
||
| 64 | "-x", |
||
| 65 | "--export", |
||
| 66 | dest="export", |
||
| 67 | help="Write XML to logs folder", |
||
| 68 | action="store_true", |
||
| 69 | default=False) |
||
| 70 | args = parser.parse_args(sys.argv[1:]) |
||
| 71 | parser.set_defaults() |
||
| 72 | execute_args(args) |
||
| 73 | |||
| 195 |