cliopts.py 28.1 KB
Newer Older
Lab's avatar
Update    
Lab committed
1
2
3
4
5
6
7
8
9
10
11
12
13
from optparse import OptionParser   # from version 2.3 to 2.7
from argparse import ArgumentParser
from . import standardhandle
from . import options
##############################################################################
#
# closercliparsing
#
##############################################################################
def closer_argparser():
    tag = standardhandle.gettag()
    parser = ArgumentParser()
    parser.add_argument("-c", "--config", action = "store", dest = "configfile", default = None,
14
                      help = "use specific config file [default cfg/sequencer.cfg]")
Lab's avatar
Update    
Lab committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    parser.add_argument("-d", "--date", action = "store", type = str, dest = "date",
                      help = "observation ending date YYYY_MM_DD [default today]")
    parser.add_argument("-n", "--usenightsummary", action = "store_true", dest = "nightsum", default = False,
                      help = "rely on existing nightsumary file")
    parser.add_argument("-o", "--outputdir", action = "store", type = str, dest = "directory",
                      help = "analysis output directory")
    parser.add_argument("-r", "--reason", action = "store", type = str, dest = "reason",
                      choices = ['moon', 'weather', 'other'],
                      help = "reason for closing without data: (moon, weather, other)")
    parser.add_argument("-s", "--simulate", action = "store_true", dest = "simulate", default = False,
                      help = "do not run, just show what would happen")
    parser.add_argument("-y", "--yes", action = "store_true", dest = "noninteractive", default = False,
                      help = "assume yes to all questions")
    parser.add_argument("-v", "--verbose", action = "store_true", dest = "verbose", default = False,
                      help = "make lots of noise for debugging")
    parser.add_argument("-w", "--warnings", action = "store_true", dest = "warning", default = False,
                      help = "show useful warnings")
    parser.add_argument("--stderr", action = "store", type = str, dest = "stderr",
                      help = "file for standard error")
    parser.add_argument("--stdout", action = "store", type = str, dest = "stdout",
                      help = "file for standard output")
    parser.add_argument("--seq", action = "store", type = str, dest = "seqtoclose",
                      help="If you only want to close a certain sequence")
    parser.add_argument('tel_id', choices=['ST', 'LST1', 'LST2'])
    return parser

def closercliparsing():
    tag = standardhandle.gettag()

    # Parse the command line
    opts = closer_argparser().parse_args()

    # Set global variables
    options.configfile = opts.configfile
    options.stderr = opts.stderr
    options.stdout = opts.stdout
    options.date = opts.date
    options.directory = opts.directory
    options.nightsum = opts.nightsum
    options.noninteractive = opts.noninteractive
    options.simulate = opts.simulate
    options.verbose = opts.verbose
    options.warning = opts.warning
    options.reason = opts.reason
    options.seqtoclose = opts.seqtoclose
    options.tel_id = opts.tel_id

    standardhandle.verbose(tag, "the options are {0}".format(opts))

    # Setting the default date and directory if needed
65
66
    # options.configfile = set_default_configfile_if_needed('closer.py')
    options.configfile = set_default_configfile_if_needed('sequencer.py')
Lab's avatar
Update    
Lab committed
67
68
69
70
71
    options.date = set_default_date_if_needed()
    options.directory = set_default_directory_if_needed()

    # Setting on the usage of night summary
    options.nightsum = True
72
73


Lab's avatar
Update    
Lab committed
74
75
##############################################################################
#
76
# pedestalsequencecliparsing
Lab's avatar
Update    
Lab committed
77
78
#
##############################################################################
79
def pedestalsequencecliparsing(command):
Lab's avatar
Update    
Lab committed
80
    tag = standardhandle.gettag()
81
    message = "usage: %prog [-vw] [-c CONFIGFILE] [-d DATE] [-o OUTPUTDIR] [-z] <PED_RUN_ID>  <TEL_ID>"
