def batch_profile_factory(batch_profile, base_directory): """Wrapper function for getting a batch profile. Args: batch_profile (None, string or BatchProfile): indication of the batch profile to use. If a string is given it is loaded from the users home folder. Else the best matching profile is returned. base_directory (str): the data folder we want to use the batch profile on. Returns: BatchProfile: If the given batch profile is None we return the output from get_best_batch_profile(). If batch profile is a string we use it from the batch profiles loader. Else we return the input. """ if batch_profile is None: return get_best_batch_profile(base_directory) elif isinstance(batch_profile, str): return get_batch_profile(batch_profile)() return batch_profile
def get_best_batch_profile(data_folder): """Get the batch profile that best matches the given directory. Args: data_folder (str): the directory for which to get the best batch profile. Returns: BatchProfile: the best matching batch profile. """ profiles = [ get_batch_profile(name)() for name in get_component_list('batch_profiles') ] best_crawler = None best_subjects_count = 0 for profile in profiles: if profile.is_suitable(data_folder): tmp_count = len(profile.get_subjects(data_folder)) if tmp_count > best_subjects_count: best_crawler = profile best_subjects_count = tmp_count return best_crawler