RunOBs

Bases: KPFFunction

Script to run a list of OBs as scheduled cals.

Source code in kpf/scripts/RunOBs.py
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
class RunOBs(KPFFunction):
    '''Script to run a list of OBs as scheduled cals.
    '''
    @classmethod
    def pre_condition(cls, args):
        # If specified obey the ALLOWSCHEDULEDCALS keyword
        if args.get('scheduled', False) == True:
            ALLOWSCHEDULEDCALS = ktl.cache('kpfconfig', 'ALLOWSCHEDULEDCALS')
            if ALLOWSCHEDULEDCALS.read(binary=True) == False:
                raise FailedPreCondition('ALLOWSCHEDULEDCALS is No')

    @classmethod
    def perform(cls, args):
        for file in args.get('files'):
            file = Path(file)
            try:
                OB = ObservingBlock(file)
            except Exception as e:
                log.error(f'Unable to parse OB from {file}')
                log.error(e)
                break
            if OB.validate():
                RunOB.execute({'waitforscript': True,
                               'scheduled': True},
                              OB=OB)
            else:
                log.error(f'OB from {file} was invalid, not executing OB')

    @classmethod
    def post_condition(cls, args):
        pass

    @classmethod
    def add_cmdline_args(cls, parser):
        parser.add_argument('files', nargs='*',
            help='The OB files to run')
        return super().add_cmdline_args(parser)