Lab's avatar
Update    
Lab committed
82
83
    parser = OptionParser(usage = message)
    parser.add_option("-c", "--config", action = "store", dest = "configfile", default = None,
84
                      help = "use specific config file [default cfg/sequencer.cfg]")
Lab's avatar
Update    
Lab committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
    parser.add_option("-d", "--date", action = "store", type = "string", dest = "date",
                      help = "observation ending date YYYY_MM_DD [default today]")
    parser.add_option("-o", "--outputdir", action = "store", type = "string", dest = "directory",
                      help = "write files to output directory")
    parser.add_option("-v", "--verbose", action = "store_true", dest = "verbose", default = False,
                      help = "make lots of noise for debugging")
    parser.add_option("-w", "--warnings", action = "store_true", dest = "warning", default = False,
                      help = "show useful warnings")
    parser.add_option("-z", "--rawzip", action = "store_true", dest = "compressed", default = False,
                      help = "Use input as compressed raw.gz files")
    parser.add_option("--stderr", action = "store", type = "string", dest = "stderr",
                      help = "file for standard error")
    parser.add_option("--stdout", action = "store", type = "string", dest = "stdout",
                      help = "file for standard output")

100

Lab's avatar
Update    
Lab committed
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
    # Parse the command line
    (opts, args) = parser.parse_args()

    # Set global variables
    options.configfile = opts.configfile
    options.stderr = opts.stderr
    options.stdout = opts.stdout
    options.date = opts.date
    options.directory = opts.directory
    options.verbose = opts.verbose
    options.warning = opts.warning
    options.compressed = opts.compressed

    # The standardhandle has to be declared here, since verbose and warnings are options from the cli
    standardhandle.verbose(tag, "the options are {0}".format(opts))
    standardhandle.verbose(tag, "the argument is {0}".format(args))

    # Mapping the telescope argument to an option parameter (it might become an option in the future)
119
    if len(args) != 2:
Lab's avatar
Update    
Lab committed
120
121
122
123
124
125
126
127
128
129
        standardhandle.error(tag, "incorrect number of arguments, type -h for help", 2)
    elif args[1] == 'ST':
        standardhandle.error(tag, "not yet ready for telescope {0}".format(options.options.tel_id), 2)
    elif args[1] != 'LST1' and args[1] != 'LST2':
        standardhandle.error(tag, "wrong telescope id, use 'LST1', 'LST2' or 'ST'", 2)

    options.tel_id = args[1]

    # Setting the default date and directory if needed
    options.configfile = set_default_configfile_if_needed(command)
130
131
132
133
134
135
136
137
138
139
140
141
    
    return args
    

    
##############################################################################
#
# calibrationsequencecliparsing
#
##############################################################################
def calibrationsequencecliparsing(command):
    tag = standardhandle.gettag()
Lab's avatar
Lab committed
142
    message = "usage: %prog [-vw] [-c CONFIGFILE] [-d DATE] [-o OUTPUTDIR] [-z] <pedoutfile> <caloutfile> <CAL_RUN_ID> <PED_RUN_ID>  <TEL_ID>"
143
144
    parser = OptionParser(usage = message)
    parser.add_option("-c", "--config", action = "store", dest = "configfile", default = None,
145
                      help = "use specific config file [default cfg/sequencer.cfg]")
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
    parser.add_option("-d", "--date", action = "store", type = "string", dest = "date",
                      help = "observation ending date YYYY_MM_DD [default today]")
    parser.add_option("-o", "--outputdir", action = "store", type = "string", dest = "directory",
                      help = "write files to output directory")
    parser.add_option("-v", "--verbose", action = "store_true", dest = "verbose", default = False,
                      help = "make lots of noise for debugging")
    parser.add_option("-w", "--warnings", action = "store_true", dest = "warning", default = False,
                      help = "show useful warnings")
    parser.add_option("-z", "--rawzip", action = "store_true", dest = "compressed", default = False,
                      help = "Use input as compressed raw.gz files")
    parser.add_option("--stderr", action = "store", type = "string", dest = "stderr",
                      help = "file for standard error")
    parser.add_option("--stdout", action = "store", type = "string", dest = "stdout",
                      help = "file for standard output")

    # Parse the command line
    (opts, args) = parser.parse_args()

    # Set global variables
    options.configfile = opts.configfile
    options.stderr = opts.stderr
    options.stdout = opts.stdout
    options.date = opts.date
    options.directory = opts.directory
    options.verbose = opts.verbose
    options.warning = opts.warning
    options.compressed = opts.compressed

    # The standardhandle has to be declared here, since verbose and warnings are options from the cli
    standardhandle.verbose(tag, "the options are {0}".format(opts))
    standardhandle.verbose(tag, "the argument is {0}".format(args))

    # Mapping the telescope argument to an option parameter (it might become an option in the future)
