StopGUIs

Bases: KPFFunction

Stop KPF GUIs

ARGS

None

Source code in kpf/utils/StopGUIs.py
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
class StopGUIs(KPFFunction):
    '''Stop KPF GUIs

    ### ARGS
    None
    '''
    @classmethod
    def pre_condition(cls, args):
        pass

    @classmethod
    def perform(cls, args):

        for GUI in GUI_list:
            GUIname = GUI['name']
            if GUI['cmd'][0] == 'kpf':
                GUIscriptname = GUI['cmd'][2]
                status_cmd = GUI['cmd']
                status_cmd[1] = 'status'
                log.info(f"Getting status of '{GUIname}' GUI")
                gui_proc = subprocess.run(status_cmd,
                                          stdout=subprocess.PIPE,
                                          stderr=subprocess.PIPE)
                stdout = gui_proc.stdout.decode().strip()
                is_running = re.search('is running on', stdout)
                if is_running is not None:
                    stop_cmd = GUI['cmd']
                    stop_cmd[1] = 'stop'
                    log.info(f"Stopping '{GUIname}' GUI")
                    stopout = subprocess.run(stop_cmd,
                                             stdout=subprocess.PIPE,
                                             stderr=subprocess.PIPE)
                    log.debug(f"{stopout.returncode}")
                    log.debug(f"{stopout.stdout.decode()}")
                    log.debug(f"{stopout.stderr.decode()}")
                else:
                    log.info(f"{GUIname} is not running")
                    log.debug(f"{stdout}")
            elif GUIname == 'MAGIQ - Observer UI':
                log.info(f"Stopping '{GUIname}' GUI")
                stop_cmd = GUI['cmd']
                stop_cmd[4] = 'stop'
                gui_proc = subprocess.Popen(stop_cmd,
                                            stdout=subprocess.PIPE,
                                            stderr=subprocess.PIPE)
            else:
                log.info(f"Stopping '{GUIname}' GUI")
                kill_process(GUI['cmd'], server='kpf')

    @classmethod
    def post_condition(cls, args):
        pass