コード例 #1
0
ファイル: rsync_ibeisdb.py プロジェクト: heroinlin/ibeis
def sync_ibeisdb(remote_uri, dbname, mode='pull', workdir=None, port=22, dryrun=False):
    """
    syncs an ibeisdb without syncing the cache or the chip directory
    (or the top level image directory because it shouldnt exist unless it is an
    old hots database)
    """
    print('[sync_ibeisdb] Syncing')
    print('  * dbname=%r ' % (dbname,))
    print('  * remote_uri=%r' % (remote_uri,))
    print('  * mode=%r' % (mode))
    import ibeis
    # Excluded temporary and cached data
    exclude_dirs = list(map(ut.ensure_unixslash, ibeis.const.EXCLUDE_COPY_REL_DIRS))
    # Specify local workdir
    if workdir is None:
        workdir = ibeis.sysres.get_workdir()
    local_uri = ut.ensure_unixslash(workdir)
    if ut.WIN32:
        # fix for mingw rsync
        local_uri = ut.ensure_mingw_drive(local_uri)
    if mode == 'pull':
        # pull remote to local
        remote_src = ut.unixjoin(remote_uri, dbname)
        ut.assert_exists(local_uri)
        rsync(remote_src, local_uri, exclude_dirs, port, dryrun=dryrun)
    elif mode == 'push':
        # push local to remote
        local_src = ut.unixjoin(local_uri, dbname)
        if not dryrun:
            ut.assert_exists(local_src)
        rsync(local_src, remote_uri, exclude_dirs, port, dryrun=dryrun)
        if dryrun:
            ut.assert_exists(local_src)
    else:
        raise AssertionError('unknown mode=%r' % (mode,))
コード例 #2
0
ファイル: export_hsdb.py プロジェクト: Erotemic/ibeis
def get_hsdb_image_gpaths(ibs, gid_list):
    r"""
    Args:
        ibs (IBEISController):  ibeis controller object
        gid_list (list):

    Returns:
        list: gpath_list

    CommandLine:
        python -m ibeis.dbio.export_hsdb --test-get_hsdb_image_gpaths

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.dbio.export_hsdb import *  # NOQA
        >>> import ibeis
        >>> # build test data
        >>> ibs = ibeis.opendb('testdb1')
        >>> gid_list = ibs.get_valid_gids()[0:2]
        >>> # execute function
        >>> gpath_list = get_hsdb_image_gpaths(ibs, gid_list)
        >>> # verify results
        >>> result = ut.list_str(gpath_list)
        >>> print(result)
        [
            '../_ibsdb/images/66ec193a-1619-b3b6-216d-1784b4833b61.jpg',
            '../_ibsdb/images/d8903434-942f-e0f5-d6c2-0dcbe3137bf7.jpg',
        ]
    """
    imgdir = join(ibs.get_dbdir(), "images")
    gpath_list_ = ibs.get_image_paths(gid_list)
    gpath_list = [ut.ensure_unixslash(relpath(gpath, imgdir)) for gpath in gpath_list_]
    return gpath_list
コード例 #3
0
def get_hsdb_image_gpaths(ibs, gid_list):
    r"""
    Args:
        ibs (IBEISController):  wbia controller object
        gid_list (list):

    Returns:
        list: gpath_list

    CommandLine:
        python -m wbia.dbio.export_hsdb --test-get_hsdb_image_gpaths

    Example:
        >>> # ENABLE_DOCTEST
        >>> from wbia.dbio.export_hsdb import *  # NOQA
        >>> import wbia
        >>> # build test data
        >>> ibs = wbia.opendb('testdb1')
        >>> gid_list = ibs.get_valid_gids()[0:2]
        >>> # execute function
        >>> gpath_list = get_hsdb_image_gpaths(ibs, gid_list)
        >>> # verify results
        >>> result = ut.repr2(gpath_list, nl=1)
        >>> print(result)
        [
            '../_ibsdb/images/66ec193a-1619-b3b6-216d-1784b4833b61.jpg',
            '../_ibsdb/images/d8903434-942f-e0f5-d6c2-0dcbe3137bf7.jpg',
        ]
    """
    imgdir = join(ibs.get_dbdir(), 'images')
    gpath_list_ = ibs.get_image_paths(gid_list)
    gpath_list = [
        ut.ensure_unixslash(relpath(gpath, imgdir)) for gpath in gpath_list_
    ]
    return gpath_list
コード例 #4
0
ファイル: sysres.py プロジェクト: warunanc/ibeis
def copy_ibeisdb(source_dbdir, dest_dbdir):
    # TODO: rectify with rsync, script, and merge script.
    from os.path import normpath
    import ibeis
    exclude_dirs_ = (ibeis.const.EXCLUDE_COPY_REL_DIRS +
                     ['_hsdb', '.hs_internals'])
    exclude_dirs = [ut.ensure_unixslash(normpath(rel))
                    for rel in exclude_dirs_]

    rel_tocopy = ut.glob(source_dbdir, '*', exclude_dirs=exclude_dirs,
                         recursive=True, with_files=True, with_dirs=False,
                         fullpath=False)
    rel_tocopy_dirs = ut.glob(source_dbdir, '*', exclude_dirs=exclude_dirs,
                              recursive=True, with_files=False, with_dirs=True,
                              fullpath=False)

    src_list = [join(source_dbdir, relpath) for relpath in rel_tocopy]
    dst_list = [join(dest_dbdir, relpath) for relpath in rel_tocopy]

    # ensure directories exist
    rel_tocopy_dirs = [dest_dbdir] + [join(dest_dbdir, dpath_)
                                      for dpath_ in rel_tocopy_dirs]
    for dpath in rel_tocopy_dirs:
        ut.ensuredir(dpath)
    # copy files
    ut.copy(src_list, dst_list)