Lab's avatar
Lab committed
179
    if len(args) != 5:
180
        standardhandle.error(tag, "incorrect number of arguments, type -h for help", 2)
Lab's avatar
Lab committed
181
    elif args[4] == 'ST':
182
        standardhandle.error(tag, "not yet ready for telescope {0}".format(options.options.tel_id), 2)
Lab's avatar
Lab committed
183
    elif args[4] != 'LST1' and args[4] != 'LST2':
184
185
        standardhandle.error(tag, "wrong telescope id, use 'LST1', 'LST2' or 'ST'", 2)

Lab's avatar
Lab committed
186
    options.tel_id = args[4]
187
188
189

    # Setting the default date and directory if needed
    options.configfile = set_default_configfile_if_needed(command)
Lab's avatar
Update    
Lab committed
190
191
192
193
194
195
196
197
198
199
200
    options.date = set_default_date_if_needed()
    options.directory = set_default_directory_if_needed()

    return args
##############################################################################
#
# datasequencecliparsing
#
##############################################################################
def datasequencecliparsing(command):
    tag = standardhandle.gettag()
201
202
203
    message = "usage: %prog  [-vw] [--stderr=FILE] [--stdout=FILE] [-c CONFIGFILE] [-d DATE] [-o OUTPUTDIR] [-z] \
<calibrationfile> <pedestalfile> <drivefile> <timecalibration> <ucts_t0_dragon> <dragon_counter0> \
<ucts_t0_tib> <tib_counter> <RUN> <TEL_ID>"
Lab's avatar
Update    
Lab committed
204
205
    parser = OptionParser(usage = message)
    parser.add_option("-c", "--config", action = "store", dest = "configfile", default = None,
206
                      help = "use specific config file [default cfg/sequencer.cfg]")
Lab's avatar
Update    
Lab committed
207
208
209
    parser.add_option("-d", "--date", action = "store", type = "string", dest = "date",
                      help = "observation ending date YYYY_MM_DD [default today]")
    parser.add_option("-o", "--outputdir", action = "store", type = "string", dest = "directory",
210
                      help = "analysis output directory")
Lab's avatar
Update    
Lab committed
211
212
213
214
215
216
217
218
219
220
    parser.add_option("-v", "--verbose", action = "store_true", dest = "verbose", default = False,
                      help = "make lots of noise for debugging")
    parser.add_option("-w", "--warnings", action = "store_true", dest = "warning", default = False,
                      help = "show useful warnings")
    parser.add_option("-z", "--rawzip", action = "store_true", dest = "compressed", default = False,
                      help = "Use input as compressed raw.gz files")
    parser.add_option("--stderr", action = "store", type = "string", dest = "stderr",
                      help = "file for standard error")
    parser.add_option("--stdout", action = "store", type = "string", dest = "stdout",
                      help = "file for standard output")
221
222
    parser.add_option("--prod_id", action = "store", type = str, dest = "prod_id",
                      help="Set the prod_id variable which defines data directories")
Lab's avatar
Update    
Lab committed
223
224
225
226
227
228
229
230
231
232
233
234
235

    # Parse the command line
    (opts, args) = parser.parse_args()

    # Set global variables
    options.configfile = opts.configfile
    options.stderr = opts.stderr
    options.stdout = opts.stdout    
    options.date = opts.date
    options.directory = opts.directory
    options.verbose = opts.verbose
    options.warning = opts.warning
    options.compressed = opts.compressed
