cliopts.py 27.3 KB
Newer Older
Lab's avatar
Update    
Lab committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
65
66
67
68
69
70
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,
                      help = "use specific config file [default cfg/osa.cfg]")
    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
    options.configfile = set_default_configfile_if_needed('closer.py')
    options.date = set_default_date_if_needed()
    options.directory = set_default_directory_if_needed()

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


Lab's avatar
Update    
Lab committed
73
74
##############################################################################
#
75
# pedestalsequencecliparsing
Lab's avatar
Update    
Lab committed
76
77
#
##############################################################################
78
def pedestalsequencecliparsing(command):
Lab's avatar
Update    
Lab committed
79
    tag = standardhandle.gettag()
80
    message = "usage: %prog [-vw] [-c CONFIGFILE] [-d DATE] [-o OUTPUTDIR] [-z] <PED_RUN_ID>  <TEL_ID>"
Lab's avatar
Update    
Lab committed
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    parser = OptionParser(usage = message)
    parser.add_option("-c", "--config", action = "store", dest = "configfile", default = None,
                      help = "use specific config file [default cfg/osa.cfg]")
    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")

99

Lab's avatar
Update    
Lab committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
    # 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)
118
    if len(args) != 2:
Lab's avatar
Update    
Lab committed
119
120
121
122
123
124
125
126
127
128
        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)
129
130
131
132
133
134
135
136
137
138
139
140
    
    return args
    

    
##############################################################################
#
# calibrationsequencecliparsing
#
##############################################################################
def calibrationsequencecliparsing(command):
    tag = standardhandle.gettag()
Lab's avatar
Lab committed
141
    message = "usage: %prog [-vw] [-c CONFIGFILE] [-d DATE] [-o OUTPUTDIR] [-z] <pedoutfile> <caloutfile> <CAL_RUN_ID> <PED_RUN_ID>  <TEL_ID>"
142
143
144
145
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
    parser = OptionParser(usage = message)
    parser.add_option("-c", "--config", action = "store", dest = "configfile", default = None,
                      help = "use specific config file [default cfg/osa.cfg]")
    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
178
    if len(args) != 5:
179
        standardhandle.error(tag, "incorrect number of arguments, type -h for help", 2)
Lab's avatar
Lab committed
180
    elif args[4] == 'ST':
181
        standardhandle.error(tag, "not yet ready for telescope {0}".format(options.options.tel_id), 2)
Lab's avatar
Lab committed
182
    elif args[4] != 'LST1' and args[4] != 'LST2':
183
184
        standardhandle.error(tag, "wrong telescope id, use 'LST1', 'LST2' or 'ST'", 2)

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

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

    return args
##############################################################################
#
# datasequencecliparsing
#
##############################################################################
def datasequencecliparsing(command):
    tag = standardhandle.gettag()
Lab's avatar
Lab committed
200
    message = "usage: %prog  [-vw] [--stderr=FILE] [--stdout=FILE] [-c CONFIGFILE] [-d DATE] [-o OUTPUTDIR] [-z] <calibrationfile> <pedestalfile> <drivefile> <timecalibration> <RUN> <TEL_ID>"
Lab's avatar
Update    
Lab committed
201
202
203
204
205
206
    parser = OptionParser(usage = message)
    parser.add_option("-c", "--config", action = "store", dest = "configfile", default = None,
                      help = "use specific config file [default cfg/osa.cfg]")
    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",
207
                      help = "analysis output directory")
Lab's avatar
Update    
Lab committed
208
209
210
211
212
213
214
215
216
217
    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")
218
219
    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
220
221
222
223
224
225
226
227
228
229
230
231
232

    # 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
233
    options.prod_id = opts.prod_id
Lab's avatar
Update    
Lab committed
234
235
236
237
238
239

    # 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
240
    if len(args) != 10:
Lab's avatar
Update    
Lab committed
241
242
        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)
243
    elif args[9] == 'ST':
Lab's avatar
Update    
Lab committed
244
        standardhandle.error(tag, "not yet ready for telescope {0}".format(options.options.tel_id), 2)
245
    elif args[9] != 'LST1' and args[9] != 'LST2':
Lab's avatar
Update    
Lab committed
246
        standardhandle.error(tag, "wrong telescope id, use 'LST1', 'LST2' or 'ST'", 2)
247
    options.tel_id = args[9]
Lab's avatar
Update    
Lab committed
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
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
484

    # 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,
                      help = "use specific config file [default cfg/osa.cfg]")
    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,
                        help = "use specific config file [default cfg/osa.cfg]")
    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

def sequencercliparsing(command):
    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()
##############################################################################
#
# 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,
                      help = "use specific config file [default cfg/osa.cfg]")
    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)
    elif args[0] != 'LST1' and args[0] != 'M2':
        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
485
486
487
488
489
490
491
492
493


##############################################################################
#
# provprocessparsing
#
##############################################################################
def provprocessparsing():
    tag = standardhandle.gettag()
494
    message = "usage: %prog [-p PROVFILE] <RUN_NUMBER> <DESTINATION_FOLDER>"
495
    parser = OptionParser(usage=message)
496
497
    parser.add_option("-p", "--prov", action="store", dest="provfile", default="prov.log",
                      help="provenance file to process [default prov.log]")
498
499
500
501

    # Parse the command line
    (opts, args) = parser.parse_args()
    # Checking arguments
502
    if len(args) != 2:
503
504
505
506
        standardhandle.error(tag, "incorrect number of arguments, type -h for help", 2)

    # Set global variables
    options.run = args[0]
507
508
    options.out = args[1]
    options.src = opts.provfile
509

510
    return options, tag
511
512


Lab's avatar
Update    
Lab committed
513
514
515
516
517
518
519
520
521
522
523
##############################################################################
#
# 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
524
525
526
        from .utils import getcurrentdate2
        from osa.configs.config import cfg
        return getcurrentdate2(cfg.get('LST', 'DATESEPARATOR'))
Lab's avatar
Update    
Lab committed
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
##############################################################################
#
# 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