Example #1
0
def get_unconverted_hsdbs(workdir=None):
    r"""
    Args:
        workdir (None): (default = None)

    CommandLine:
        python -m wbia.dbio.ingest_hsdb --test-get_unconverted_hsdbs

    Example:
        >>> # SCRIPT
        >>> from wbia.dbio.ingest_hsdb import *  # NOQA
        >>> workdir = None
        >>> result = get_unconverted_hsdbs(workdir)
        >>> print(result)
    """
    import os
    import numpy as np

    if workdir is None:
        workdir = sysres.get_workdir()
    dbname_list = os.listdir(workdir)
    dbpath_list = np.array([join(workdir, name) for name in dbname_list])
    needs_convert = list(map(check_unconverted_hsdb, dbpath_list))
    needs_convert_hsdbs = ut.compress(dbpath_list, needs_convert)
    return needs_convert_hsdbs
Example #2
0
def set_up_db(request):
    """
    Sets up the testing databases.
    This fixture is set to run automatically any any test run of wbia.

    """
    # If selected, disable running the main logic of this fixture
    if request.config.getoption('--disable-refresh-db', False):
        # Assume the user knows what they are requesting
        return  # bale out

    # Delete DBs, if they exist
    # FIXME (16-Jul-12020) this fixture does not cleanup after itself to preserve exiting usage behavior
    for dbname in TEST_DBNAMES:
        delete_dbdir(dbname)

    # Set up DBs
    ingest_database.ingest_standard_database('testdb1')
    ensure_pz_mtest()
    ensure_nauts()
    ensure_wilddogs()
    ensure_testdb2()

    # Set testdb1 as the main database
    workdir = Path(get_workdir())
    default_db_dir = workdir / 'testdb1'
    # FIXME (16-Jul-12020) Set this only for the test session
    set_default_dbdir(default_db_dir.resolve())
Example #3
0
def ingest_unconverted_hsdbs_in_workdir():
    workdir = sysres.get_workdir()
    needs_convert_hsdbs = get_unconverted_hsdbs(workdir)
    for hsdb in needs_convert_hsdbs:
        try:
            convert_hsdb_to_wbia(hsdb)
        except Exception as ex:
            ut.printex(ex)
            raise
Example #4
0
    def get_db_name_from_db_dir(self, db_dir: Path):
        """Discover the database name from the given ``db_dir``"""
        from wbia.init.sysres import get_workdir

        db_dir = db_dir.resolve()  # just in case
        work_dir = Path(get_workdir()).resolve()

        # Can we discover the database name?
        # if not db_dir.is_relative_to(workdir):  # >= Python 3.9
        if not str(work_dir) in str(db_dir):
            raise ValueError(
                'Strange circumstances have lead us to a place of '
                f"incongruity where the '{db_dir}' is not within '{work_dir}'"
            )

        # lowercase because database names are case insensitive
        return db_dir.name.lower()
Example #5
0
def main(force_replace):
    """Initializes the testdb0 & testdb1 testing directories on the filesystem"""
    workdir = Path(get_workdir())

    dbs = {
        # <name>: <factory>
        'testdb1': lambda: ingest_database.ingest_standard_database('testdb1'),
    }

    for db in dbs:
        loc = (workdir / db).resolve()
        if loc.exists():
            if force_replace:
                rmtree(loc)
            else:
                raise RuntimeError(f'{db} already exists at {loc}, aborting')
        factory = dbs[db]
        factory()
        click.echo(f'{db} created at {loc}')
Example #6
0
def set_up_db(request, postgres_base_uri):
    """
    Sets up the testing databases.
    This fixture is set to run automatically any any test run of wbia.

    """
    # If selected, disable running the main logic of this fixture
    if request.config.getoption('--disable-refresh-db', False):
        # Assume the user knows what they are requesting
        return  # bale out

    # Delete DBs, if they exist
    # FIXME (16-Jul-12020) this fixture does not cleanup after itself to preserve exiting usage behavior
    for dbname in TEST_DBNAMES:
        delete_dbdir(dbname)
        if postgres_base_uri:
            engine = sqlalchemy.create_engine(postgres_base_uri)
            engine.execution_options(isolation_level='AUTOCOMMIT').execute(
                f'DROP DATABASE IF EXISTS {dbname}'
            )
            engine.execution_options(isolation_level='AUTOCOMMIT').execute(
                f'CREATE DATABASE {dbname}'
            )
            engine.dispose()

    # Monkey patch the global URI getter
    from wbia.init import sysres

    setattr(sysres, 'get_wbia_db_uri', MonkeyPatchedGetWbiaDbUri(postgres_base_uri))

    # Set up DBs
    ingest_database.ingest_standard_database('testdb1')
    ensure_pz_mtest()
    ensure_nauts()
    ensure_wilddogs()
    ensure_testdb2()

    # Set testdb1 as the main database
    workdir = Path(get_workdir())
    default_db_dir = workdir / 'testdb1'
    # FIXME (16-Jul-12020) Set this only for the test session
    set_default_dbdir(default_db_dir.resolve())
def preload_commands(dbdir, **kwargs):
    """ Preload commands work with command line arguments and global caches """
    # logger.info('[main_cmd] preload_commands')
    params.parse_args()
    if params.args.dump_argv:
        logger.info(ut.repr2(vars(params.args), sorted_=False))
    if params.args.dump_global_cache:
        ut.global_cache_dump()  # debug command, dumps to stdout
    if params.args.set_workdir is not None:
        sysres.set_workdir(params.args.set_workdir)
    if params.args.get_workdir:
        logger.info(' Current work dir = %s' % sysres.get_workdir())
    # if params.args.logdir is not None:
    #     sysres.set_logdir(params.args.logdir)
    if params.args.get_logdir:
        logger.info(' Current local  log dir = %s' %
                    (sysres.get_logdir_local(), ))
        logger.info(' Current global log dir = %s' %
                    (sysres.get_logdir_global(), ))
    if params.args.view_logdir:
        ut.view_directory(sysres.get_logdir_local())
        ut.view_directory(sysres.get_logdir_global())
    if params.args.view_logdir_local:
        ut.view_directory(sysres.get_logdir_local())
    if params.args.view_logdir_global:
        ut.view_directory(sysres.get_logdir_local())
    if ut.get_argflag('--vwd'):
        vwd()
    if ut.get_argflag('--vdq'):
        logger.info('got arg --vdq')
        vdq(dbdir)
    if kwargs.get('delete_ibsdir', False):
        ibsfuncs.delete_wbia_database(dbdir)
    if params.args.preload_exit:
        logger.info('[main_cmd] preload exit')
        sys.exit(0)
def vwd():
    """ view work dir """
    ut.util_cplat.view_directory(sysres.get_workdir())