236
    options.prod_id = opts.prod_id
Lab's avatar
Update    
Lab committed
237
238
239
240
241
242

    # The standardhandle has to be declared here, since verbose and warnings are options from the cli
    standardhandle.verbose(tag, "the options are {0}".format(opts))
    standardhandle.verbose(tag, "the argument is {0}".format(args))

    # Checking arguments
243
    if len(args) != 10:
Lab's avatar
Update    
Lab committed
244
245
        standardhandle.error(tag, "incorrect number of arguments, type -h for help", 2)
    # Mapping the telescope argument to an option parameter (it might become an option in the future)
246
    elif args[9] == 'ST':
Lab's avatar
Update    
Lab committed
247
        standardhandle.error(tag, "not yet ready for telescope {0}".format(options.options.tel_id), 2)
248
    elif args[9] != 'LST1' and args[9] != 'LST2':
Lab's avatar
Update    
Lab committed
249
        standardhandle.error(tag, "wrong telescope id, use 'LST1', 'LST2' or 'ST'", 2)
250
    options.tel_id = args[9]
Lab's avatar
Update    
Lab committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267

    # Setting the default date and directory if needed
    options.configfile = set_default_configfile_if_needed(command)
    options.date = set_default_date_if_needed()
    options.directory = set_default_directory_if_needed()

    return args
##############################################################################
#
# stereosequencecliparsing
#
##############################################################################
def stereosequencecliparsing(command):
    tag = standardhandle.gettag()
    message = "usage: %prog  [-vw] [--stderr=FILE] [--stdout=FILE] [-c CONFIGFILE] [-d DATE] [-o OUTPUTDIR] [-z] <RUN>"
    parser = OptionParser(usage = message)
    parser.add_option("-c", "--config", action = "store", dest = "configfile", default = None,
268
                      help = "use specific config file [default cfg/sequencer.cfg]")
Lab's avatar
Update    
Lab committed
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
    parser.add_option("-d", "--date", action = "store", type = "string", dest = "date",
                      help = "observation ending date YYYY_MM_DD [default today]")
    parser.add_option("-o", "--outputdir", action = "store", type = "string", dest = "directory",
                          help = "analysis output directory")
    parser.add_option("-v", "--verbose", action = "store_true", dest = "verbose", default = False,
                      help = "make lots of noise for debugging")
    parser.add_option("-w", "--warnings", action = "store_true", dest = "warning", default = False,
                      help = "show useful warnings")
    parser.add_option("-z", "--rawzip", action = "store_true", dest = "compressed", default = False,
                      help = "Use input as compressed raw.gz files")
    parser.add_option("--stderr", action = "store", type = "string", dest = "stderr",
                      help = "file for standard error")
    parser.add_option("--stdout", action = "store", type = "string", dest = "stdout",
                      help = "file for standard output")

    # Parse the command line
    (opts, args) = parser.parse_args()

    # Set global variables
    options.configfile = opts.configfile
    options.stderr = opts.stderr
    options.stdout = opts.stdout    
    options.date = opts.date
    options.directory = opts.directory
    options.verbose = opts.verbose
    options.warning = opts.warning
    options.compressed = opts.compressed

    # The standardhandle has to be declared here, since verbose and warnings are options from the cli
    standardhandle.verbose(tag, "the options are {0}".format(opts))
    standardhandle.verbose(tag, "the argument is {0}".format(args))

    # Checking arguments
    if len(args) != 1:
        standardhandle.error(tag, "incorrect number of arguments, type -h for help", 2)
    # Mapping the telescope argument to an option parameter (it might become an option in the future)
    options.tel_id = 'ST'

    # Setting the default date and directory if needed
    options.configfile = set_default_configfile_if_needed(command)
    options.date = set_default_date_if_needed()
    options.directory = set_default_directory_if_needed()

    return args
