Skip to content
Snippets Groups Projects
anselm.py 2.25 KiB
Newer Older
wactbprot's avatar
wactbprot committed
import sys
wactbprot's avatar
wactbprot committed
import json
wactbprot's avatar
wactbprot committed
import argparse
import pika
from anselm.system import System
wactbprot's avatar
wactbprot committed

wactbprot's avatar
wactbprot committed
class Anselm(System):
    """
    https://chase-seibert.github.io/blog/2014/03/21/python-multilevel-argparse.html
wactbprot's avatar
wactbprot committed


    always talk to short-term-memory, if there is somthing not in stm try to remember
wactbprot's avatar
wactbprot committed
    """
    def __init__(self):
        super().__init__()

        msg_dict = self.config['rabbitmq']
        host = msg_dict['host']
        self.msg_param = pika.ConnectionParameters(host=host)

wactbprot's avatar
ok  
wactbprot committed
        self.init_ctrl_msg_prod()
wactbprot's avatar
wactbprot committed
        self.init_stm_msg_prod()
wactbprot's avatar
ok  
wactbprot committed
        self.init_ltm_msg_prod()
        
wactbprot's avatar
wactbprot committed
        parser = argparse.ArgumentParser(
            description='check systems',
            usage='''anselm <command> [<args>]''')

        parser.add_argument('command', help='Subcommand to run')
        args = parser.parse_args(sys.argv[1:2])

        if not hasattr(self, args.command):
            parser.print_help()
            exit(1)

wactbprot's avatar
wactbprot committed
        if len(args.command) > self.max_arg_len:
            print("command too long")
            exit(1)

wactbprot's avatar
wactbprot committed
        getattr(self, args.command)()

wactbprot's avatar
ok  
wactbprot committed
    def ini_mps(self):
        self.ltm_pub(body_dict={
                    'do':'get_mps',
wactbprot's avatar
wactbprot committed
                    'payload':{}
                    })
wactbprot's avatar
wactbprot committed
        self.ltm_conn.close()

wactbprot's avatar
wactbprot committed
    def clear_stm(self):
wactbprot's avatar
wactbprot committed
        self.stm_pub(body_dict={
wactbprot's avatar
ok  
wactbprot committed
                    'do':'clear_stm',
wactbprot's avatar
wactbprot committed
                    'payload':{}})
wactbprot's avatar
wactbprot committed
        self.stm_conn.close()

    
wactbprot's avatar
wactbprot committed
    def build_auxobj_mp_for(self):
wactbprot's avatar
wactbprot committed
        """
        usage:

        > python anselm provide_excahnge_for calid
        
        """
wactbprot's avatar
wactbprot committed
        parser = argparse.ArgumentParser(
wactbprot's avatar
wactbprot committed
            description="builds the api for the mp given by id")
wactbprot's avatar
wactbprot committed

wactbprot's avatar
wactbprot committed
        parser.add_argument('id')
wactbprot's avatar
wactbprot committed
        arg = parser.parse_args(sys.argv[2:3])

wactbprot's avatar
wactbprot committed
        if len(arg.id) < self.max_arg_len:
            self.ltm_pub(body_dict={
                        'do':'get_auxobj',
                        'payload':{"id": arg.id}
wactbprot's avatar
wactbprot committed
                        })
wactbprot's avatar
wactbprot committed

wactbprot's avatar
ok  
wactbprot committed
        self.ctrl_conn.close()
wactbprot's avatar
wactbprot committed

    def read_exchange(self):
wactbprot's avatar
wactbprot committed
       
        self.stm_pub(body_dict={
wactbprot's avatar
wactbprot committed
                        'do':'read_exchange',
                        'payload':{"id":"mpd-ce3-calib", "find_set":{"StartTime.Type":"start"}}
                        })
wactbprot's avatar
wactbprot committed

        self.stm_conn.close()
wactbprot's avatar
wactbprot committed

if __name__ == '__main__':
    Anselm()