Example #1
0
def interactive_TStat(TStat):
    """ function provides interactive dialog
    """
    # methods supported
    # keys = ['set', 'get', 'esc']

    key_dict = []
    while True:
        key_input = raw_input("\n\ninteractive mode, enter method and parameter ('esc' to exit): ")
        key_input.strip("\t\n\r")
        if " " in key_input:
            key_dict = key_input.split(" ")
        else:
            key_dict.append(key_input)
        if len(key_dict) >= 1:
            method = key_dict[0]
        if len(key_dict) >= 2:
            param = key_dict[1]
        if len(key_dict) >= 3:
            valu = key_dict[2]

        if method == "get":
            if len(key_dict) != 2:
                print "\nparse error in string '%s', 'get' method requires 1 parameter, exiting..." % key_input
                sys.exit(-1)
            print "\nparam '%s' returns: %s" % (param, TStat._get(param))
        if method == "set":
            if len(key_dict) != 3:
                print "\nparse error in string '%s', 'set' method requires 2 parameters, exiting..." % key_input
                sys.exit(-1)
            print "\nparam '%s' was set to: %s, changing to: %s" % (param, TStat._get(param), valu)
            TStat._post(param, valu)
            print "\nparam '%s' returns: %s" % (param, TStat._get(param))
        elif method == "esc":
            print "\nescape sequence detected, exiting interactive mode..."
            sys.exit(0)