Changeset 1821
- Timestamp:
- 05/12/06 17:27:45 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TI01-discovery/trunk/ingestAutomation/OAIBatch/SpaceTimeIngestFromMOLES.py
r1809 r1821 36 36 def main(indir): 37 37 if indir == "": 38 sys.exit("U sage: argument 1 = full path of directory where MOLES records reside")38 sys.exit("USAGE: argument 1 = full path of directory where MOLES records reside") 39 39 else: 40 40 print "INFO: moles records are in %s" %indir 41 41 42 42 #this is a fix to the ElementTree namespace problem that namespaces are usually represented as ns0, ns1, ns2 etc. 43 etree._namespace_map.update({'http://ndg.nerc.ac.uk/moles': 'moles', 'http:// ndg.nerc.ac.uk/csml' : 'csml', 'http://www.w3.org/1999/xlink':'xlink'})43 etree._namespace_map.update({'http://ndg.nerc.ac.uk/moles': 'moles', 'http://www.w3.org/1999/xlink':'xlink'}) 44 44 numfilesproc = 0 45 45 … … 49 49 full_filename = indir + "/" + filename 50 50 dgMeta=MRW.dgMetadata() 51 dgMeta.fromXML(cElementTree.ElementTree(file=full_filename).getroot()) 52 bbox=dgMeta.dgMetadataRecord.dgDataEntity.dgDataSummary.dgDataCoverage.dgSpatialCoverage.BoundingBox 53 dates=dgMeta.dgMetadataRecord.dgDataEntity.dgDataSummary.dgDataCoverage.dgTemporalCoverage.DateRange 51 try: 52 dgMeta.fromXML(cElementTree.ElementTree(file=full_filename).getroot()) 53 except: 54 print "WARNING: Cannot parse the XML moles document %s. Will not process" %full_filename 55 continue 56 try: 57 bbox=dgMeta.dgMetadataRecord.dgDataEntity.dgDataSummary.dgDataCoverage.dgSpatialCoverage.BoundingBox 58 except: 59 print "INFO: XML moles document %s does not contain a bounding box." %full_filename 60 61 try: 62 dates=dgMeta.dgMetadataRecord.dgDataEntity.dgDataSummary.dgDataCoverage.dgTemporalCoverage.DateRange 63 except: 64 print "INFO: XML moles document %s does not contain a bounding box." %full_filename 65 54 66 coverage= [dates.DateRangeEnd, dates.DateRangeStart, bbox.LimitNorth, bbox.LimitSouth,bbox.LimitEast, bbox.LimitWest] 55 67 #Mid = dgMeta.dgMetadataRecord.dgMetadataID.repositoryIdentifier+"__"+dgMeta.dgMetadataRecord.dgMetadataID.localIdentifier … … 69 81 float(west) 70 82 except: 71 print "E rror:Will not process File %s. Contains incorrect West bounding box limit." %full_filename83 print "ERROR: Will not process File %s. Contains incorrect West bounding box limit." %full_filename 72 84 continue 73 85 print "West = %s" %west … … 84 96 float(east) 85 97 except: 86 print "E rror:Will not process File %s. Contains incorrect East bounding box limit." %full_filename98 print "ERROR: Will not process File %s. Contains incorrect East bounding box limit." %full_filename 87 99 continue 88 100 print "East = %s" %east … … 99 111 float(north) 100 112 except: 101 print "E rror: Will not process File %s. Contains incorrect North bounding box limit." %full_filename113 print "ERROR: Will not process File %s. Contains incorrect North bounding box limit." %full_filename 102 114 continue 103 115 print "North = %s" %north … … 114 126 float(south) 115 127 except: 116 print "E rror: Will not process File %s. Contains incorrect North bounding box limit." %full_filename128 print "ERROR: Will not process File %s. Contains incorrect North bounding box limit." %full_filename 117 129 continue 118 130 print "North = %s" %south 119 131 120 132 if id_exists( Mid ): 121 print "doc %s exists, updating\n" %Mid122 133 print "INFO: doc %s exists, updating\n" %Mid 134 do_update( Mid, west, south, east, north, dates.DateRangeStart, dates.DateRangeEnd ) 123 135 else: 124 print "doc %s does not exist, inserting new record\n" %Mid125 136 print "INFO: doc %s does not exist, inserting new record\n" %Mid 137 do_insert( Mid, west, south, east, north, dates.DateRangeStart, dates.DateRangeEnd ) 126 138 127 139 numfilesproc += 1 128 140 141 else: 142 print "WARNING: File %s appears not to be XML. Will not be processed." %filename 129 143 130 print ' SpaceTimeIngestFromMOLES.py ran to end. files processed= %s' %(numfilesproc)144 print 'INFO: SpaceTimeIngestFromMOLES.py ran to end. files processed= %s' %(numfilesproc) 131 145 132 146 if __name__=='__main__':
Note: See TracChangeset
for help on using the changeset viewer.