Ejemplo n.º 1
0
def main():
    try:
        argv = patch_argv(sys.argv)
        args = cmd_parser.parse_cmds(argv)
        cmd_processor.process_cmds(args)
    except Exception as ex:
        print ex
        traceback.print_exc()
        sys.exit(1)
    print '[alauda] OK'
Ejemplo n.º 2
0
def main():
    try:
        argv = patch_argv(sys.argv)
        args = cmd_parser.parse_cmds(argv)
        cmd_processor.process_cmds(args)
    except Exception as ex:
        print ex
        traceback.print_exc()
        sys.exit(1)
    print '[alauda] OK'
Ejemplo n.º 3
0
def main():
    try:
        argv = patch_argv(sys.argv)
        args = cmd_parser.parse_cmds(argv)
        cmd_processor.process_cmds(args)
    except AlaudaInputError as ex:
        print ex
        sys.exit(1)
    except AlaudaServerError as ex:
        print ex
        sys.exit(1)
    print '[alauda] OK'
Ejemplo n.º 4
0
def main():
    # parse arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('-c', '--cmds', help='commandlist filename')
    parser.add_argument('-d', '--delay', help='delay between commands [s]')
    parser.add_argument("-l",
                        help='start in live modus',
                        action="store_true",
                        default=False)
    args = parser.parse_args()

    if args.l == False:
        global cmd_delay
        try:
            commandlist = cmd_parser.parse_cmds(args.cmds)
            print commandlist, cmd_delay
        except ValueError as e:
            print e
        except IOError as e:
            print "I/O error({0}): {1}".format(e.errno,
                                               e.strerror) + ":", args.cmds

        if args.delay != None:
            cmd_delay = args.delay

        try:
            i2ctool = I2C.I2CTool()
            pool = ThreadPool(processes=1)

            for command in commandlist:
                if command.isif:
                    res = execute_command(pool, i2ctool, command)
                    if res == config.I2C_TRUE:
                        execute_command(
                            pool, i2ctool,
                            cmd_parser.parse_cmd(command.getThen()))
                    elif res == config.I2C_FALSE:
                        execute_command(
                            pool, i2ctool,
                            cmd_parser.parse_cmd(command.getElse()))
                else:
                    res = execute_command(pool, i2ctool, command)

                if res == config.I2C_ERR:
                    print "ERROR: command", command
                    print "exit programm"
                    break
        finally:
            exit_program()

    else:
        print "To exit enter 'quit'"
        i2ctool = I2C.I2CTool()
        pool = ThreadPool(processes=1)

        while True:
            try:
                print "Enter command: ",
                line = sys.stdin.readline()
                if line.startswith("quit"):
                    exit_program()
                command = cmd_parser.parse_cmd(line)
                if command.isif:
                    res = execute_command(pool, i2ctool, command)
                    if res == config.I2C_TRUE:
                        execute_command(
                            pool, i2ctool,
                            cmd_parser.parse_cmd(command.getThen()))
                    elif res == config.I2C_FALSE:
                        execute_command(
                            pool, i2ctool,
                            cmd_parser.parse_cmd(command.getElse()))
                else:
                    execute_command(pool, i2ctool, command)
            except ValueError as e:
                print e