Conditions | 2 |
Total Lines | 83 |
Code Lines | 60 |
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 | tmp_help = "Store intermediate files in a temp directory." |
||
53 | parser.add_argument("-d", "--tmp", help=tmp_help) |
||
54 | |||
55 | template_help = "Pass a template file of plugin input parameters." |
||
56 | parser.add_argument("-t", "--template", help=template_help, default=None) |
||
57 | |||
58 | log_help = "Store full log file in a separate location" |
||
59 | parser.add_argument("-l", "--log", help=log_help) |
||
60 | |||
61 | v_help = "Display all debug log messages" |
||
62 | parser.add_argument("-v", "--verbose", help=v_help, action="store_true", |
||
63 | default=False) |
||
64 | parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", |
||
65 | help="Display only Errors and Info.", default=False) |
||
66 | # temporary flag to fix lustre issue |
||
67 | parser.add_argument("--lustre_workaround", action="store_true", |
||
68 | dest="lustre", help="Avoid lustre segmentation fault", |
||
69 | default=False) |
||
70 | sys_params_help = "Override default path to Savu system parameters file." |
||
71 | parser.add_argument("--system_params", help=sys_params_help, default=None) |
||
72 | |||
73 | # Hidden arguments |
||
74 | # process names |
||
75 | parser.add_argument("-n", "--names", help=hide, default="CPU0") |
||
76 | # transport mechanism |
||
77 | parser.add_argument("--transport", help=hide, default="hdf5") |
||
78 | # Set Savu mode |
||
79 | parser.add_argument("-m", "--mode", help=hide, default="full", |
||
80 | choices=['basic', 'full']) |
||
81 | # Set logging to cluster mode |
||
82 | parser.add_argument("-c", "--cluster", action="store_true", help=hide, |
||
83 | default=False) |
||
84 | # Send an email on completion |
||
85 | parser.add_argument("-e", "--email", dest="email", help=hide, default=None) |
||
86 | # Facility email for errors |
||
87 | parser.add_argument("--facility_email", dest="femail", help=hide, |
||
88 | default=None) |
||
89 | # Set beamline log file (for online processing) |
||
90 | parser.add_argument("--bllog", dest="bllog", help=hide, default=None) |
||
91 | # Location of syslog server |
||
92 | parser.add_argument("-s", "--syslog", dest="syslog", help=hide, |
||
93 | default='localhost') |
||
94 | # Port to connect to syslog server on |
||
95 | parser.add_argument("-p", "--syslog_port", dest="syslog_port", |
||
96 | help=hide, default=514, type=int) |
||
97 | parser.add_argument("--test_state", dest="test_state", default='False', |
||
98 | action='store_true', help=hide) |
||
99 | |||
100 | # DosNa related parameters |
||
101 | parser.add_argument("--dosna_backend", dest="dosna_backend", help=hide, |
||
102 | default=None) |
||
103 | parser.add_argument("--dosna_engine", dest="dosna_engine", help=hide, |
||
104 | default=None) |
||
105 | parser.add_argument("--dosna_connection", dest="dosna_connection", |
||
106 | help=hide, default=None) |
||
107 | parser.add_argument("--dosna_connection_options", |
||
108 | dest="dosna_connection_options", help=hide, |
||
109 | nargs='+', default=[]) |
||
110 | |||
111 | check_help = "Continue Savu processing from a checkpoint." |
||
112 | choices = ['plugin', 'subplugin'] |
||
113 | parser.add_argument("--checkpoint", nargs="?", choices=choices, |
||
114 | const='plugin', help=check_help, default=None) |
||
115 | if doc==False: |
||
116 | args = parser.parse_args() |
||
117 | __check_conditions(parser, args) |
||
118 | return args |
||
119 | else: |
||
120 | return parser |
||
121 | |||
237 |