Changeset 3909 for TI01-discovery
- Timestamp:
- 19/05/08 17:14:53 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
TI01-discovery/branches/ingestAutomation-upgrade/OAIBatch/keywordAdder.py
r3865 r3909 24 24 from ndgUtils.elementtree import cElementTree 25 25 import molesReadWrite as MRW 26 import sys 27 import os 26 import sys, os, logging 27 28 28 29 29 def PrettyPrint(elem,indent='',html=0,space=' '): … … 57 57 58 58 if (len(keywords))%3 != 0: 59 print "Keywords must be in triples. keyword namespace key." 59 print "ERROR: Keywords must be in triples: keyword namespace key." 60 print "Actual: ", keywords 60 61 sys.exit() 61 62 62 print "INFO: moles records are in %s" %indir63 print "INFO: moles records output to %s" %outdir64 print "INFO: keywords to add are %s" %keywords63 logging.info("moles records are in %s" %indir) 64 logging.info("moles records output to %s" %outdir) 65 logging.info("keywords to add are %s" %keywords) 65 66 66 67 # initialise variables … … 71 72 count=0 72 73 while count < len(keywords)/3: 73 #print "count = %s. keywordList = %s" %(count, keywordList)74 74 keywordList.append([]) 75 75 keywordList[count].append(keywords[(count*3)]) … … 77 77 keywordList[count].append(keywords[(count*3)+2]) 78 78 count=count+1 79 #print "Final keywordList = %s" %keywordList80 79 81 80 # moles skeleton for creating new objects … … 96 95 strParentListID=str(keyword[1]) 97 96 strTermID=str(keyword[2]) 98 print strValidTerm, strParentListID, strTermID99 97 dgVTID=M.dgValidTermID(ParentListID=strParentListID, TermID=strTermID) 100 98 dgSK=M.dgStructuredKeyword(dgValidTerm=strValidTerm, dgValidTermID=dgVTID) 101 99 dgMeta.dgMetadataRecord.addChildElem('dgStructuredKeyword', dgSK) 102 100 103 101 # now write out updated document 104 #print dir(dgMeta.dgMetadataRecord)105 102 molestree=dgMeta.toXML() 106 103 moles=PrettyPrint(molestree) … … 109 106 f.close() 110 107 numfilesproc += 1 111 except: 112 print "WARNING: Cannot parse the XML moles document %s. Will not process" %full_filename 108 except Exception, detail: 109 logging.error("Cannot parse the XML moles document %s. Will not process" %full_filename) 110 logging.error("Detail: %s" %detail) 113 111 continue 114 112 115 113 else: 116 print "WARNING: File %s appears not to be XML. Will not be processed." %filename114 logging.error("File %s appears not to be XML. Will not be processed." %filename) 117 115 118 print 'INFO: keywordAdder.py ran to end. files processed= %s' %(numfilesproc)116 logging.info('keywordAdder.py ran to end. files processed= %s' %(numfilesproc)) 119 117 120 118
Note: See TracChangeset
for help on using the changeset viewer.