##############################################################################
#
# sequencercliparsing
#
##############################################################################
def sequencer_argparser():
    tag = standardhandle.gettag()
    parser = ArgumentParser()
    """ Options which define variables """
    parser.add_argument("-c", "--config", action = "store", dest = "configfile", default = None,
323
                        help = "use specific config file [default cfg/sequencer.cfg]")
Lab's avatar
Update    
Lab committed
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
    parser.add_argument("-d", "--date", action = "store", type = str, dest = "date",
                        help = "observation ending date YYYY_MM_DD [default today]")
    parser.add_argument("-m", "--mode", action = "store", type = str, dest = "mode", choices = ['P', 'S', 'T'],
                        help = "mode to run dependant sequences:\n P=parallel [default], S=Sequential, T=temperature-aware")
    """ Boolean options """
    parser.add_argument("-n", "--usenightsummary", action = "store_true", dest = "nightsum", default = False,
                        help = "rely on existing nightsumary file")
    parser.add_argument("-o", "--outputdir", action = "store", type = str, dest = "directory",
                        help = "analysis output directory")
    parser.add_argument("-s", "--simulate", action = "store_true", dest = "simulate", default = False,
                        help = "do not submit sequences as jobs")
    parser.add_argument("-v", "--verbose", action = "store_true", dest = "verbose", default = False,
                        help = "make lots of noise for debugging")
    parser.add_argument("-w", "--warnings", action = "store_true", dest = "warning", default = False,
                        help = "show useful warnings")
    parser.add_argument("-z", "--rawzip", action = "store_true", dest = "compressed", default = False,
                        help = "Use input as compressed raw.gz files, compulsory if using -n and raw.gz files")
    parser.add_argument("--stderr", action = "store", type = str, dest = "stderr",
                        help = "file for standard error")
    parser.add_argument("--stdout", action = "store", type = str, dest = "stdout",
                        help = "file for standard output")
    parser.add_argument('tel_id', choices=['ST', 'LST1', 'LST2', 'all'], help = "telescope identifier LST1, LST2, ST or all.")
    return parser

Daniel Morcuende's avatar
Daniel Morcuende committed
348
349

def sequencercliparsing():
Lab's avatar
Update    
Lab committed
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
    tag = standardhandle.gettag()

    # Parse the command line
    opts = sequencer_argparser().parse_args()

    # Set global variables
    options.configfile = opts.configfile
    options.stderr = opts.stderr
    options.stdout = opts.stdout
    options.date = opts.date
    options.directory = opts.directory
    options.mode = opts.mode
    options.nightsum = opts.nightsum
    options.simulate = opts.simulate
    options.verbose = opts.verbose
    options.warning = opts.warning
    options.compressed = opts.compressed
    options.tel_id = opts.tel_id

    # The standardhandle has to be declared before here, since verbose and warnings are options from the cli
    standardhandle.verbose(tag, "the options are {0}".format(opts))

    # Set the default value for mode
    if not opts.mode:
        options.mode = 'P'

    # Setting the default date and directory if needed
    options.configfile = set_default_configfile_if_needed('sequencer.py')
    options.date = set_default_date_if_needed()
Daniel Morcuende's avatar
Daniel Morcuende committed
379
380


Lab's avatar
Update    
Lab committed
381
382
383
384
385
386
387
388
389
390
391
392
##############################################################################
#
# monolithcliparsing
#
##############################################################################
def monolithcliparsing(command):
    tag = standardhandle.gettag()
    message = "usage: %prog [-syvw] [--stderr=FILE] [--stdout=FILE] [-c CONFIGFILE] [-t] TEL_ID"
    parser = OptionParser(usage = message)
    # Options which define variables
    parser = OptionParser(usage = message)
    parser.add_option("-c", "--config", action = "store", dest = "configfile", default = None,
393
                      help = "use specific config file [default cfg/sequencer.cfg]")
