Ejemplo n.º 1
0
def test_zmq_task():
    """
    CommandLine:
        python -m ibeis.web.zmq_task_queue --exec-test_zmq_task
        python -b -m ibeis.web.zmq_task_queue --exec-test_zmq_task

        python -m ibeis.web.zmq_task_queue --main
        python -m ibeis.web.zmq_task_queue --main --bg
        python -m ibeis.web.zmq_task_queue --main --fg

    Example:
        >>> # SCRIPT
        >>> from ibeis.web.zmq_task_queue import *  # NOQA
        >>> test_zmq_task()
    """
    _init_signals()
    # now start a few clients, and fire off some requests
    client_id = np.random.randint(1000)
    jobiface = JobInterface(client_id)
    reciever = JobBackend()
    if ut.get_argflag('--bg'):
        from ibeis.init import sysres
        dbdir = sysres.get_args_dbdir('cache', False, None, None,
                                      cache_priority=False)
        reciever.initialize_background_processes(dbdir)
        print('[testzmq] parent process is looping forever')
        while True:
            time.sleep(1)
    elif ut.get_argflag('--fg'):
        jobiface.initialize_client_thread()
    else:
        dbdir = sysres.get_args_dbdir('cache', False, None, None,
                                      cache_priority=False)
        reciever.initialize_background_processes(dbdir)
        jobiface.initialize_client_thread()

    # Foreground test script
    print('... waiting for jobs')
    if ut.get_argflag('--cmd'):
        ut.embed()
        jobiface.queue_job()
    else:
        print('[test] ... emit test1')
        jobid1 = jobiface.queue_job('helloworld', 1)
        jobiface.wait_for_job_result(jobid1)
        #jobiface.get_job_status(jobid1)
        #jobid_list = [jobiface.queue_job('helloworld', 5) for _ in range(NUM_JOBS)]
        #jobid_list += [jobiface.queue_job('get_valid_aids')]
        jobid_list = []

        #identify_jobid = jobiface.queue_job('query_chips', [1], [3, 4, 5], cfgdict={'K': 1})
        identify_jobid = jobiface.queue_job('query_chips_simple_dict', [1], [3, 4, 5], cfgdict={'K': 1})

        for jobid in jobid_list:
            jobiface.wait_for_job_result(jobid)

        jobiface.wait_for_job_result(identify_jobid)
    print('FINISHED TEST SCRIPT')
Ejemplo n.º 2
0
def test_main(gui=True, dbdir=None, defaultdb='cache', allow_newdir=False,
              db=None):
    """ alias for main() """  # + main.__doc__
    from ibeis.init import sysres
    _preload()
    dbdir = sysres.get_args_dbdir(defaultdb, allow_newdir, db, dbdir, cache_priority=False)
    ibs = _init_ibeis(dbdir)
    return ibs
Ejemplo n.º 3
0
def opendb_test(gui=True,
                dbdir=None,
                defaultdb='cache',
                allow_newdir=False,
                db=None):
    """ alias for main() """  # + main.__doc__
    from ibeis.init import sysres
    _preload()
    dbdir = sysres.get_args_dbdir(defaultdb=defaultdb,
                                  allow_newdir=allow_newdir,
                                  db=db,
                                  dbdir=dbdir)
    ibs = _init_ibeis(dbdir)
    return ibs
Ejemplo n.º 4
0
def opendb(db=None, dbdir=None, defaultdb='cache', allow_newdir=False,
           delete_ibsdir=False, verbose=False, use_cache=True,
           web=None, **kwargs):
    """
    main without the preload (except for option to delete database before
    opening)

    Args:
        db (str):  database name in your workdir used only if dbdir is None
        dbdir (None): full database path
        defaultdb (str): dbdir search stratagy when db is None and dbdir is
            None
        allow_newdir (bool): (default=True) if True errors when opening a
            nonexisting database
        delete_ibsdir (bool): BE CAREFUL! (default=False) if True deletes the
            entire
        verbose (bool): verbosity flag
        web (bool): starts webserver if True (default=param specification)
        use_cache (bool): if True will try to return a previously loaded
            controller

    Returns:
        ibeis.IBEISController: ibs

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.main_module import *  # NOQA
        >>> db = None
        >>> dbdir = None
        >>> defaultdb = 'cache'
        >>> allow_newdir = False
        >>> delete_ibsdir = False
        >>> verbose = False
        >>> use_cache = True
        >>> ibs = opendb(db, dbdir, defaultdb, allow_newdir, delete_ibsdir,
        >>>              verbose, use_cache)
        >>> result = str(ibs)
        >>> print(result)
    """
    from ibeis.init import sysres
    from ibeis.other import ibsfuncs
    dbdir = sysres.get_args_dbdir(defaultdb, allow_newdir, db, dbdir,
                                  cache_priority=False)
    if delete_ibsdir is True:
        assert allow_newdir, (
            'must be making new directory if you are deleting everything!')
        ibsfuncs.delete_ibeis_database(dbdir)
    ibs = _init_ibeis(dbdir, verbose=verbose, use_cache=use_cache, web=web,
                      **kwargs)
    return ibs
