#!/usr/bin/env python

import sys
import argparse
import socket
from webserver import server
from base import Client
from influxgraph import InfluxGraph
from secop import SecopInteractor
from sehistory.seinflux import SEHistory


def parseArgv(argv):
    parser = argparse.ArgumentParser(
        description="start a webserver for history and interaction",
    )
    # loggroup = parser.add_mutually_exclusive_group()
    # loggroup.add_argument("-v", "--verbose",
    #                       help="Output lots of diagnostic information",
    #                       action='store_true', default=False)
    # loggroup.add_argument("-q", "--quiet", help="suppress non-error messages",
    #                       action='store_true', default=False)
    parser.add_argument("port",
                        type=str,
                        help="port number to serve\n")
    # parser.add_argument('-d',
    #                     '--daemonize',
    #                     action='store_true',
    #                     help='Run as daemon',
    #                     default=False)
    parser.add_argument('-i',
                        '--instrument',
                        action='store',
                        help="instrument, if running on an instrument computer\n"
                        "if the value is HOST, take the host name as instrument name",
                        default=None)
    return parser.parse_args(argv)

args = parseArgv(sys.argv[1:])

instrument = socket.gethostname().split('.')[0] if args.instrument == 'HOST' else args.instrument

server.run(int(args.port), SEHistory(), InfluxGraph, Client, single_instrument=instrument, secop=SecopInteractor)
