예제 #1
0
def add_new_temp_contributor(ibs, user_prompt=False, offset=None, autolocate=False):
    r"""
    Auto-docstr for 'add_new_temp_contributor'

    RESTful:
        Method: POST
        URL:    /api/contributor/new_temp/
    """
    name_first = ibs.get_dbname()
    name_last = ut.get_computer_name() + ':' + ut.get_user_name() + ':' + ibs.get_dbdir()
    print('[collect_transfer_data] Contributor default first name: %s' % (name_first, ))
    print('[collect_transfer_data] Contributor default last name:  %s' % (name_last, ))
    if user_prompt:
        name_first = input('\n[collect_transfer_data] Change first name (Enter to use default): ')
        name_last  = input('\n[collect_transfer_data] Change last name (Enter to use default): ')

    if autolocate:
        success, location_city, location_state, location_country, location_zip = ut.geo_locate()
    else:
        success = False

    if success:
        print('\n[collect_transfer_data] Your location was be determined automatically.')
        print('[collect_transfer_data] Contributor default city: %s'    % (location_city, ))
        print('[collect_transfer_data] Contributor default state: %s'   % (location_state, ))
        print('[collect_transfer_data] Contributor default zip: %s'     % (location_country, ))
        print('[collect_transfer_data] Contributor default country: %s' % (location_zip, ))
        if user_prompt:
            location_city    = input('\n[collect_transfer_data] Change default location city (Enter to use default): ')
            location_state   = input('\n[collect_transfer_data] Change default location state (Enter to use default): ')
            location_zip     = input('\n[collect_transfer_data] Change default location zip (Enter to use default): ')
            location_country = input('\n[collect_transfer_data] Change default location country (Enter to use default): ')
    else:
        if user_prompt:
            print('\n')
        print('[collect_transfer_data] Your location could not be determined automatically.')
        if user_prompt:
            location_city    = input('[collect_transfer_data] Enter your location city (Enter to skip): ')
            location_state   = input('[collect_transfer_data] Enter your location state (Enter to skip): ')
            location_zip     = input('[collect_transfer_data] Enter your location zip (Enter to skip): ')
            location_country = input('[collect_transfer_data] Enter your location country (Enter to skip): ')
        else:
            location_city    = ''
            location_state   = ''
            location_zip     = ''
            location_country = ''

    #tag = '::'.join([name_first, name_last, location_city, location_state, location_zip, location_country])
    tag_components = [name_first, name_last, location_city, location_state, location_zip, location_country]
    if offset is not None:
        tag_components += [str(offset)]
    tag_components_clean = [comp.replace(';', '<semi>') for comp in tag_components]
    tag = ','.join(tag_components_clean)
    contrib_rowid = ibs.add_contributors(
        [tag], name_first_list=[name_first],
        name_last_list=[name_last], loc_city_list=[location_city],
        loc_state_list=[location_state], loc_country_list=[location_country],
        loc_zip_list=[location_zip])[0]
    return contrib_rowid
예제 #2
0
    def deploy(self, task_key=None, publish=False):
        """
        Trains and saves a classifier for deployment

        Notes:
            A deployment consists of the following information
                * The classifier itself
                * Information needed to construct the input to the classifier
                    - TODO: can this be encoded as an sklearn pipeline?
                * Metadata concerning what data the classifier was trained with
                * PUBLISH TO /media/hdd/PUBLIC/models/pairclf

        Example:
            >>> # xdoctest: +REQUIRES(module:wbia_cnn)
            >>> from wbia.algo.verif.vsone import *  # NOQA
            >>> params = dict(sample_method='random')
            >>> pblm = OneVsOneProblem.from_empty('PZ_MTEST', **params)
            >>> pblm.setup(with_simple=False)
            >>> task_key = pblm.primary_task_key
            >>> self = Deployer(dpath='.', pblm=pblm)
            >>> deploy_info = self.deploy()

        Ignore:
            pblm.evaluate_classifiers(with_simple=False)
            res = pblm.task_combo_res[pblm.primary_task_key]['RF']['learn(sum,glob)']
        """
        deploy_info = self._make_deploy_info(task_key=task_key)
        deploy_fname = deploy_info['metadata']['fname']

        meta_fname = deploy_fname + self.meta_suffix
        deploy_fpath = join(self.dpath, deploy_fname)
        meta_fpath = join(self.dpath, meta_fname)

        ut.save_json(meta_fpath, deploy_info['metadata'])
        ut.save_data(deploy_fpath, deploy_info)

        if publish:
            user = ut.get_user_name()
            remote_uri = '{user}@{remote}:{path}'.format(user=user,
                                                         **self.publish_info)

            ut.rsync(meta_fpath, remote_uri + '/' + meta_fname)
            ut.rsync(deploy_fpath, remote_uri + '/' + deploy_fname)
        return deploy_info
