def main():
    """
    main processing module
    """
    options = parse_command_line()
    initialize_logging(options.log_name)
    log = logging.getLogger("main")
    log.info("program starts")

    halt_event = Event()
    gevent.signal(signal.SIGTERM, _handle_sigterm, halt_event)

    log.info("loading test script from %r" % (options.test_script,))
    with open(options.test_script, "rt") as input_file:
        test_script = json.load(input_file)

    log.info("loading user identity files from %r" % (options.user_identity_dir,))
    customer_list = list()
    for file_name in os.listdir(options.user_identity_dir):
        if not ("motoboto" in file_name and "benchmark" in file_name):
            continue
        if options.max_users is not None and len(customer_list) >= options.max_users:
            log.info("breaking at %s users" % (options.max_users,))
            break

        log.info("loading %r" % (file_name,))
        user_identity = load_identity_from_file(os.path.join(options.user_identity_dir, file_name))
        customer = GreenletCustomer(halt_event, user_identity, test_script)
        customer.link_exception(_unhandled_greenlet_exception)
        customer.start_later(random.uniform(0.0, 15.0))
        customer_list.append(customer)

    log.info("waiting")
    try:
        halt_event.wait(options.test_duration)
    except KeyboardInterrupt:
        log.info("KeyBoardInterrupt")

    if test_script.get("audit-after", False):
        print >>sys.stderr, "run redis_stats_collector, press return when done"
        raw_input("waiting...")

    log.info("setting halt event")
    halt_event.set()

    total_error_count = 0
    log.info("joining")
    for customer in customer_list:
        customer.join()
        total_error_count += customer.error_count

    log.info(
        "program ends {0} total errors, {1} unhandled exceptions".format(total_error_count, _unhandled_exception_count)
    )
    return 0
Esempio n. 2
0
def main():
    info_yellow("BERNAISE: Unit-conversion tool")
    cmd_kwargs = parse_command_line()

    # Get help if it was called for.
    if cmd_kwargs.get("help", False):
        get_help()

    folder = cmd_kwargs.get("folder", False)

    LoadSettings(folder)
Esempio n. 3
0
def main():
    cmd_kwargs = parse_command_line()

    method = cmd_kwargs.get("mesh", "straight_capilar")

    scripts_folder = "mesh_scripts"

    methods = get_methods(scripts_folder)

    # Get help if it was called for.
    if cmd_kwargs.get("help", False):
        get_help(methods, scripts_folder, __file__)

    call_method(method, methods, scripts_folder, cmd_kwargs)
Esempio n. 4
0
def main():
    cmd_kwargs = parse_command_line()

    image_path = cmd_kwargs.get("image", False)
    show = cmd_kwargs.get("show", False)

    name = os.path.splitext(os.path.basename(image_path))[0]
    info("Image name: {}".format(name))

    if not image_path or not os.path.exists(image_path):
        info_on_red("Image does not exist.")
        exit()

    image = misc.imread(image_path)
    image = np.array(np.array(np.mean(image[:, :, :3], 2), dtype=int) / 255,
                     dtype=float)

    contours = measure.find_contours(image, 0.5)

    nodes = contours[0][::10, 1::-1]
    nodes /= np.max(nodes)
    nodes[:, 1] = -nodes[:, 1]

    nodes_max = np.max(nodes, 0)
    nodes_min = np.min(nodes, 0)
    nodes[:, 1] -= nodes_min[1]
    nodes[:, 0] -= nodes_min[0]

    edges = round_trip_connect(0, len(nodes) - 1)

    savefile_prefix = os.path.join(MESHES_DIR, name)
    np.savetxt(savefile_prefix + ".nodes", nodes)
    np.savetxt(savefile_prefix + ".edges", edges, fmt='%i')

    if show:
        plot_edges(nodes, edges)
