Changeset 1821 for TI01-discovery


Ignore:
Timestamp:
05/12/06 17:27:45 (13 years ago)
Author:
selatham
Message:

error trapping

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI01-discovery/trunk/ingestAutomation/OAIBatch/SpaceTimeIngestFromMOLES.py

    r1809 r1821  
    3636def main(indir): 
    3737    if indir == "": 
    38         sys.exit("Usage: argument 1 = full path of directory where MOLES records reside") 
     38        sys.exit("USAGE: argument 1 = full path of directory where MOLES records reside") 
    3939    else: 
    4040        print "INFO: moles records are in %s" %indir 
    4141 
    4242#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'}) 
    4444    numfilesproc = 0 
    4545 
     
    4949                full_filename = indir + "/" + filename 
    5050                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 
    5466                coverage= [dates.DateRangeEnd, dates.DateRangeStart, bbox.LimitNorth, bbox.LimitSouth,bbox.LimitEast, bbox.LimitWest] 
    5567                #Mid = dgMeta.dgMetadataRecord.dgMetadataID.repositoryIdentifier+"__"+dgMeta.dgMetadataRecord.dgMetadataID.localIdentifier 
     
    6981                    float(west) 
    7082                except: 
    71                     print "Error: Will not process File %s. Contains incorrect West bounding box limit." %full_filename 
     83                    print "ERROR: Will not process File %s. Contains incorrect West bounding box limit." %full_filename 
    7284                    continue 
    7385                print "West = %s" %west 
     
    8496                    float(east) 
    8597                except: 
    86                     print "Error: Will not process File %s. Contains incorrect East bounding box limit." %full_filename 
     98                    print "ERROR: Will not process File %s. Contains incorrect East bounding box limit." %full_filename 
    8799                    continue 
    88100                print "East = %s" %east 
     
    99111                    float(north) 
    100112                except: 
    101                     print "Error: Will not process File %s. Contains incorrect North bounding box limit." %full_filename 
     113                    print "ERROR: Will not process File %s. Contains incorrect North bounding box limit." %full_filename 
    102114                    continue 
    103115                print "North = %s" %north 
     
    114126                    float(south) 
    115127                except: 
    116                     print "Error: Will not process File %s. Contains incorrect North bounding box limit." %full_filename 
     128                    print "ERROR: Will not process File %s. Contains incorrect North bounding box limit." %full_filename 
    117129                    continue 
    118130                print "North = %s" %south 
    119131 
    120132                if id_exists( Mid ): 
    121                         print "doc %s exists, updating\n" %Mid 
    122                         do_update( Mid, west, south, east, north, dates.DateRangeStart, dates.DateRangeEnd ) 
     133                    print "INFO: doc %s exists, updating\n" %Mid 
     134                    do_update( Mid, west, south, east, north, dates.DateRangeStart, dates.DateRangeEnd ) 
    123135                else: 
    124                         print "doc %s does not exist, inserting new record\n" %Mid 
    125                         do_insert( Mid, west, south, east, north, dates.DateRangeStart, dates.DateRangeEnd ) 
     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 ) 
    126138 
    127139                numfilesproc += 1 
    128140 
     141            else: 
     142                print "WARNING: File %s appears not to be XML. Will not be processed." %filename 
    129143 
    130     print 'SpaceTimeIngestFromMOLES.py ran to end. files processed= %s' %(numfilesproc) 
     144    print 'INFO: SpaceTimeIngestFromMOLES.py ran to end. files processed= %s' %(numfilesproc) 
    131145 
    132146if __name__=='__main__': 
Note: See TracChangeset for help on using the changeset viewer.