Ejemplo n.º 5
0
def main(gui=True, dbdir=None, defaultdb='cache',
         allow_newdir=False, db=None,
         delete_ibsdir=False,
         **kwargs):
    """
    Program entry point
    Inits the system environment, an IBEISControl, and a GUI if requested

    Args:
        gui (bool): (default=True) If gui is False a gui instance will not be created
        dbdir (None): full directory of a database to load
        db (None): name of database to load relative to the workdir
        allow_newdir (bool): (default=False) if False an error is raised if a
            a new database is created
        defaultdb (str): codename of database to load if db and dbdir is None. a value
            of 'cache' will open the last database opened with the GUI.

    Returns:
        dict: main_locals
    """
    set_newfile_permissions()
    from ibeis.init import main_commands
    from ibeis.init import sysres
    # Display a visible intro message
    msg1 = '''
    _____ ....... _______ _____ _______
      |   |_____| |______   |   |______
    ..|.. |.....| |______s__|__ ______|
    '''
    msg2 = '''
    _____ ______  _______ _____ _______
      |   |_____] |______   |   |______
    __|__ |_____] |______ __|__ ______|
    '''
    if NOT_QUIET:
        print(msg2 if '--myway' not in sys.argv else msg1)
    # Init the only two main system api handles
    ibs = None
    back = None
    if NOT_QUIET:
        print('[main] ibeis.main_module.main()')
    _preload()
    DIAGNOSTICS = NOT_QUIET
    if DIAGNOSTICS:
        import os
        import utool as ut
        import ibeis
        print('[main] MAIN DIAGNOSTICS')
        print('[main]  * username = %r' % (ut.get_user_name()))
        print('[main]  * ibeis.__version__ = %r' % (ibeis.__version__,))
        print('[main]  * computername = %r' % (ut.get_computer_name()))
        print('[main]  * cwd = %r' % (os.getcwd(),))
        print('[main]  * sys.argv = %r' % (sys.argv,))
    # Parse directory to be loaded from command line args
    # and explicit kwargs
    dbdir = sysres.get_args_dbdir(defaultdb, allow_newdir, db, dbdir, cache_priority=False)
    if delete_ibsdir is True:
        from ibeis.other import ibsfuncs
        assert allow_newdir, 'must be making new directory if you are deleting everything!'
        ibsfuncs.delete_ibeis_database(dbdir)
    # Execute preload commands
    main_commands.preload_commands(dbdir, **kwargs)  # PRELOAD CMDS
    try:
        # Build IBEIS Control object
        ibs = _init_ibeis(dbdir)
        if gui and USE_GUI:
            back = _init_gui(activate=kwargs.get('activate', True))
            back.connect_ibeis_control(ibs)
    except Exception as ex:
        print('[main()] IBEIS LOAD imageseted exception: %s %s' % (type(ex), ex))
        raise
    main_commands.postload_commands(ibs, back)  # POSTLOAD CMDS
    main_locals = {'ibs': ibs, 'back': back}
    return main_locals