def main():
    """
    main processing module
    """
    options = parse_command_line()
    initialize_logging(options.log_name)
    log = logging.getLogger("main")
    log.info("program starts")

    halt_event = Event()
    signal.signal(signal.SIGTERM, _create_signal_handler(halt_event))

    log.info("using test script %r" % (options.test_script, ))

    program_dir = os.path.dirname(__file__)
    program_path = os.path.join(program_dir, "customer_process.py")

    customer_process_list = list()
    for file_name in os.listdir(options.user_identity_dir):
        if options.max_users is not None \
        and len(customer_process_list) >= options.max_users:
            log.info("breaking at %s users" % (options.max_users, ))
            break

        log.info("user identity %r" % (file_name, ))
        user_identity_path = os.path.join(options.user_identity_dir, file_name)

        args = [
            sys.executable,
            program_path,
            options.test_script,
            user_identity_path
        ]

        environment = {
            "PYTHONPATH"                : os.environ["PYTHONPATH"],
            "NIMBUSIO_LOG_DIR"          : os.environ["NIMBUSIO_LOG_DIR"],
            "NIMBUS_IO_SERVICE_HOST"    : os.environ["NIMBUS_IO_SERVICE_HOST"], 
            "NIMBUS_IO_SERVICE_PORT"    : os.environ["NIMBUS_IO_SERVICE_PORT"], 
            "NIMBUS_IO_SERVICE_DOMAIN"  : \
                os.environ["NIMBUS_IO_SERVICE_DOMAIN"], 
            "NIMBUS_IO_SERVICE_SSL"     : os.environ.get(
                "NIMBUS_IO_SERVICE_SSL", "0"
            )
        }        

        process = subprocess.Popen(args, env=environment)
        customer_process_list.append(process)

    log.info("waiting")
    try:
        halt_event.wait(options.test_duration)
    except KeyboardInterrupt:
        log.info("KeyBoardInterrupt")
        halt_event.set()
    
    log.info("terminating processes")
    for process in customer_process_list:
        process.terminate()

    log.info("waiting for processes")
    for process in customer_process_list:
        process.wait()
        if process.returncode != 0:
            log.error("process returncode %s" % (process.returncode, ))
    
    log.info("program ends")
    return 0
Esempio n. 6
0
def main():
    """
    main processing module
    """
    options = parse_command_line()
    initialize_logging(options.log_name)
    log = logging.getLogger("main")
    log.info("program starts")

    halt_event = Event()
    signal.signal(signal.SIGTERM, _create_signal_handler(halt_event))

    log.info("using test script %r" % (options.test_script, ))

    program_dir = os.path.dirname(__file__)
    program_path = os.path.join(program_dir, "customer_process.py")

    customer_process_list = list()
    for file_name in os.listdir(options.user_identity_dir):
        if options.max_users is not None \
        and len(customer_process_list) >= options.max_users:
            log.info("breaking at %s users" % (options.max_users, ))
            break

        log.info("user identity %r" % (file_name, ))
        user_identity_path = os.path.join(options.user_identity_dir, file_name)

        args = [
            sys.executable, program_path, options.test_script,
            user_identity_path
        ]

        environment = {
            "PYTHONPATH"                : os.environ["PYTHONPATH"],
            "NIMBUSIO_LOG_DIR"          : os.environ["NIMBUSIO_LOG_DIR"],
            "NIMBUS_IO_SERVICE_HOST"    : os.environ["NIMBUS_IO_SERVICE_HOST"],
            "NIMBUS_IO_SERVICE_PORT"    : os.environ["NIMBUS_IO_SERVICE_PORT"],
            "NIMBUS_IO_SERVICE_DOMAIN"  : \
                os.environ["NIMBUS_IO_SERVICE_DOMAIN"],
            "NIMBUS_IO_SERVICE_SSL"     : os.environ.get(
                "NIMBUS_IO_SERVICE_SSL", "0"
            )
        }

        process = subprocess.Popen(args, env=environment)
        customer_process_list.append(process)

    log.info("waiting")
    try:
        halt_event.wait(options.test_duration)
    except KeyboardInterrupt:
        log.info("KeyBoardInterrupt")
        halt_event.set()

    log.info("terminating processes")
    for process in customer_process_list:
        process.terminate()

    log.info("waiting for processes")
    for process in customer_process_list:
        process.wait()
        if process.returncode != 0:
            log.error("process returncode %s" % (process.returncode, ))

    log.info("program ends")
    return 0