def build_fileSec(flgrp_dict): file_sec = mets_model.FileSec() for rep in flgrp_dict: for item in rep: id_val = item rep_no = id_val[3:] rep_admid = id_val + "-amd" flgrp_attrs = { 'USE': rep[item][0]['USE'], 'ID': id_val, 'ADMID': rep_admid } flgrp = mets_model.FileGrp(**flgrp_attrs) file_sec.append(flgrp) for file_item in rep[item][1]: for fi in file_item: file_id = fi file_admid = "{}-amd".format(file_id) file_element = mets_model.File(ID=file_id, ADMID=file_admid) flgrp.append(file_element) flocat = mets_model.FLocat(href=file_item[fi]['href'], LOCTYPE='URL') file_element.append(flocat) return file_sec
def _parse_json_for_filegrp(filegrp, rep_no, json_doc, input_dir): if type(json_doc) == str: rep_dict = json.loads(json_doc) else: rep_dict = json_doc file_no = 1 for item in rep_dict: try: file_el = mm.File(ID="fid{}-{}".format(file_no, rep_no), ADMID="fid{}-{}-amd".format(file_no, rep_no)) flocat = mm.FLocat(LOCTYPE="URL", href=item['fileOriginalPath']) file_el.append(flocat) filegrp.append(file_el) file_no += 1 except KeyError: print( "The following json was missing an important value: {}".format( item))
def test_FLocat_tag(): flocat = mm.FLocat() assert (flocat.tag == '{http://www.loc.gov/METS/}FLocat')
def build_single_file_mets(ie_dmd_dict=None, filepath=None, cms=None, webHarvesting=None, generalIECharacteristics=None, objectIdentifier=None, accessRightsPolicy=None, eventList=None, digital_original=False): mets = mf.build_mets() _build_ie_dmd_amd(mets, ie_dmd_dict=ie_dmd_dict, generalIECharacteristics=generalIECharacteristics, cms=cms, webHarvesting=webHarvesting, objectIdentifier=objectIdentifier, accessRightsPolicy=accessRightsPolicy, eventList=eventList) # Build rep amdsec rep_amdsec = ET.Element("{http://www.loc.gov/METS/}amdSec", ID="rep1-amd") general_rep_characteristics = [{ 'RevisionNumber': '1', 'DigitalOriginal': str(digital_original).lower(), 'usageType': 'VIEW', 'preservationType': 'PRESERVATION_MASTER' }] rep_amd_tech = dnx_factory.build_rep_amdTech( generalRepCharacteristics=general_rep_characteristics) rep_amd_rights = None rep_amd_digiprov = None rep_amd_source = None build_amdsec(rep_amdsec, tech_sec=rep_amd_tech, rights_sec=rep_amd_rights, source_sec=rep_amd_source, digiprov_sec=rep_amd_digiprov) mets.append(rep_amdsec) # Build file amdsec fl_amdsec = ET.Element("{http://www.loc.gov/METS/}amdSec", ID="fid1-1-amd") file_original_location = filepath file_original_name = os.path.normpath(file_original_location).split( os.path.sep)[-1] file_label = os.path.splitext(file_original_name)[0] file_size_bytes = os.path.getsize(file_original_location) last_modified = time.strftime( "%Y-%m-%dT%H:%M:%S", time.localtime(os.path.getmtime(file_original_location))) created_time = time.strftime( "%Y-%m-%dT%H:%M:%S", time.localtime(os.path.getctime(file_original_location))) general_file_characteristics = [{ 'fileOriginalPath': file_original_location, 'fileSizeBytes': str(file_size_bytes), 'fileModificationDate': last_modified, 'fileCreationDate': created_time, 'fileOriginalName': file_original_name, 'label': file_label }] file_fixity = [{ 'fixityType': 'MD5', 'fixityValue': generate_md5(file_original_location) }] fl_amd_tech = dnx_factory.build_file_amdTech( generalFileCharacteristics=general_file_characteristics, fileFixity=file_fixity) build_amdsec(fl_amdsec, tech_sec=fl_amd_tech) mets.append(fl_amdsec) # build filesec filename = os.path.basename(filepath) file_label = os.path.splitext(filename)[0] filesec = mm.FileSec() filegrp = mm.FileGrp(ID="rep1", ADMID="rep1-amd", USE="VIEW") filesec.append(filegrp) file_el = mm.File(ID='fid1-1', ADMID="fid1-1-amd") filegrp.append(file_el) flocat = mm.FLocat(LOCTYPE="URL", href=filename) file_el.append(flocat) mets.append(filesec) # build structmap structmap = mm.StructMap(ID="rep1-1", TYPE="PHYSICAL") div_1 = mm.Div(LABEL="Preservation Master") structmap.append(div_1) div_2 = mm.Div(LABEL="Table of Contents") div_1.append(div_2) div_3 = mm.Div(LABEL=file_label, TYPE="FILE") div_2.append(div_3) fptr = mm.Fptr(FILEID='fid1-1') div_3.append(fptr) mets.append(structmap) return mets