Exemple #1
0
def init_configurator(CONFIG_LOCATION=CONFIG_LOCATION):
    """ Register local computer if not done previously.
    :return: The configurator for this local computer
    """
    if os.path.isfile(CONFIG_LOCATION):
        configurator = Configurator(filename=CONFIG_LOCATION)
        print "Found local configurator at {}".format(CONFIG_LOCATION)
    else:
        configurator = Configurator()
        configurator.write_config(CONFIG_LOCATION)

        data_connection = DataConnection(configurator)
        my_reg_token = str(uuid4())
        print "Registering to {} with token {}".format(
            configurator.get_config()['server'], my_reg_token)
        data_connection.register(my_reg_token, CONFIG_LOCATION)
        configurator.write_config(CONFIG_LOCATION)

    return configurator
Exemple #2
0
        program = self.data_connection.get_program(
            program_command['program_id'])

        self.worker_pool.stop_program(program['id'])


if __name__ == '__main__':
    """
    Main loop.  Handle commands until done.
    """
    if len(sys.argv) != 2:
        print "usage: python base <config file>"
        sys.exit()

    configurator = init_configurator(sys.argv[1])
    data_connection = DataConnection(configurator)
    data_connection.update_config(CONFIG_LOCATION)
    worker_pool = WorkerPool(data_connection)
    command_handler = CommandHandler(worker_pool, data_connection)

    done = False
    data_connection.set_local_computer_status(is_running=True)
    print "Connected to " + configurator.get_config()['server']
    print "Polling for commands.  <ctrl-c> to exit."
    while not done:
        try:
            commands = data_connection.get_new_commands()
            done = command_handler.handle_commands(commands)
            time.sleep(configurator.get_config()['command_refresh_sec'])
        except KeyboardInterrupt:
            print "Stopping"