Lab's avatar
Update    
Lab committed
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
    parser.add_option("-t", "--telescope", action = "store", type = "choice", dest = "tel_id",
                      choices = ['LST1', 'LST2', 'ST'], help = "telescope identifier LST1, LST2 or ST [default all]")
    parser.add_option("-s", "--simulate", action = "store_true", dest = "simulate", default = False,
                      help = "do not run, just show what would happen")
    parser.add_option("-y", "--yes", action = "store_true", dest = "noninteractive", default = False,
                      help = "assume yes to all questions")
    parser.add_option("-v", "--verbose", action = "store_true", dest = "verbose", default = False,
                      help = "make lots of noise for debugging")
    parser.add_option("-w", "--warnings", action = "store_true", dest = "warning", default = False,
                      help = "show useful warnings")
    parser.add_option("--stderr", action = "store", type = "string", dest = "stderr",
                      help = "file for standard error")
    parser.add_option("--stdout", action = "store", type = "string", dest = "stdout",
                      help = "file for standard output")

    # Parse the command line
    (opts, args) = parser.parse_args()

    # Set global variables
    options.configfile = opts.configfile
    options.stderr = opts.stderr
    options.stdout = opts.stdout    
    options.tel_id = opts.tel_id
    options.simulate = opts.simulate
    options.noninteractive = opts.noninteractive
    options.verbose = opts.verbose
    options.warning = opts.warning

    # The standardhandle has to be declared here, since verbose and warnings are options from the cli
    standardhandle.verbose(tag, "the options are {0}".format(opts))
    standardhandle.verbose(tag, "the argument is {0}".format(args))

    # Mapping the telescope argument to an option parameter (it might become an option in the future)
    if len(args) > 1:
        standardhandle.error(tag, "incorrect number of arguments, type -h for help", 2)
    elif len(args) == 1:
        if (args[0] != 'LST1' and args[0] != 'LST2' and args[0] != 'ST'):
            standardhandle.error(tag, "wrong telescope id, use 'LST1', 'LST2' or 'ST'", 2)
        options.tel_id = args[0]

    options.configfile = set_default_configfile_if_needed(command)
    return args
##############################################################################
#
# rawcopycliparsing
#
##############################################################################
def rawcopycliparsing(command):
    tag = standardhandle.gettag()
    message = "usage: %prog [-vw] [--stderr=FILE] [--stdout=FILE] [-c CONFIGFILE] [-d DATE] [-z] <TEL_ID>"
    parser = OptionParser(usage = message)
    parser.add_option("-c", "--config", action = "store", dest = "configfile", default = None,
                      help = "use specific config file [default rawcopy.cfg]")
    parser.add_option("-d", "--date", action = "store", type = "string", dest = "date",
                      help = "observation ending date YYYY_MM_DD [default today]")
    parser.add_option("--nocheck", action = "store_true", dest = "nocheck", default = False,
                          help = "Skip checking if the daily activity is set over")
    parser.add_option("-v", "--verbose", action = "store_true", dest = "verbose", default = False,
                      help = "make lots of noise for debugging")
    parser.add_option("-w", "--warnings", action = "store_true", dest = "warning", default = False,
                      help = "show useful warnings")
    parser.add_option("-z", "--rawzip", action = "store_true", dest = "compressed", default = False,
                      help = "compress output into raw.gz files")
    parser.add_option("--stderr", action = "store", type = "string", dest = "stderr",
                      help = "file for standard error")
    parser.add_option("--stdout", action = "store", type = "string", dest = "stdout",
                      help = "file for standard output")

    # Parse the command line
    (opts, args) = parser.parse_args()

    # Set global variables
    options.configfile = opts.configfile
    options.stderr = opts.stderr
    options.stdout = opts.stdout    
    options.date = opts.date 
    options.nocheck = opts.nocheck
    options.verbose = opts.verbose
    options.warning = opts.warning
    options.compressed = opts.compressed

    # The standardhandle has to be declared here, since verbose and warnings are options from the cli
    standardhandle.verbose(tag, "the options are {0}".format(opts))
    standardhandle.verbose(tag, "the argument is {0}".format(args))

    # Mapping the telescope argument to an option parameter (it might become an option in the future)
    if len(args) != 1:
        standardhandle.error(tag, "incorrect number of arguments, type -h for help", 2)
    elif args[0] == 'ST':
        standardhandle.error(tag, "not yet ready for telescope {0}".format(options.options.tel_id), 2)
