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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI01-discovery/branches/ingestAutomation-upgrade/OAIBatch/SchemaNameSpace.py@3810
Revision 3810, 1.3 KB checked in by cbyrom, 12 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.

Line 
1import sys
2from Logger import Logger
3
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="http://gcmd.gsfc.nasa.gov/Aboutus/xml/dif/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\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.