Beispiel #1
0
def add_file_to_filesec(workspace, path, filegrp):
    """Add file element to fileGrp element given as parameter.

    :param workspace: Workspace directorye from which administrative MD
                      files and amd reference files searched.
    :param path: url encoded path of the file
    :param lxml.etree.Element filegrp: fileGrp element
    :param str returns: id of file added to fileGrp
    :returns: unique identifier of file element
    """
    fileid = '_{}'.format(uuid4())

    # Create list of IDs of amdID elements
    amdids = get_md_references(workspace, path=path)

    # Create XML element and add it to fileGrp
    file_el = mets.file_elem(fileid,
                             admid_elements=set(amdids),
                             loctype='URL',
                             xlink_href='file://%s' %
                             encode_path(path, safe='/'),
                             xlink_type='simple',
                             groupid=None)

    streams = get_objectlist(workspace, path)
    if streams:
        for stream in streams:
            stream_ids = get_md_references(workspace, path=path, stream=stream)
            stream_el = mets.stream(admid_elements=stream_ids)
            file_el.append(stream_el)

    filegrp.append(file_el)

    return fileid
def add_file_to_filesec(all_amd_refs, object_refs, path, filegrp):
    """Add file element to fileGrp element given as parameter.

    :all_amd_refs: XML element tree of administrative metadata references
    :object_refs: XML tree of object references
    :path: url encoded path of the file
    :filegrp: fileGrp element
    :returns: unique identifier of file element
    """
    fileid = '_{}'.format(uuid4())

    # Create list of IDs of amdID elements
    amdids = get_md_references(all_amd_refs, path=path)

    # Create XML element and add it to fileGrp
    file_el = mets.file_elem(fileid,
                             admid_elements=set(amdids),
                             loctype='URL',
                             xlink_href='file://%s' %
                             encode_path(path, safe='/'),
                             xlink_type='simple',
                             groupid=None)

    streams = get_objectlist(object_refs, path)
    if streams:
        for stream in streams:
            stream_ids = get_md_references(all_amd_refs,
                                           path=path,
                                           stream=stream)
            stream_el = mets.stream(admid_elements=stream_ids)
            file_el.append(stream_el)

    filegrp.append(file_el)

    return fileid
Beispiel #3
0
def add_file_to_filesec(workspace, path, filegrp, amdids):
    """Add file element to fileSec.
    """
    othermd_types = ['addml', 'mix', 'videomd', 'audiomd', 'textmd']
    techmd_files, techmd_ids = ids_for_files(workspace, path, 'techmd.xml')
    fileid = '_' + str(uuid4())
    filepath = decode_path(techmd_files[0], '-techmd.xml')
    othermd_ids = []
    for mdtype in othermd_types:
        othermd_ids = read_temp_othermdfile(workspace, mdtype, filepath,
                                            othermd_ids)
    file_el = mets.file_elem(fileid,
                             admid_elements=techmd_ids + amdids + othermd_ids,
                             loctype='URL',
                             xlink_href='file://%s' % filepath,
                             xlink_type='simple',
                             groupid=None)
    filegrp.append(file_el)
    return fileid
Beispiel #4
0
def test_get_fileid():
    """Test get_fileid function. Create a fileGrp element with few files and
    test that the function finds correct file IDs.
    """

    # Create fileGrp element that contains three file elements with different
    # identifiers and paths
    files = [
        mets.file_elem(file_id='identifier%s' % num,
                       admid_elements=['foo', 'bar'],
                       loctype='foo',
                       xlink_href='file://path/to/file+name%s' % num,
                       xlink_type='foo') for num in range(3)
    ]

    filegrp = mets.filegrp(child_elements=files)

    assert compile_structmap.get_fileid(filegrp, 'path/to/file name1') \
        == 'identifier1'