Changeset 3909 for TI01-discovery


Ignore:
Timestamp:
19/05/08 17:14:53 (11 years ago)
Author:
cbyrom
Message:

Add default logger use to keywordAdder + tidy up code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI01-discovery/branches/ingestAutomation-upgrade/OAIBatch/keywordAdder.py

    r3865 r3909  
    2424        from ndgUtils.elementtree import cElementTree 
    2525import molesReadWrite as MRW 
    26 import sys 
    27 import os 
     26import sys, os, logging 
     27 
    2828 
    2929def PrettyPrint(elem,indent='',html=0,space='   '): 
     
    5757 
    5858    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 
    6061        sys.exit() 
    6162 
    62     print "INFO: moles records are in %s" %indir 
    63     print "INFO: moles records output to %s" %outdir 
    64     print "INFO: keywords to add are %s" %keywords 
     63    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) 
    6566 
    6667    # initialise variables 
     
    7172    count=0 
    7273    while count < len(keywords)/3: 
    73         #print "count = %s. keywordList = %s" %(count, keywordList) 
    7474        keywordList.append([]) 
    7575        keywordList[count].append(keywords[(count*3)]) 
     
    7777        keywordList[count].append(keywords[(count*3)+2]) 
    7878        count=count+1 
    79     #print "Final keywordList = %s" %keywordList 
    8079 
    8180    # moles skeleton for creating new objects 
     
    9695                    strParentListID=str(keyword[1]) 
    9796                    strTermID=str(keyword[2]) 
    98                     print strValidTerm, strParentListID, strTermID 
    9997                    dgVTID=M.dgValidTermID(ParentListID=strParentListID, TermID=strTermID) 
    10098                    dgSK=M.dgStructuredKeyword(dgValidTerm=strValidTerm, dgValidTermID=dgVTID) 
    10199                    dgMeta.dgMetadataRecord.addChildElem('dgStructuredKeyword', dgSK) 
    102      
     100 
    103101                # now write out updated document 
    104                 #print dir(dgMeta.dgMetadataRecord) 
    105102                molestree=dgMeta.toXML() 
    106103                moles=PrettyPrint(molestree) 
     
    109106                f.close() 
    110107                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) 
    113111                continue 
    114112 
    115113        else: 
    116             print "WARNING: File %s appears not to be XML. Will not be processed." %filename 
     114            logging.error("File %s appears not to be XML. Will not be processed." %filename) 
    117115 
    118     print 'INFO: keywordAdder.py ran to end. files processed= %s' %(numfilesproc) 
     116    logging.info('keywordAdder.py ran to end. files processed= %s' %(numfilesproc)) 
    119117 
    120118 
Note: See TracChangeset for help on using the changeset viewer.