def scan_calib_for_experiment(exp='cxix25615', **kwargs): host = kwargs.get('host', None) port = kwargs.get('port', None) user = kwargs.get('user', None) upwd = kwargs.get('upwd', None) verbose = kwargs.get('verbose', False) client = dbu.connect_to_server(host, port, user, upwd) dbname = dbu.db_prefixed_name(exp) if dbu.database_exists(client, dbname): msg = 'Experiment %s already has a database. Consider to delete it from the list:\n%s'%\ (exp, str(dbu.database_names(client)))+\ '\nBefore adding consider to delete existing DB using command: cdb deldb --dbname %s -C -u <username> -p <password>' % dbname logger.warning(msg) return dircalib = nm.dir_calib(exp) #if verbose : logger.info('Scan: %s' % dircalib) for dir0 in gu.get_list_of_files_in_dir_for_part_fname(dircalib, pattern='::'): if not os.path.isdir(dir0): continue calibvers = os.path.basename(dir0) logger.debug(' %s ' % calibvers) for dir1 in gu.get_list_of_files_in_dir_for_part_fname(dir0, pattern=':'): if not os.path.isdir(dir1): continue detname = os.path.basename(dir1) detname_m = detname_conversion(detname) logger.debug(' %s' % detname_m) for cftype in gu.get_list_of_files_in_dir(dir1): if not (cftype in cc.list_calib_names): continue dir2 = '%s/%s' % (dir1, cftype) if not os.path.isdir(dir2): continue logger.debug(' %s' % cftype) cfdir = '%s/%s/%s/%s' % (dircalib, calibvers, detname, cftype) listdicts = history_list_of_dicts('%s/HISTORY' % cfdir, verbose) #logger.debug('XXX listdicts %s' % listdicts) count = 0 for fname in gu.get_list_of_files_in_dir(dir2): logger.debug(' %s' % fname) if fname == 'HISTORY': continue if os.path.splitext(fname)[1] != '.data': continue logger.debug(' XXX begin adding: %s %s %s %s' % (dircalib, detname_m, cftype, fname)) add_calib_file_to_cdb(exp, dircalib, calibvers, detname_m, cftype, fname, cfdir, listdicts, **kwargs) count += 1 logger.info(' converted %3d files from: %s' % (count, cfdir))
def test_dir_calib(tname): logger.info('dir_calib: %s' % nm.dir_calib('cxi02117'))