Ignore:
Timestamp:
03/09/08 12:33:30 (12 years ago)
Author:
cbyrom
Message:

Pull out common constants into module level variables, to improve
consistency + re-use. Fix setting of some config file defaults.
Extend test suite + improve - add checks for config files and use
module level variables.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgUtils/ndgObject.py

    r4160 r4167  
    11import ndgRetrieve,xmlHandler2, logging 
    22 
     3# The various different document types: 
     4MOLES_DOC_TYPE = 'NDG-B0' 
     5DIF_DOC_TYPE = 'DIF' 
     6DC_DOC_TYPE = 'DC' 
     7ISO_DOC_TYPE = 'ISO19139' 
     8NDGB1_DOC_TYPE = 'NDG-B1' 
     9NDGB0_DOC_TYPE = 'NDG-B0' 
     10MDIP_DOC_TYPE = 'MDIP' 
     11NDGA0_DOC_TYPE = 'NDG-A0' 
     12NUMSIM_DOC_TYPE = 'NumSim' 
     13ATOM_DOC_TYPE = 'ATOM' 
     14ATOM_BACKUP_DOC_TYPE = 'ATOM-BACKUP' 
     15     
     16# Group the doc types according to the source they should be retrieved from 
     17DISCOVERY_SCHEMES = ['DIF','DC','MDIP','ISO19139', 'ISO'] 
     18BROWSE_SCHEMES = ['NDG-B0','NDG-B1','NumSim', 'ATOM', 'ATOM-BACKUP'] 
     19 
    320class ndgObject: 
    4     ''' This class instantiates an ndgObject which describes the various ways of obtaining itself, primarily 
     21    ''' This class instantiates an ndgObject which describes the various ways  
     22        of obtaining itself, primarily 
    523                (1) a downloadable xml representation from a repository, 
    624                (2) a printable xml representation ''' 
     
    6785        self.viewService='%s/view/'%server 
    6886        discoveryBASE='%s%s__%s__%s'%(self.viewService,self.repository,self.schema,self.localID) 
    69         fmt=self.config.get('DISCOVERY','formatDefault','DIF') 
     87 
     88        # set default return format - if not set, just return in original format 
     89        fmt='' 
     90        if self.config.has_option('DISCOVERY','formatDefault'): 
     91            fmt=self.config.get('DISCOVERY','formatDefault') 
     92            logging.info("Default discovery format set to: %s" %fmt) 
     93             
    7094        self.BURL=None 
    7195        # We'll build the following even if it can't be used (as would be the case for 
     
    7599        servicehost=self.config.get('NDG_B_SERVICE',self.repository,'unknown') 
    76100        # If this record is itself a discovery record, then we don't have much more to do 
    77         if self.schema in ['DIF','DC','MDIP','ISO19139']: 
     101        if self.schema in DISCOVERY_SCHEMES: 
    78102            self.xmlURL=self.__buildURL( 
    79103                discoveryBASE.replace('/view/','/retrieve/'),[qs,('format','raw')]) 
     
    81105            self.URL=self.discoveryURL 
    82106            if servicehost!='unknown':self.gettable=1 
    83         elif self.schema in ['NDG-B0','NDG-B1','NumSim']: 
     107        elif self.schema in BROWSE_SCHEMES: 
    84108            # One day we'll use a service binding to get this 
    85109            # This is a mapping from the ndg repository id to an actual repository id 
Note: See TracChangeset for help on using the changeset viewer.