Daniel Morcuende's avatar
Daniel Morcuende committed
484
    elif args[0] != 'LST1' and args[0] != 'LST2':
Lab's avatar
Update    
Lab committed
485
486
487
488
489
490
        standardhandle.error(tag, "wrong telescope id, use 'LST1', 'LST2' or 'ST'", 2)
    options.tel_id = args[0]

    options.configfile = set_default_configfile_if_needed(command)
    options.date = set_default_date_if_needed()
    return args
491
492
493
494
495
496
497
498
499


##############################################################################
#
# provprocessparsing
#
##############################################################################
def provprocessparsing():
    tag = standardhandle.gettag()
500
    message = "usage: %prog [-c CONFIGFILE] [-f PROCESS] <RUN_NUMBER> <DATEFOLDER> <SUBFOLDER>"
501
    parser = OptionParser(usage=message)
502
    parser.add_option("-c", "--config", action="store", dest="configfile", default="cfg/sequencer.cfg",
503
                      help="use specific config file [default cfg/sequencer.cfg]")
504
505
    parser.add_option("-f", "--filter", action="store", dest="filter", default="",
                      help="filter by process granularity [r0_to_dl1 or dl1_to_dl2]")
506
    parser.add_option("-q", action="store_true", dest="quit", help="use this flag to reset session and remove log file")
507
508
509
510

    # Parse the command line
    (opts, args) = parser.parse_args()
    # Checking arguments
511
    if len(args) != 3:
512
        standardhandle.error(tag, "incorrect number of arguments, type -h for help", 2)
Jose Enrique.Ruiz's avatar
Jose Enrique.Ruiz committed
513
    if opts.filter not in ["r0_to_dl1", "dl1_to_dl2", ""]:
514
        standardhandle.error(tag, "incorrect value for --filter argument, type -h for help", 2)
515
516
517

    # Set global variables
    options.run = args[0]
518
519
    options.datefolder = args[1]
    options.subfolder = args[2]
520
    options.configfile = opts.configfile
521
    options.filter = opts.filter
522
    options.quit = opts.quit
523

524
    return options, tag
525
526


Lab's avatar
Update    
Lab committed
527
528
529
530
531
532
533
534
535
536
537
##############################################################################
#
# set_default_date_if_needed
#
##############################################################################
def set_default_date_if_needed():
    tag = standardhandle.gettag()
    from .utils import is_defined
    if is_defined(options.date):
        return options.date
    else:
Lab's avatar
Lab committed
538
539
540
        from .utils import getcurrentdate2
        from osa.configs.config import cfg
        return getcurrentdate2(cfg.get('LST', 'DATESEPARATOR'))
Lab's avatar
Update    
Lab committed
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
##############################################################################
#
# set_default_directory_if_needed
#
##############################################################################
def set_default_directory_if_needed():
    tag = standardhandle.gettag()
    from osa.utils.utils import is_defined, getnightdirectory
    if is_defined(options.directory):
        return options.directory
    else:
        return getnightdirectory()
##############################################################################
#
# set_default_configfile_if_needed
#
##############################################################################
def set_default_configfile_if_needed(command):
    tag = standardhandle.gettag()

    """ The default config will be the name of the program, with suffix .cfg
        and present in the cfg subdir, trivial, isn't it? """ 

    from os.path import abspath, dirname, basename, join
    standardhandle.verbose(tag, "Command is {0}".format(command))
    if not options.configfile:
        command_dirname = dirname(abspath(command))
        command_basename = basename(command)
        config_basename = command_basename.replace('.py', '.cfg')
        options.configfile = join(command_dirname, 'cfg', config_basename)

    standardhandle.verbose(tag, "Setting default config file to {0}".format(options.configfile))
    return options.configfile