Conditions | 2 |
Total Lines | 89 |
Code Lines | 63 |
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 | # Copyright 2014 Diamond Light Source Ltd. |
||
38 | def __option_parser(doc=True): |
||
39 | """ Option parser for command line arguments. |
||
40 | """ |
||
41 | version = "%(prog)s " + __version__ |
||
42 | parser = argparse.ArgumentParser(prog='savu') |
||
43 | hide = argparse.SUPPRESS |
||
44 | |||
45 | parser.add_argument('in_file', help='Input data file.') |
||
46 | process_str = 'Process list, created with the savu configurator.' |
||
47 | parser.add_argument('process_list', help=process_str) |
||
48 | parser.add_argument('out_folder', help='Output folder.') |
||
49 | parser.add_argument('--version', action='version', version=version) |
||
50 | parser.add_argument("-f", "--folder", help="Override output folder name") |
||
51 | |||
52 | parser.add_argument("--pre_run", help="Pre-run of savu to gather stats and cropping information.", |
||
53 | action="store_true", default=False) |
||
54 | |||
55 | tmp_help = "Store intermediate files in a temp directory." |
||
56 | parser.add_argument("-d", "--tmp", help=tmp_help) |
||
57 | |||
58 | template_help = "Pass a template file of plugin input parameters." |
||
59 | parser.add_argument("-t", "--template", help=template_help, default=None) |
||
60 | |||
61 | log_help = "Store full log file in a separate location" |
||
62 | parser.add_argument("-l", "--log", help=log_help) |
||
63 | |||
64 | v_help = "Display all debug log messages" |
||
65 | parser.add_argument("-v", "--verbose", help=v_help, action="store_true", |
||
66 | default=False) |
||
67 | parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", |
||
68 | help="Display only Errors and Info.", default=False) |
||
69 | # temporary flag to fix lustre issue |
||
70 | parser.add_argument("--lustre_workaround", action="store_true", |
||
71 | dest="lustre", help="Avoid lustre segmentation fault", |
||
72 | default=False) |
||
73 | sys_params_help = "Override default path to Savu system parameters file." |
||
74 | parser.add_argument("--system_params", help=sys_params_help, default=None) |
||
75 | |||
76 | # Set stats off |
||
77 | parser.add_argument("--stats", help="Turn stats 'on' or 'off'.", default="on", choices=["on", "off"]) |
||
78 | |||
79 | # Hidden arguments |
||
80 | # process names |
||
81 | parser.add_argument("-n", "--names", help=hide, default="CPU0") |
||
82 | # transport mechanism |
||
83 | parser.add_argument("--transport", help=hide, default="hdf5") |
||
84 | # Set Savu mode |
||
85 | parser.add_argument("-m", "--mode", help=hide, default="full", |
||
86 | choices=['basic', 'full']) |
||
87 | # Set logging to cluster mode |
||
88 | parser.add_argument("-c", "--cluster", action="store_true", help=hide, |
||
89 | default=False) |
||
90 | # Send an email on completion |
||
91 | parser.add_argument("-e", "--email", dest="email", help=hide, default=None) |
||
92 | # Facility email for errors |
||
93 | parser.add_argument("--facility_email", dest="femail", help=hide, |
||
94 | default=None) |
||
95 | # Set beamline log file (for online processing) |
||
96 | parser.add_argument("--bllog", dest="bllog", help=hide, default=None) |
||
97 | # Location of syslog server |
||
98 | parser.add_argument("-s", "--syslog", dest="syslog", help=hide, |
||
99 | default='localhost') |
||
100 | # Port to connect to syslog server on |
||
101 | parser.add_argument("-p", "--syslog_port", dest="syslog_port", |
||
102 | help=hide, default=514, type=int) |
||
103 | parser.add_argument("--test_state", dest="test_state", default='False', |
||
104 | action='store_true', help=hide) |
||
105 | |||
106 | # DosNa related parameters |
||
107 | parser.add_argument("--dosna_backend", dest="dosna_backend", help=hide, |
||
108 | default=None) |
||
109 | parser.add_argument("--dosna_engine", dest="dosna_engine", help=hide, |
||
110 | default=None) |
||
111 | parser.add_argument("--dosna_connection", dest="dosna_connection", |
||
112 | help=hide, default=None) |
||
113 | parser.add_argument("--dosna_connection_options", |
||
114 | dest="dosna_connection_options", help=hide, |
||
115 | nargs='+', default=[]) |
||
116 | |||
117 | check_help = "Continue Savu processing from a checkpoint." |
||
118 | choices = ['plugin', 'subplugin'] |
||
119 | parser.add_argument("--checkpoint", nargs="?", choices=choices, |
||
120 | const='plugin', help=check_help, default=None) |
||
121 | if doc==False: |
||
122 | args = parser.parse_args() |
||
123 | __check_conditions(parser, args) |
||
124 | return args |
||
125 | else: |
||
126 | return parser |
||
127 | |||
268 |