def load_thing_classes(dr: DataRiver, thing_class_dir: str): tcr = JSonThingClassRegistry() for entry in os.scandir(thing_class_dir): if entry.is_file() and entry.path.endswith('.json'): log.info(f'Loading thing class: {entry.path}') try: tcr.register_thing_classes_from_uri(f'file://{entry.path}') except Exception as e: log.error(f'Unable to load thing class: {entry.path} : {e}') pass dr.add_thing_class_registry(tcr)
def register_thing_classes(dr: DataRiver, thing_class_dir: str, thing_classes: List[str]): ''' For each of the Thing Classes listed in thing_classes and whose definition is in thing_class_dir register them with the provided instance of the Data River; dr. The thing_classes list shoudl be the name of the file without the .json extension ''' tcr = JSonThingClassRegistry() for tc in thing_classes: logging.info(f'Loading Thing Class: {tc}.json from {thing_class_dir}') tcr.register_thing_classes_from_uri( get_abs_file_uri(str(os.path.join(thing_class_dir, f'{tc}.json')))) dr.add_thing_class_registry(tcr)