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