Changeset 2422 for TI07-MOLES


Ignore:
Timestamp:
20/04/07 08:12:11 (12 years ago)
Author:
lawrence
Message:

Code to support late binding to Browse service

Location:
TI07-MOLES/trunk/PythonCode/wsgi
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • TI07-MOLES/trunk/PythonCode/wsgi/DIF.py

    r2417 r2422  
    99from renderEntity import renderEntity 
    1010from ServiceBinding import DIFService 
     11from ndgObject import ndgObject 
    1112try: #python 2.5 
    1213    from xml.etree import ElementTree as ET 
     
    3637    note ... not a complete implementation, currently minimum to 
    3738    show a reasonable piece of content ''' 
    38     def __init__(self,xml,et=0,debug=0,ndgObject=None): 
     39    def __init__(self,xml,et=0,debug=0,ndgObj=None): 
    3940         
    4041        '''Initialise a python dif instance based on an xml document (expected 
     
    6162         
    6263        # if this is an ndgObject that'll have been sorted externally ... 
    63         self.ndgObject=ndgObject 
     64        self.ndgObject=ndgObj 
    6465         
    6566        # now try and interpret it  
     
    158159                 helper.getText(item,'URL'), 
    159160                 helper.getText(item,'Description') )) 
    160          
     161         
    161162        if self.ndgObject is None: 
    162163            self.binding=None 
     
    164165            if self.ndgObject.discoveryURL is not None: 
    165166                self.binding=DIFService('DISCOVERY',self.ndgObject.discoveryURL,'Discovery record') 
     167                #explicitly do late binding on NDG-B URL  
     168                #... and override contents in metadatarecord 
     169                print '1' 
     170                B='%s__%s__%s'%(self.ndgObject.repository,'NDG-B1',self.ndgObject.localID) 
     171                Bobject=ndgObject(B,config=self.ndgObject.config) 
     172                print '2' 
     173                bdone=0 
     174                if Bobject.gettable!=-1: 
     175                    for s in self.services: 
     176                        print '3 ',s.contentType 
     177                        if s.contentType=='NDG_B_SERVICE':  
     178                            s.url=Bobject.URL 
     179                            bdone=1 
     180                    print '4' 
     181                    if not bdone: self.services.append( 
     182                                DIFService('NDG_B_SERVICE',Bobject.URL,'NDG Browse Metadata Service')) 
    166183            else: self.binding=None 
    167  
     184            print '5' 
    168185        if self.debug: 
    169186           f=open('difs.log','a') 
  • TI07-MOLES/trunk/PythonCode/wsgi/DiscoveryGUI.py

    r2417 r2422  
    139139                    obj.setConfig(self.config) 
    140140                    try: 
    141                         difs.append(DIF(result[1],ndgObject=obj)) 
     141                        difs.append(DIF(result[1],ndgObj=obj)) 
    142142                    except ValueError,e: 
    143                         errors.append((result[0],e)) 
     143                        errors.append((result[0],str(e))) 
    144144                if results==[]: 
    145145                    self.html+='<p>No results for "%s"!</p>'%searchString 
  • TI07-MOLES/trunk/PythonCode/wsgi/ndgDiscovery.config

    r2380 r2422  
    7575# needs to be mapped into a specific server ... 
    7676badc.nerc.ac.uk: chinook.badc.rl.ac.uk 
     77neodc.nerc.ac.uk: chinook.badc.rl.ac.uk 
    7778bodc.nerc.ac.uk: BODC-dummyHost 
    7879grid.bodc.nerc.ac.uk: BODC-dumyHOST-G 
  • TI07-MOLES/trunk/PythonCode/wsgi/ndgObject.py

    r2380 r2422  
    66     
    77    def __init__(self,uri,config=None): 
    8              
    9         ''' Instantiate an ndg URI, and potentially methods for retrieving documents described by this URI. 
    10          
    11         If discoveryOriginal is set, then it indicates that the URI provided corresponds to an original 
    12         URI which can be obtained both from the original database, and via transformation from the  
    13         intermediate schema (aka mini-moles) database ''' 
     8        ''' Instantiate an ndg URI, and potentially methods for retrieving documents described by this URI 
     9        if a config file is available.  Three default views should be available: 
     10            (1) a rendered html version 
     11            (2) a downloadable xml representation, and 
     12            (3) a printable xml version. 
     13        Real services should also be available, and at some point of course the services should be looked up  
     14        at a service registry, but that's not yet available. ''' 
    1415         
    15         bits=uri.split(':') 
     16        self.gettable=-1  # The specific record is not known to be gettable via any service 
     17                          # other values of gettable allowed are  
     18                          # 0: browseable, 1: discoverable  
     19                           
     20        # handle all the known ways of doing an NDG URI ... 
     21        bits=uri.split(':') 
    1622        bits2=uri.split('__') 
    1723        ok=1 
     
    3743            else: ok=0 
    3844        if not ok: 
     45            # after all that, we don't think it's an NDG URI ... 
    3946            raise ValueError,'URI [%s] is not a valid NDG style URI'%uri 
    4047        else: 
     48            # yes, it is an NDG URI ... 
    4149            self.repository,self.schema,self.localID=repository,schema,localID 
    4250        self.setConfig(config) 
     
    4553        ''' Set up the configuration for retrieving this document ''' 
    4654        if config is None: 
    47             self.gettable=-1 
    4855            self.discoveryURL,self.baseURL,self.xmlURL,self.printableURL=None,None,None,None 
    4956        else: 
    5057            self.config=config 
    51             # this NDG object may itself be a discovery record, which makes life easy, but 
     58            # This NDG object may itself be a discovery record, which makes life easy, but 
    5259            # it might not be, in which case we have to build up all the possible views upon it. 
    5360            discoveryBASE='%s&uri=%s__%s__%s'%( 
    5461                self.config.get('DISCOVERY','default'),self.repository,self.schema,self.localID) 
    5562            fmt=self.config.get('DISCOVERY','formatDefault','DIF') 
     63            # We'll build the following even if it can't be used (as would be the case for 
     64            # a non data entity B record or an A record) because it's a useful template. 
    5665            self.discoveryURL=discoveryBASE+'&format=%s&type=html'%fmt 
    5766            # If this record is itself a discovery record, then we don't have much more to do 
     
    6271                self.URL=self.discoveryURL 
    6372            elif self.schema in ['NDG-B0','NDG-B1']: 
    64                 #one day we'll use a service binding to get this 
    65                 #this is a mapping from the ndg repository id to an actual repository id 
    66                 #understood by the ndg exist interface 
     73                # One day we'll use a service binding to get this 
     74                # This is a mapping from the ndg repository id to an actual repository id 
     75                # understood by the ndg exist interface 
    6776                repository=self.config.get('NDG_B_SERVICE',self.repository,'Unknown-B-Repository') 
    6877                url=self.discoveryURL.replace('ndg',repository) 
     
    7079                self.xmlURL=self.URL.replace('html','xml') 
    7180                self.printableURL=self.URL.replace('html','print') 
    72                 self.gettable=0 
     81                if repository!='Unknown-B-Repository': self.gettable=0 
    7382            else: 
    7483                #currently we don't know how to get this one 
    75                 self.gettable=-1 
    7684                self.URL='unknown' 
    7785                self.discoveryURL,self.baseURL,self.xmlURL,self.printableURL=None,None,None,None 
     86                 
     87        #now, we'll build a stub-B url as well, in cae that comes in handy  
    7888        if self.gettable<>-1: 
    7989            if self.schema<>'NDG-B1': 
  • TI07-MOLES/trunk/PythonCode/wsgi/ndgRetrieve.py

    r2386 r2422  
    4141        self.renderer=renderEntity(self.config) 
    4242         
    43     def get(self,xml,format,otype='html',ndgObject=None): 
     43    def get(self,xml,format,otype='html',ndgObj=None): 
    4444        if otype=='html': 
    4545            if format=='DIF': 
    46                 r=DIF(xml,ndgObject=ndgObject) 
     46                r=DIF(xml,ndgObj=ndgObj) 
    4747            elif format=='NDG-B1': 
    4848                r=stubB(xml,self.config) 
     
    159159        if outputType!='xml':  
    160160            if debug: 
    161                 r=self.shower.get(r,format,otype=outputType,ndgObject=self.uri) 
     161                r=self.shower.get(r,format,otype=outputType,ndgObj=self.uri) 
    162162            else: 
    163163                try: 
    164                     r=self.shower.get(r,format,otype=outputType,ndgObject=self.uri) 
     164                    r=self.shower.get(r,format,otype=outputType,ndgObj=self.uri) 
    165165                except Exception,e: 
    166166                    r='<p> Unable to show document, reason was [%s]<p>'%e 
  • TI07-MOLES/trunk/PythonCode/wsgi/renderService.py

    r2330 r2422  
    5555        obj=ndgObject(testURI) 
    5656        obj.setConfig(con) 
    57         d=DIF(r,ndgObject=obj) 
     57        d=DIF(r,ndgObj=obj) 
    5858        for s in d.services: 
    5959            h=renderService(con) 
  • TI07-MOLES/trunk/PythonCode/wsgi/stubB.py

    r2392 r2422  
    158158                self.config=config 
    159159                self.citation='' 
     160                self.personnel=[] # for DIF compatiability for the moment. 
    160161                 
    161162                try: 
Note: See TracChangeset for help on using the changeset viewer.