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: wbia.IBEISController: ibs Example: >>> # ENABLE_DOCTEST >>> from wbia.entry_points 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 wbia.init import sysres from wbia.other import ibsfuncs dbdir = sysres.get_args_dbdir( defaultdb=defaultdb, allow_newdir=allow_newdir, db=db, dbdir=dbdir ) if delete_ibsdir is True: assert ( allow_newdir ), 'must be making new directory if you are deleting everything!' ibsfuncs.delete_wbia_database(dbdir) ibs = _init_wbia(dbdir, verbose=verbose, use_cache=use_cache, web=web, **kwargs) return ibs
def test_defaultdb_cache(self, monkeypatch): # Monkeypatch the target function to guarantee the result. target = '<monkey>' monkeypatch.setattr(sysres, 'get_default_dbdir', lambda: target) # If defaultdb='cache' then the most recently used database directory is returned. d = get_args_dbdir(defaultdb='cache') assert d == target
def opendb_test(gui=True, dbdir=None, defaultdb='cache', allow_newdir=False, db=None): """ alias for main() """ # + main.__doc__ from wbia.init import sysres _preload() dbdir = sysres.get_args_dbdir( defaultdb=defaultdb, allow_newdir=allow_newdir, db=db, dbdir=dbdir ) ibs = _init_wbia(dbdir) return ibs
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
def test_defaultdb(self): target = 'foo' # In all other circumstances defaultdb is used. d = get_args_dbdir(defaultdb=target) assert d == self.get_db_to_dbdir_marked(target)
def test_cli_dbdir(self, monkeypatch): target = 'foo' monkeypatch.setattr(sys, 'argv', ['--dbdir', target]) # ... then command line arguments are used. d = get_args_dbdir(None, False, None, None) assert d == self.get_realpath_marked(target)
def test_dbdir_arg(self): # The function first defaults to the specified function arguments. target = 'foo' d = get_args_dbdir(None, False, None, target) assert d == self.get_realpath_marked(target)
def test_db_arg(self): # The function first defaults to the specified function arguments. target = 'testdb1' d = get_args_dbdir(None, False, target, None) assert d == self.get_db_to_dbdir_marked(target)
def test_no_args(self): try: get_args_dbdir() except ValueError as exc: assert exc.args[ 0] == 'Must specify at least db, dbdir, or defaultdb'