コード例 #5
0
ファイル: sysres.py プロジェクト: heroinlin/ibeis
def copy_ibeisdb(source_dbdir, dest_dbdir):
    # TODO; rectify with rsycn script
    from os.path import normpath
    import ibeis
    exclude_dirs = [ut.ensure_unixslash(normpath(rel)) for rel in ibeis.const.EXCLUDE_COPY_REL_DIRS + ['_hsdb', '.hs_internals']]

    rel_tocopy = ut.glob(source_dbdir, '*', exclude_dirs=exclude_dirs, recursive=True, with_files=True, with_dirs=False, fullpath=False)
    rel_tocopy_dirs = ut.glob(source_dbdir, '*', exclude_dirs=exclude_dirs, recursive=True, with_files=False, with_dirs=True, fullpath=False)

    src_list = [join(source_dbdir, relpath) for relpath in rel_tocopy]
    dst_list = [join(dest_dbdir, relpath) for relpath in rel_tocopy]

    # ensure directories exist
    rel_tocopy_dirs = [dest_dbdir] + [join(dest_dbdir, dpath_) for dpath_ in rel_tocopy_dirs]
    for dpath in rel_tocopy_dirs:
        ut.ensuredir(dpath)
    # copy files
    ut.copy(src_list, dst_list)
コード例 #6
0
def sync_wbiadb(remote_uri,
                dbname,
                mode='pull',
                workdir=None,
                port=22,
                dryrun=False):
    """
    syncs an wbiadb without syncing the cache or the chip directory
    (or the top level image directory because it shouldnt exist unlese
    it is an old hots database)
    """
    logger.info('[sync_wbiadb] Syncing')
    logger.info('  * dbname=%r ' % (dbname, ))
    logger.info('  * remote_uri=%r' % (remote_uri, ))
    logger.info('  * mode=%r' % (mode))
    import wbia

    assert dbname is not None, 'must specify a database name'
    # Excluded temporary and cached data
    exclude_dirs = list(
        map(ut.ensure_unixslash, wbia.const.EXCLUDE_COPY_REL_DIRS))
    # Specify local workdir
    if workdir is None:
        workdir = wbia.sysres.get_workdir()
    local_uri = ut.ensure_unixslash(workdir)
    if ut.WIN32:
        # fix for mingw rsync
        local_uri = ut.ensure_mingw_drive(local_uri)
    if mode == 'pull':
        # pull remote to local
        remote_src = ut.unixjoin(remote_uri, dbname)
        ut.assert_exists(local_uri)
        ut.rsync(remote_src, local_uri, exclude_dirs, port, dryrun=dryrun)
    elif mode == 'push':
        # push local to remote
        local_src = ut.unixjoin(local_uri, dbname)
        if not dryrun:
            ut.assert_exists(local_src)
        ut.rsync(local_src, remote_uri, exclude_dirs, port, dryrun=dryrun)
        if dryrun:
            ut.assert_exists(local_src)
    else:
        raise AssertionError('unknown mode=%r' % (mode, ))
コード例 #7
0
ファイル: util_autogen.py プロジェクト: SU-ECE-18-7/utool
def make_default_module_maintest(modname, modpath=None):
    """
    make_default_module_maintest

    TODO: use path relative to home dir if the file is a script

    Args:
        modname (str):  module name

    Returns:
        str: text source code

    CommandLine:
        python -m utool.util_autogen --test-make_default_module_maintest

    References:
        http://legacy.python.org/dev/peps/pep-0338/

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_autogen import *  # NOQA
        >>> modname = 'utool.util_autogen'
        >>> text = make_default_module_maintest(modname)
        >>> result = str(text)
        >>> print(result)
    """
    import utool as ut
    # Need to use python -m to run a module
    # otherwise their could be odd platform specific errors.
    #python -c "import utool, {modname};
    # ut.doctest_funcs({modname}, allexamples=True)"
    #in_pythonpath, module_type, path = find_modname_in_pythonpath(modname)
    # only use the -m if it is part of a package directory

    if modpath is not None:
        moddir = dirname(modpath)
        pkginit_fpath = join(moddir, '__init__.py')
        use_modrun = exists(pkginit_fpath)
    else:
        use_modrun = True

    if use_modrun:
        pyargs = '-m ' + modname
    else:
        if ut.WIN32:
            modpath = normpath(modpath).replace(expanduser('~'), '%HOME%')
            pyargs = '-B ' + ut.ensure_unixslash(modpath)
        else:
            modpath = normpath(modpath).replace(expanduser('~'), '~')
            pyargs = modpath

    cmdline = ut.codeblock(
        '''
        python {pyargs}
        python {pyargs} --allexamples
        # REM python {pyargs} --allexamples --noface --nosrc
        ''')

    if not use_modrun:
        if ut.WIN32:
            augpath = 'set PYTHONPATH=%PYTHONPATH%' + os.pathsep + moddir
        else:
            augpath = 'export PYTHONPATH=$PYTHONPATH' + os.pathsep + moddir
        cmdline = augpath + '\n' + cmdline

    cmdline = ut.indent(cmdline, ' ' * 8).lstrip(' ').format(pyargs=pyargs)

    text = ut.codeblock(
        r'''
        # STARTBLOCK
        if __name__ == '__main__':
            r"""
            CommandLine:
                {cmdline}
            """
            import multiprocessing
            multiprocessing.freeze_support()  # for win32
            import utool as ut  # NOQA
            ut.doctest_funcs()
        # ENDBLOCK
        '''
    ).format(cmdline=cmdline)
    text = remove_codeblock_syntax_sentinals(text)
    return text