Ejemplo n.º 6
0
def opendb(db=None,
           dbdir=None,
           defaultdb='cache',
           allow_newdir=False,
           delete_ibsdir=False,
           verbose=False,
           use_cache=True,
           web=None,
           **kwargs):
    """
    main without the preload (except for option to delete database before
    opening)

    Args:
        db (str):  database name in your workdir used only if dbdir is None
        dbdir (None): full database path
        defaultdb (str): dbdir search stratagy when db is None and dbdir is
            None
        allow_newdir (bool): (default=True) if True errors when opening a
            nonexisting database
        delete_ibsdir (bool): BE CAREFUL! (default=False) if True deletes the
            entire
        verbose (bool): verbosity flag
        web (bool): starts webserver if True (default=param specification)
        use_cache (bool): if True will try to return a previously loaded
            controller

    Returns:
        ibeis.IBEISController: ibs

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.main_module import *  # NOQA
        >>> db = None
        >>> dbdir = None
        >>> defaultdb = 'cache'
        >>> allow_newdir = False
        >>> delete_ibsdir = False
        >>> verbose = False
        >>> use_cache = True
        >>> ibs = opendb(db, dbdir, defaultdb, allow_newdir, delete_ibsdir,
        >>>              verbose, use_cache)
        >>> result = str(ibs)
        >>> print(result)
    """
    from ibeis.init import sysres
    from ibeis.other import ibsfuncs
    dbdir = sysres.get_args_dbdir(defaultdb,
                                  allow_newdir,
                                  db,
                                  dbdir,
                                  cache_priority=False)
    if delete_ibsdir is True:
        assert allow_newdir, (
            'must be making new directory if you are deleting everything!')
        ibsfuncs.delete_ibeis_database(dbdir)
    ibs = _init_ibeis(dbdir,
                      verbose=verbose,
                      use_cache=use_cache,
                      web=web,
                      **kwargs)
    return ibs
Ejemplo n.º 7
0
def main(gui=True,
         dbdir=None,
         defaultdb='cache',
         allow_newdir=False,
         db=None,
         delete_ibsdir=False,
         **kwargs):
    """
    Program entry point
    Inits the system environment, an IBEISControl, and a GUI if requested

    Args:
        gui (bool): (default=True) If gui is False a gui instance will not be created
        dbdir (None): full directory of a database to load
        db (None): name of database to load relative to the workdir
        allow_newdir (bool): (default=False) if False an error is raised if a
            a new database is created
        defaultdb (str): codename of database to load if db and dbdir is None. a value
            of 'cache' will open the last database opened with the GUI.

    Returns:
        dict: main_locals
    """
    set_newfile_permissions()
    from ibeis.init import main_commands
    from ibeis.init import sysres
    # Display a visible intro message
    msg1 = '''
    _____ ....... _______ _____ _______
      |   |_____| |______   |   |______
    ..|.. |.....| |______s__|__ ______|
    '''
    msg2 = '''
    _____ ______  _______ _____ _______
      |   |_____] |______   |   |______
    __|__ |_____] |______ __|__ ______|
    '''
    if NOT_QUIET:
        print(msg2 if '--myway' not in sys.argv else msg1)
    # Init the only two main system api handles
    ibs = None
    back = None
    if NOT_QUIET:
        print('[main] ibeis.main_module.main()')
    _preload()
    DIAGNOSTICS = NOT_QUIET
    if DIAGNOSTICS:
        import os
        import utool as ut
        import ibeis
        print('[main] MAIN DIAGNOSTICS')
        print('[main]  * username = %r' % (ut.get_user_name()))
        print('[main]  * ibeis.__version__ = %r' % (ibeis.__version__, ))
        print('[main]  * computername = %r' % (ut.get_computer_name()))
        print('[main]  * cwd = %r' % (os.getcwd(), ))
        print('[main]  * sys.argv = %r' % (sys.argv, ))
    # Parse directory to be loaded from command line args
    # and explicit kwargs
    dbdir = sysres.get_args_dbdir(defaultdb,
                                  allow_newdir,
                                  db,
                                  dbdir,
                                  cache_priority=False)
    if delete_ibsdir is True:
        from ibeis.other import ibsfuncs
        assert allow_newdir, 'must be making new directory if you are deleting everything!'
        ibsfuncs.delete_ibeis_database(dbdir)
    # Execute preload commands
    main_commands.preload_commands(dbdir, **kwargs)  # PRELOAD CMDS
    try:
        # Build IBEIS Control object
        ibs = _init_ibeis(dbdir)
        if gui and USE_GUI:
            back = _init_gui(activate=kwargs.get('activate', True))
            back.connect_ibeis_control(ibs)
    except Exception as ex:
        print('[main()] IBEIS LOAD imageseted exception: %s %s' %
              (type(ex), ex))
        raise
    main_commands.postload_commands(ibs, back)  # POSTLOAD CMDS
    main_locals = {'ibs': ibs, 'back': back}
    return main_locals