예제 #3
0
def rsync_ibsdb_main():
    import sys
    default_user = ut.get_user_name()
    default_db = 'MUGU_Master'
    if len(sys.argv) < 2:
        print('Usage: '
              'python -m ibeis.scripts.rsync_ibeisdb'
              '[push, pull] --db <db=%s> --user <user=%s>' %
              (default_db, default_user,))
        sys.exit(1)
    user = ut.get_argval('--user', type_=str, default=default_user)
    port = ut.get_argval('--port', type_=int, default=22)
    dbname = ut.get_argval(('--db', '--dbname'), type_=str, default=default_db)
    workdir = ut.get_argval(('--workdir', '--dbname'), type_=str, default=None,
                            help_='local work dir override')
    dry_run = ut.get_argflag(('--dryrun', '--dry-run', '--dry'))
    mode = sys.argv[1]

    assert mode in ['push', 'pull'], 'mode=%r must be push or pull' % (mode,)
    remote_key = ut.get_argval('--remote', type_=str, default='hyrule')
    remote_map = {
        'hyrule': 'hyrule.cs.rpi.edu',
        'pachy': 'pachy.cs.uic.edu',
        'lewa': '41.203.223.178',
        'lev': 'lev.cs.rpi.edu',
    }
    remote_workdir_map = {
        'hyrule': '/raid/work',
        'pachy': '/home/shared_ibeis/data/work',
        'lewa': '/data/ibeis',
        'lev': '/media/hdd/work',
    }
    if ':' in remote_key:
        remote_key_, remote_workdir = remote_key.split(':')
    else:
        remote_key_ = remote_key
        remote_workdir = remote_workdir_map.get(remote_key, '')

    remote = remote_map.get(remote_key_, remote_key_)
    remote_uri = user + '@' + remote + ':' + remote_workdir

    ut.change_term_title('RSYNC IBEISDB %r' % (dbname,))
    sync_ibeisdb(remote_uri, dbname, mode, workdir, port, dry_run)
