Skip to content
Snippets Groups Projects
CommandLineInterface.py 3.59 KiB
Newer Older
BRONES Romain's avatar
BRONES Romain committed
#!/usr/bin/env python
###################################################################################################
#   COMMAND LINE INTERFACE
###################################################################################################
#
# This file gives the Command Line Interface for FofbTool
#
###################################################################################################

if __name__ == '__main__':
    import logging
    import argparse
    import os
    import sys

    # Safer import: add the parent dir in path
    sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
    import FofbTool.Utils
BRONES Romain's avatar
BRONES Romain committed
    import FofbTool.Configuration
BRONES Romain's avatar
BRONES Romain committed

    # Get the module logger
    logger = logging.getLogger("FofbTool")

    # Add a Stream handler to the module logger
    sh=logging.StreamHandler()
    sh.setLevel(logging.DEBUG)
    sh.setFormatter(logging.Formatter("{levelname:8}: {message}", style='{'))
    logger.addHandler(sh)

    parser = argparse.ArgumentParser("FofbTool")
    parser.add_argument("--log", default="info",
            help="Log level (error, warning, info, debug)")
BRONES Romain's avatar
BRONES Romain committed

    parser.add_argument("--DS-init-opcua", action="store_true",
            help="Run init on opcua devices.")
BRONES Romain's avatar
BRONES Romain committed
    parser.add_argument("--DS-init-watcher", action="store_true",
            help="Run init on the Fofb-Watcher device, and then the Fofb-Command.")
BRONES Romain's avatar
BRONES Romain committed
    parser.add_argument("--DS-conf", action="store_true",
            help="Applying attribute configuration on Tango Device Servers. This is required after restart of devices.")
BRONES Romain's avatar
BRONES Romain committed

    parser.add_argument("--configure", choices=["combpm", "ccn", "comcorr", "corr", "all", "every"], nargs="+",
            help="Configuration commands for the Fofb applications blocs."+
            " 'all' is for all com, not configuring corrector. 'every' configure everything.")
BRONES Romain's avatar
BRONES Romain committed

    args = parser.parse_args()

    # Set log level from args
    logger.setLevel(getattr(logging, args.log.upper()))

    logger.debug(args)

BRONES Romain's avatar
BRONES Romain committed
    ## Device Server related commands
    if args.DS_init_opcua:
        FofbTool.Utils.init_opcua()

BRONES Romain's avatar
BRONES Romain committed
    if args.DS_init_watcher:
        FofbTool.Utils.init_watcher()
BRONES Romain's avatar
BRONES Romain committed
    if args.DS_conf:
        FofbTool.Utils.confds_opcua()
BRONES Romain's avatar
BRONES Romain committed
    for conf in args.configure:
        if conf in ("combpm", "all", "every"):
            FofbTool.Utils.conf_all_combpm()
        if conf in ("comcorr", "all", "every"):
            FofbTool.Utils.conf_all_comcorr()
        if conf in ("ccn", "all", "every"):
            FofbTool.Utils.conf_all_ccn()
        if conf in ("corr", "every"):
            FofbTool.Configuration.centralnode_configure_corr()

    exit(0)

BRONES Romain's avatar
BRONES Romain committed
    if args.stop:
        for cnp in cellnode_subscribers:
            cellnode_stop_ccn(cnp)
            cellnode_stop_combpm(cnp)
        centralnode_stop_ccn(centralnode_subscriber)

    if not args.respmat is None:
        centralnode_configure_respmat(centralnode_subscriber, args.respmat)



    if args.conf:
        for cnp in cellnode_subscribers:
            cellnode_configure_combpm(cnp)
            cellnode_configure_comcorr(cnp, not args.disable_corr)
            time.sleep(2)
            cellnode_configure_ccn(cnp)
        centralnode_configure_ccn(centralnode_subscriber)
        centralnode_configure_corr(centralnode_subscriber)
    elif args.disable_corr:
        for cnp in cellnode_subscribers:
            cellnode_configure_comcorr(cnp, not args.disable_corr)

    if args.start:
        for cnp in cellnode_subscribers:
            cellnode_start_ccn(cnp)
            cellnode_start_combpm(cnp)
            cellnode_ack_ccn(cnp)
        centralnode_start_ccn(centralnode_subscriber)