def new_database(back): # File -> New Database new_db = back.user_input('Enter the new database name') msg_put = 'Where should I put %r?' % new_db opt_put = ['Choose Directory', 'My Work Dir'] reply = back.user_option(msg_put, 'options', opt_put, True) if reply == opt_put[1]: put_dir = back.get_work_directory() elif reply == opt_put[0]: msg = 'Select where to put the new database' put_dir = guitools.select_directory(msg) elif reply is None: back.user_info('No Reply. Aborting new database') print('[*back] abort new database()') return None else: raise Exception('Unknown reply=%r' % reply) new_db_dir = join(put_dir, new_db) # Check the put directory exists and the new database does not exist msg_try = None if not exists(put_dir): msg_try = 'Directory %r does not exist.' % put_dir elif exists(new_db_dir): msg_try = 'New Database %r already exists.' % new_db_dir if msg_try is not None: opt_try = ['Try Again'] title_try = 'New Database Failed' try_again = back.user_option(msg_try, title_try, opt_try, False) if try_again == 'Try Again': return back.new_database() print('[*back] valid new_db_dir = %r' % new_db_dir) helpers.ensurepath(new_db_dir) back.open_database(new_db_dir)
def open_database(back, db_dir=None): # File -> Open Database try: # Use the same args in a new (opened) database args = back.hs.args if db_dir is None: msg = 'Select (or create) a database directory.' db_dir = guitools.select_directory(msg) print('[*back] user selects database: ' + db_dir) # Try and load db args.dbdir = db_dir hs = HotSpotterAPI.HotSpotter(args=args, db_dir=db_dir) hs.load(load_all=False) # Write to cache and connect if successful io.global_cache_write('db_dir', db_dir) back.connect_api(hs) #back.layout_figures() except Exception as ex: import traceback print(traceback.format_exc()) back.user_info('Aborting open database') print('aborting open database') print(ex) if back.hs.args.strict: raise print('')
def import_images_from_dir(back): # File -> Import Images From Directory msg = 'Select directory with images in it' img_dpath = guitools.select_directory(msg) print('[*back] selected %r' % img_dpath) fpath_list = helpers.list_images(img_dpath, fullpath=True) back.hs.add_images(fpath_list) back.populate_image_table() print('')
def get_work_directory(back, use_cache=True): # TODO: This should go in api (or higher level main?) cache_id = 'work_directory_cache_id' if use_cache: work_dir = io.global_cache_read(cache_id, default='.') if work_dir is not '.' and exists(work_dir): return work_dir msg_dir = 'Work directory not currently set. Select a work directory' work_dir = guitools.select_directory(msg_dir) if not exists(work_dir): msg_try = 'Directory %r does not exist.' % work_dir opt_try = ['Try Again'] try_again = back.user_option(msg_try, 'get work dir failed', opt_try, False) if try_again == 'Try Again': return back.get_work_dir(use_cache) io.global_cache_write(cache_id, work_dir) return work_dir