예제 #4
0
def set_annot_pair_as_reviewed(ibs, aid1, aid2):
    """ denote that this match was reviewed and keep whatever status it is given """
    isunknown1, isunknown2 = ibs.is_aid_unknown([aid1, aid2])
    if isunknown1 or isunknown2:
        truth = ibs.const.EVIDENCE_DECISION.UNKNOWN
    else:
        nid1, nid2 = ibs.get_annot_name_rowids((aid1, aid2))
        truth = (ibs.const.EVIDENCE_DECISION.POSITIVE if
                 (nid1 == nid2) else ibs.const.EVIDENCE_DECISION.NEGATIVE)

    # Ensure a row exists for this pair
    annotmatch_rowids = ibs.add_annotmatch_undirected([aid1], [aid2])

    # Old functionality, remove. Reviewing should not set truth
    confidence = ibs.const.CONFIDENCE.CODE_TO_INT['guessing']
    ibs.set_annotmatch_evidence_decision(annotmatch_rowids, [truth])
    user_id = ut.get_user_name() + '@' + ut.get_computer_name()
    ibs.set_annotmatch_reviewer(annotmatch_rowids, ['user:'******'... set truth=%r' % (truth, ))
예제 #5
0
def add_new_temp_contributor(ibs,
                             user_prompt=False,
                             offset=None,
                             autolocate=False):
    r"""

    RESTful:
        Method: POST
        URL:    /api/contributor/new/temp/
    """
    name_first = ibs.get_dbname()
    name_last = ut.get_computer_name() + ':' + ut.get_user_name(
    ) + ':' + ibs.get_dbdir()
    print('[collect_transfer_data] Contributor default first name: %s' %
          (name_first, ))
    print('[collect_transfer_data] Contributor default last name:  %s' %
          (name_last, ))
    if user_prompt:
        name_first = input(
            '\n[collect_transfer_data] Change first name (Enter to use default): '
        )
        name_last = input(
            '\n[collect_transfer_data] Change last name (Enter to use default): '
        )

    if autolocate:
        success, location_city, location_state, location_country, location_zip = ut.geo_locate(
        )
    else:
        success = False

    if success:
        print(
            '\n[collect_transfer_data] Your location was be determined automatically.'
        )
        print('[collect_transfer_data] Contributor default city: %s' %
              (location_city, ))
        print('[collect_transfer_data] Contributor default state: %s' %
              (location_state, ))
        print('[collect_transfer_data] Contributor default zip: %s' %
              (location_country, ))
        print('[collect_transfer_data] Contributor default country: %s' %
              (location_zip, ))
        if user_prompt:
            location_city = input(
                '\n[collect_transfer_data] Change default location city (Enter to use default): '
            )
            location_state = input(
                '\n[collect_transfer_data] Change default location state (Enter to use default): '
            )
            location_zip = input(
                '\n[collect_transfer_data] Change default location zip (Enter to use default): '
            )
            location_country = input(
                '\n[collect_transfer_data] Change default location country (Enter to use default): '
            )
    else:
        if user_prompt:
            print('\n')
        print(
            '[collect_transfer_data] Your location could not be determined automatically.'
        )
        if user_prompt:
            location_city = input(
                '[collect_transfer_data] Enter your location city (Enter to skip): '
            )
            location_state = input(
                '[collect_transfer_data] Enter your location state (Enter to skip): '
            )
            location_zip = input(
                '[collect_transfer_data] Enter your location zip (Enter to skip): '
            )
            location_country = input(
                '[collect_transfer_data] Enter your location country (Enter to skip): '
            )
        else:
            location_city = ''
            location_state = ''
            location_zip = ''
            location_country = ''

    #tag = '::'.join([name_first, name_last, location_city, location_state, location_zip, location_country])
    tag_components = [
        name_first, name_last, location_city, location_state, location_zip,
        location_country
    ]
    if offset is not None:
        tag_components += [str(offset)]
    tag_components_clean = [
        comp.replace(';', '<semi>') for comp in tag_components
    ]
    tag = ','.join(tag_components_clean)
    contributor_rowid = ibs.add_contributors(
        [tag],
        name_first_list=[name_first],
        name_last_list=[name_last],
        loc_city_list=[location_city],
        loc_state_list=[location_state],
        loc_country_list=[location_country],
        loc_zip_list=[location_zip])[0]
    return contributor_rowid
예제 #6
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
예제 #7
0
def rsync_ibsdb_main():
    import sys
    default_user = ut.get_user_name()
    # default_db = 'MUGU_Master'
    default_db = None

    # Get positional commandline arguments
    cmdline_varags = ut.get_cmdline_varargs()
    if len(cmdline_varags) > 0 and cmdline_varags[0] == 'rsync':
        # ignore rsync as first command (b/c we are calling from ibeis.__main__)
        cmdline_varags = cmdline_varags[1:]

    valid_modes = ['push', 'pull', 'list']

    if len(cmdline_varags) < 1:
        print('Usage: '
              # 'python -m ibeis.scripts.rsync_ibeisdb'
              'python -m ibeis rsync'
              '%s --db <db=%s> --user <user=%s>' %
              (valid_modes, default_db, default_user,))
        sys.exit(1)

    varargs_dict = dict(enumerate(cmdline_varags))

    mode = varargs_dict.get(0, None)
    default_db = varargs_dict.get(1, None)

    user = ut.get_argval('--user', type_=str, default=default_user)
    port = ut.get_argval('--port', type_=int, default=22)
    dbname = ut.get_argval(('--db', '--dbname'), type_=str, default=default_db)
    workdir = ut.get_argval(('--workdir', '--dbname'), type_=str, default=None,
                            help_='local work dir override')
    dry_run = ut.get_argflag(('--dryrun', '--dry-run', '--dry'))

    assert mode in valid_modes, 'mode=%r must be in %r' % (mode, valid_modes)
    remote_key = ut.get_argval('--remote', type_=str, default='hyrule')
    remote_map = {
        'hyrule': 'hyrule.cs.rpi.edu',
        'pachy': 'pachy.cs.uic.edu',
        'lewa': '41.203.223.178',
        'lev': 'lev.cs.rpi.edu',
    }
    remote_workdir_map = {
        'hyrule': '/raid/work',
        'pachy': '/home/shared_ibeis/data/work',
        'lewa': '/data/ibeis',
        'lev': '/media/hdd/work',
    }
    if ':' in remote_key:
        remote_key_, remote_workdir = remote_key.split(':')
    else:
        remote_key_ = remote_key
        remote_workdir = remote_workdir_map.get(remote_key, '')

    remote = remote_map.get(remote_key_, remote_key_)
    remote_uri = user + '@' + remote + ':' + remote_workdir

    if mode == 'list':
        print('remote = %r' % (remote,))
        print('need to list')
        remote_paths = ut.list_remote(remote_uri)
        print('REMOTE LS -- TODO need to get only ibeis dirs')
        print('\n'.join(remote_paths))
    elif mode in ['push', 'pull']:
        ut.change_term_title('RSYNC IBEISDB %r' % (dbname,))
        sync_ibeisdb(remote_uri, dbname, mode, workdir, port, dry_run)
예제 #8
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
    """
    _preload()
    set_newfile_permissions()
    from wbia.init import main_commands
    from wbia.init import sysres

    # Display a visible intro message
    msg = """
    _____ ______  _______ _____ _______
      |   |_____] |______   |   |______
    __|__ |_____] |______ __|__ ______|
    """
    if NOT_QUIET:
        logger.info(msg)
    # Init the only two main system api handles
    ibs = None
    back = None
    if NOT_QUIET:
        logger.info('[main] wbia.entry_points.main()')
    DIAGNOSTICS = NOT_QUIET
    if DIAGNOSTICS:
        import os
        import utool as ut
        import wbia

        logger.info('[main] MAIN DIAGNOSTICS')
        logger.info('[main]  * username = %r' % (ut.get_user_name()))
        logger.info('[main]  * wbia.__version__ = %r' % (wbia.__version__, ))
        logger.info('[main]  * computername = %r' % (ut.get_computer_name()))
        logger.info('[main]  * cwd = %r' % (os.getcwd(), ))
        logger.info('[main]  * sys.argv = %r' % (sys.argv, ))
    # Parse directory to be loaded from command line args
    # and explicit kwargs
    dbdir = sysres.get_args_dbdir(defaultdb=defaultdb,
                                  allow_newdir=allow_newdir,
                                  db=db,
                                  dbdir=dbdir)
    if delete_ibsdir is True:
        from wbia.other import ibsfuncs

        assert (
            allow_newdir
        ), 'must be making new directory if you are deleting everything!'
        ibsfuncs.delete_wbia_database(dbdir)

    # limit = sys.getrecursionlimit()
    # if limit == 1000:
    #    logger.info('Setting Recursion Limit to 3000')
    #    sys.setrecursionlimit(3000)
    # Execute preload commands
    main_commands.preload_commands(dbdir, **kwargs)  # PRELOAD CMDS
    try:
        # Build IBEIS Control object
        ibs = _init_wbia(dbdir)
        if gui and USE_GUI:
            back = _init_gui(activate=kwargs.get('activate', True))
            back.connect_wbia_control(ibs)
    except Exception as ex:
        logger.info('[main()] IBEIS LOAD encountered exception: %s %s' %
                    (type(ex), ex))
        raise
    main_commands.postload_commands(ibs, back)  # POSTLOAD CMDS
    main_locals = {'ibs': ibs, 'back': back}
    return main_locals
예제 #9
0
def rsync_ibsdb_main():
    import sys
    default_user = ut.get_user_name()
    # default_db = 'MUGU_Master'
    default_db = None

    # Get positional commandline arguments
    cmdline_varags = ut.get_cmdline_varargs()
    if len(cmdline_varags) > 0 and cmdline_varags[0] == 'rsync':
        # ignore rsync as first command (b/c we are calling from ibeis.__main__)
        cmdline_varags = cmdline_varags[1:]

    valid_modes = ['push', 'pull', 'list']

    if len(cmdline_varags) < 1:
        print('Usage: '
              # 'python -m ibeis.scripts.rsync_ibeisdb'
              'python -m ibeis rsync'
              '%s --db <db=%s> --user <user=%s>' % (
                  valid_modes,
                  default_db,
                  default_user,
              ))
        sys.exit(1)

    varargs_dict = dict(enumerate(cmdline_varags))

    mode = varargs_dict.get(0, None)
    default_db = varargs_dict.get(1, None)

    user = ut.get_argval('--user', type_=str, default=default_user)
    port = ut.get_argval('--port', type_=int, default=22)
    dbname = ut.get_argval(('--db', '--dbname'), type_=str, default=default_db)
    workdir = ut.get_argval(('--workdir', '--dbname'),
                            type_=str,
                            default=None,
                            help_='local work dir override')
    dry_run = ut.get_argflag(('--dryrun', '--dry-run', '--dry'))

    assert mode in valid_modes, 'mode=%r must be in %r' % (mode, valid_modes)
    remote_key = ut.get_argval('--remote', type_=str, default='hyrule')
    remote_map = {
        'hyrule': 'hyrule.cs.rpi.edu',
        'pachy': 'pachy.cs.uic.edu',
        'lewa': '41.203.223.178',
        'lev': 'lev.cs.rpi.edu',
    }
    remote_workdir_map = {
        'hyrule': '/raid/work',
        'pachy': '/home/shared_ibeis/data/work',
        'lewa': '/data/ibeis',
        'lev': '/media/hdd/work',
    }
    if ':' in remote_key:
        remote_key_, remote_workdir = remote_key.split(':')
    else:
        remote_key_ = remote_key
        remote_workdir = remote_workdir_map.get(remote_key, '')

    remote = remote_map.get(remote_key_, remote_key_)
    remote_uri = user + '@' + remote + ':' + remote_workdir

    if mode == 'list':
        print('remote = %r' % (remote, ))
        print('need to list')
        remote_paths = ut.list_remote(remote_uri)
        print('REMOTE LS -- TODO need to get only ibeis dirs')
        print('\n'.join(remote_paths))
    elif mode in ['push', 'pull']:
        ut.change_term_title('RSYNC IBEISDB %r' % (dbname, ))
        sync_ibeisdb(remote_uri, dbname, mode, workdir, port, dry_run)
예제 #10
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
예제 #11
0
def rsync_ibsdb_main():
    import sys

    default_user = ut.get_user_name()
    # default_db = 'MUGU_Master'
    default_db = None

    # Get positional commandline arguments
    cmdline_varags = ut.get_cmdline_varargs()
    if len(cmdline_varags) > 0 and cmdline_varags[0] == 'rsync':
        # ignore rsync as first command (b/c we are calling from
        # wbia.__main__)
        cmdline_varags = cmdline_varags[1:]
    valid_modes = ['push', 'pull', 'list']

    if len(cmdline_varags) < 1:
        logger.info('Usage: '
                    # 'python -m wbia.scripts.rsync_wbiadb'
                    'python -m wbia rsync'
                    '%s --db <db=%s> --user <user=%s>' %
                    (valid_modes, default_db, default_user))
        sys.exit(1)

    varargs_dict = dict(enumerate(cmdline_varags))

    mode = varargs_dict.get(0, None)
    default_db = varargs_dict.get(1, None)

    user = ut.get_argval('--user', type_=str, default=default_user)
    port = ut.get_argval('--port', type_=int, default=22)
    dbnames = ut.get_argval(('--db', '--dbs', '--dbname'),
                            type_=str,
                            default=default_db)
    dbnames = ut.smart_cast(dbnames, list)
    workdir = ut.get_argval(('--workdir'),
                            type_=str,
                            default=None,
                            help_='local work dir override')
    dry_run = ut.get_argflag(('--dryrun', '--dry-run', '--dry'))

    assert mode in valid_modes, 'mode=%r must be in %r' % (mode, valid_modes)
    remote_key = ut.get_argval('--remote', type_=str, default='hyrule')
    remote_map = {
        'hyrule': 'hyrule.cs.rpi.edu',
        'pachy': 'pachy.cs.uic.edu',
        'lewa': '41.203.223.178',
    }
    remote_workdir_map = {
        'hyrule': '/raid/work',
        'pachy': '/home/shared_wbia/data/work',
        'lewa': '/data/wbia',
    }
    if ':' in remote_key:
        remote_key_, remote_workdir = remote_key.split(':')
    else:
        remote_key_ = remote_key
        if remote_key not in remote_workdir_map:
            import warnings

            warnings.warn('Workdir not specified for remote')
        remote_workdir = remote_workdir_map.get(remote_key, '')

    remote = remote_map.get(remote_key_, remote_key_)
    remote_uri = user + '@' + remote + ':' + remote_workdir

    if mode == 'list':
        logger.info('remote = %r' % (remote, ))
        logger.info('need to list')
        remote_paths = ut.list_remote(remote_uri)
        logger.info('REMOTE LS -- TODO need to get only wbia dirs')
        logger.info('\n'.join(remote_paths))
    elif mode in ['push', 'pull']:
        logger.info('dbnames = {!r}'.format(dbnames))
        for dbname in ut.ProgIter(dbnames, label='sync db'):
            ut.change_term_title('RSYNC IBEISDB %r' % (dbname, ))
            sync_wbiadb(remote_uri, dbname, mode, workdir, port, dry_run)