Ejemplo n.º 8
0
def job_engine_tester():
    """
    CommandLine:
        python -m ibeis.web.job_engine --exec-job_engine_tester
        python -b -m ibeis.web.job_engine --exec-job_engine_tester

        python -m ibeis.web.job_engine job_engine_tester
        python -m ibeis.web.job_engine job_engine_tester --bg
        python -m ibeis.web.job_engine job_engine_tester --fg

    Example:
        >>> # SCRIPT
        >>> from ibeis.web.job_engine import *  # NOQA
        >>> job_engine_tester()
    """
    _init_signals()
    # now start a few clients, and fire off some requests
    client_id = np.random.randint(1000)
    reciever = JobBackend(use_static_ports=True)
    jobiface = JobInterface(client_id, reciever.port_dict)
    from ibeis.init import sysres
    if ut.get_argflag('--bg'):
        dbdir = sysres.get_args_dbdir(defaultdb='cache',
                                      allow_newdir=False,
                                      db=None,
                                      dbdir=None)
        reciever.initialize_background_processes(dbdir)
        print('[testzmq] parent process is looping forever')
        while True:
            time.sleep(1)
    elif ut.get_argflag('--fg'):
        jobiface.initialize_client_thread()
    else:
        dbdir = sysres.get_args_dbdir(defaultdb='cache',
                                      allow_newdir=False,
                                      db=None,
                                      dbdir=None)
        reciever.initialize_background_processes(dbdir)
        jobiface.initialize_client_thread()

    # Foreground test script
    print('... waiting for jobs')
    if ut.get_argflag('--cmd'):
        ut.embed()
        #jobiface.queue_job()
    else:
        print('[test] ... emit test1')
        callback_url = None
        callback_method = None
        args = (1, )
        jobid1 = jobiface.queue_job('helloworld', callback_url,
                                    callback_method, *args)
        jobiface.wait_for_job_result(jobid1)
        jobid_list = []

        args = ([1], [3, 4, 5])
        kwargs = dict(cfgdict={'K': 1})
        identify_jobid = jobiface.queue_job('query_chips_simple_dict',
                                            callback_url, callback_method,
                                            *args, **kwargs)
        for jobid in jobid_list:
            jobiface.wait_for_job_result(jobid)

        jobiface.wait_for_job_result(identify_jobid)
    print('FINISHED TEST SCRIPT')
Ejemplo n.º 9
0
def test_job_engine():
    """
    CommandLine:
        python -m ibeis.web.job_engine --exec-test_job_engine
        python -b -m ibeis.web.job_engine --exec-test_job_engine

        python -m ibeis.web.job_engine test_job_engine
        python -m ibeis.web.job_engine test_job_engine --bg
        python -m ibeis.web.job_engine test_job_engine --fg

    Example:
        >>> # SCRIPT
        >>> from ibeis.web.job_engine import *  # NOQA
        >>> test_job_engine()
    """
    _init_signals()
    # now start a few clients, and fire off some requests
    client_id = np.random.randint(1000)
    jobiface = JobInterface(client_id)
    reciever = JobBackend()
    from ibeis.init import sysres
    if ut.get_argflag('--bg'):
        dbdir = sysres.get_args_dbdir('cache', False, None, None,
                                      cache_priority=False)
        reciever.initialize_background_processes(dbdir)
        print('[testzmq] parent process is looping forever')
        while True:
            time.sleep(1)
    elif ut.get_argflag('--fg'):
        jobiface.initialize_client_thread()
    else:
        dbdir = sysres.get_args_dbdir('cache', False, None, None,
                                      cache_priority=False)
        reciever.initialize_background_processes(dbdir)
        jobiface.initialize_client_thread()

    # Foreground test script
    print('... waiting for jobs')
    if ut.get_argflag('--cmd'):
        ut.embed()
        #jobiface.queue_job()
    else:
        print('[test] ... emit test1')
        callback_url = None
        callback_method = None
        args = (1,)
        jobid1 = jobiface.queue_job('helloworld', callback_url,
                                    callback_method, *args)
        jobiface.wait_for_job_result(jobid1)
        jobid_list = []

        args = ([1], [3, 4, 5])
        kwargs = dict(cfgdict={'K': 1})
        identify_jobid = jobiface.queue_job('query_chips_simple_dict',
                                            callback_url, callback_method,
                                            *args, **kwargs)
        for jobid in jobid_list:
            jobiface.wait_for_job_result(jobid)

        jobiface.wait_for_job_result(identify_jobid)
    print('FINISHED TEST SCRIPT')