def step( self ) : error = None mets_file = self.command_line.exported_mets_file mets_file_original = mets_file + self.config.general.mets_file_original_extension # Duplicate METS so we always have the original file (This has the current image paths) if self.debug: print "File locations:", mets_file, mets_file_original shutil.copyfile( mets_file, mets_file_original ) error = self.checkFile( mets_file_original ) if error == None: silo = self.config.databank.silo mets, error = self._open( mets_file ) if mets: error = None schema = r"{http://www.loc.gov/METS/}" pretty_print = False if self.debug: pretty_print = True root = mets.getroot() for div_element in root.iterfind( r"./{0}structMap[@TYPE='PHYSICAL']/{0}div/{0}div".format (schema) ) : uuid = div_element.get( "CONTENTIDS" )[9:] for fptr in div_element.iterfind( "{0}fptr".format(schema) ) : xpath = r"./{0}fileSec/{0}fileGrp/{0}file[@ID='{1}']/{0}FLocat".format( schema, fptr.get( "FILEID" ) ) file_link = root.find( xpath ) file_href_basename = os.path.basename( file_link.get( "{http://www.w3.org/1999/xlink}href" ) ) databank_href = self.config.update_mets.databank_url + Databank.getFileUrl( silo, uuid, file_href_basename ) file_link.set( "{http://www.w3.org/1999/xlink}href", databank_href ) success, error = self._save( mets_file, unicode( etree.tostring( root, xml_declaration=True, encoding='UTF-8', method='xml', pretty_print=pretty_print ), "utf-8" ) ) if success: error = None else: error += " Unable to copy the METS file" return error