示例#1
0
def store_view_model(view_model, base_dir):
    # type: (ViewModel, str) -> str
    """
    Completely store any ViewModel object to the directory specified by base_dir.
    """
    vm_loader = ViewModelLoader(base_dir)
    return vm_loader.store(view_model)
示例#2
0
def load_view_model(gid, base_dir):
    # type: (typing.Union[uuid.UUID, str], str) -> ViewModel
    """
    Load a ViewModel object by reading the H5 file with the given GID, from the directory specified by base_dir.
    """
    vm_loader = ViewModelLoader(base_dir)
    return vm_loader.load(gid)
示例#3
0
def gather_references_of_view_model(gid, base_dir, only_view_models=False):
    """
    Gather in 2 lists all file paths that are referenced by a ViewModel with the given GID stored in base_dir directory.
    If only_view_models=True, returns only ViewModelH5 file paths, otherwise, returns also datatype H5 file paths.
    """
    def load_dts(vm_h5, ref_files):
        uuids = vm_h5.gather_datatypes_references()
        uuid_files = []
        for _, gid in uuids:
            if not gid:
                continue
            index = load_entity_by_gid(gid)
            h5_file = h5_file_for_index(index)
            uuid_files.append(h5_file.path)
            gather_all_references_by_index(h5_file, uuid_files)
        ref_files.extend(uuid_files)

    vm_refs = []
    dt_refs = []
    load_dts_function = None if only_view_models else load_dts
    ViewModelLoader(base_dir).gather_reference_files(gid, vm_refs, dt_refs,
                                                     load_dts_function)

    if only_view_models:
        return list(set(vm_refs)), None
    else:
        return list(set(vm_refs)), list(set(dt_refs))
示例#4
0
def load_view_model_from_file(filepath):
    # type: (str) -> ViewModel
    """
    Load a ViewModel object by reading the H5 file specified by filepath.
    """
    base_dir = os.path.dirname(filepath)
    fname = os.path.basename(filepath)
    return ViewModelLoader(base_dir).load(fname=fname)