source: TI01-discovery/branches/ingestAutomation-upgrade/OAIBatch/ @ 3810

Subversion URL:
Revision 3810, 1.3 KB checked in by cbyrom, 13 years ago (diff)

Create Logger class to standardise output - and allow this to be
switched on/off with a verbose flag.
Implement the logger in several other classes + extend available logging in these.
Also, add a 'usage' method to oai_ingest_new to show proper usage of script.

1import sys
2from Logger import Logger
4class SchemaNameSpace:
5    '''
6    Class to change/correct namespaces to the latest ones used by NDG discovery
7    NB, only currently handles correction of DIF files
8    '''
9    def __init__(self,infile,outfile,format, logger):
10        '''
11        Constructor - with the logic to do the namespace change
12        @param infile: file to correct namespaces in
13        @param outfile: file to create with the corrected namespaces
14        @param format: Format of file being processed.  DIF is the only format which currently is processed.   
15        '''
16        self.ff=open(infile,'r')
17        self.ww=open(outfile,'w')
18        self.format= format
19        self.lines=self.ff.readlines()
20        for self.line in self.lines:
21            if self.format== "DIF" and self.line.startswith('<DIF'):
22                message = "INFO: changing line for %s. output to %s" %(infile,outfile)
23                if (logger is None):
24                    print message
25                else:
26                    logger.printOutput(message)
27                self.line='<DIF xmlns="" xmlns:xsi="">\n'
28            self.ww.write(self.line)
29        self.ff.close()
30        self.ww.close()
Note: See TracBrowser for help on using the repository browser.