Changeset 4483 for exist


Ignore:
Timestamp:
24/11/08 09:53:38 (11 years ago)
Author:
cbyrom
Message:

Add schemas to ndgXqueries object and add method to retrieve these + tidy up logic in a few other scripts.

Location:
exist/trunk
Files:
5 edited

Legend:

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

    r4430 r4483  
    113113         
    114114        logging.info("Executing xquery search") 
     115        logging.debug(" - query: '%s'" %xquery) 
    115116        r=self.executeChunkedQuery(str(xquery),start,howmany) 
    116117        logging.info("Search complete - processing results") 
  • exist/trunk/python/ndgUtils/models/existdbclient.py

    r4433 r4483  
    310310        colData = {} 
    311311        for member in et: 
    312             col = member.findtext('{http://www.w3.org/2005/Atom}fileName') 
    313             key = data.split('/')[-1] 
    314             key = key.split('.')[0] 
    315             val = '/'.join(data.split('/')[0:-1]) 
    316             colData[key] = val 
     312            collection = member.findtext('{http://www.w3.org/2005/Atom}fileName') 
     313            fileName = collection.split('/')[-1] 
     314            fileName = fileName.split('.')[0] 
     315            dir = '/'.join(collection.split('/')[0:-1]) 
     316            colData[fileName] = dir 
    317317 
    318318        logging.debug("Finished looking up atom paths") 
  • exist/trunk/python/ndgUtils/ndgObject.py

    r4430 r4483  
    106106 
    107107        # set default return format - if not set, just return in original format 
    108         fmt='' 
    109         if self.config.has_option('DISCOVERY','formatDefault'): 
    110             fmt=self.config.get('DISCOVERY','formatDefault') 
     108        fmt = self.config.get('DISCOVERY','formatDefault') 
     109        if fmt: 
    111110            logging.info("Default discovery format set to: %s" %fmt) 
    112111             
     
    120119        # config file should have details on the service to use for the repository 
    121120        # - if not, default to 'unknown' 
    122         servicehost = 'unknown' 
    123         if self.config.has_option('NDG_B_SERVICE',self.repository): 
    124             servicehost=self.config.get('NDG_B_SERVICE',self.repository) 
     121        servicehost = self.config.get('NDG_B_SERVICE',self.repository) 
     122        if not servicehost: 
     123            servicehost = 'unknown' 
    125124             
    126125        # If this record is itself a discovery record, then we don't have much more to do 
     
    130129            self.printableURL=self.__buildURL(discoveryBASE,[qs,('format','xml')]) 
    131130            self.URL=self.discoveryURL 
    132             if servicehost!='unknown':self.gettable=1 
     131            if servicehost != 'unknown': 
     132                self.gettable=1 
    133133        elif self.schema in self.BROWSE_SCHEMES: 
    134134            # One day we'll use a service binding to get this 
     
    141141            self.xmlURL=url.replace('/view/','/retrieve/')+'?format=raw' 
    142142            self.printableURL=url+'?format=xml' 
    143             if servicehost!='unknown': self.gettable=0 
     143            if servicehost !='unknown':  
     144                self.gettable=0 
    144145            self.useDiscoveryService = 0 
    145146        else: 
  • exist/trunk/python/ndgUtils/ndgXqueries.py

    r3840 r4483  
    22import re 
    33class ndgXqueries(object): 
    4     ''' Holds a set of ndg xqueries after having read them from disk (which is 
     4    '''  
     5    Holds a set of ndg xqueries after having read them from disk (which is 
    56    done in order to share the xqueries amongst different applications and  
    6     programming languages). ''' 
     7    programming languages).  
     8    ''' 
     9    ATOM_MOLES_SCHEMA = "molesAtom1.0" 
    710    def __init__(self,directory='xquery'): 
    811        ''' Loads up xqueries from the internal package directory ''' 
     
    1013        # this next bit to get rid of .svn and anything else in testing 
    1114        xq=[] 
     15        xsd = [] 
    1216        for f in files: 
    13             if f.find('.xq')!=-1: xq.append(f) 
     17            if f.find('.xq') != -1:  
     18                xq.append(f) 
     19            elif f.find('.xsd') != -1: 
     20                xsd.append(f) 
     21                 
    1422        #remember that .rstrip doesn't quite do what you think it does :-) 
    15         self.xq=dict([(re.sub('.xq\Z','',f),pkg_resources.resource_string('ndgUtils','%s/%s'%(directory,f))) for f in xq]) 
     23        self.xq = dict([(re.sub('.xq\Z','',f),\ 
     24                       pkg_resources.resource_string('ndgUtils','%s/%s'%(directory,f))) for f in xq]) 
     25        self.xsd = dict([(re.sub('.xsd\Z','',f),\ 
     26               pkg_resources.resource_string('ndgUtils',\ 
     27                                             '%s/%s'%(directory, f))) for f in xsd]) 
    1628         
    1729        # add the various xquery libraries, too 
     
    2436                    continue 
    2537 
    26                 #re.sub('.xquery\Z','',f)] = \ 
    2738                self.xqlib[f] = pkg_resources.resource_string('ndgUtils','%s/%s'%(dir,f)) 
    28              
     39         
    2940    def __setitem__(self,key,value): 
    3041        ''' Add a new xquery to the xquery database dynamically''' 
     
    3344        ''' Given a key, return an xquery ''' 
    3445        return self.xq[key] 
     46     
     47    def getSchema(self, schemaName): 
     48        ''' 
     49        Return the specified schema 
     50        @param schemaName: Name of schema to retrieve - NB, use the class constants to specify the schemaName 
     51        - e.g. self.ATOM_MOLES_SCHEMA 
     52        @return: schema in string format 
     53        ''' 
     54        schema =  self.xsd.get(schemaName) 
     55        if not schema: 
     56            raise ValueError("Unrecognised schema, '%s'" %schemaName) 
     57         
     58        return schema 
     59         
     60         
    3561    def keys(self): 
    3662        ''' Return a list of all the xqueries loaded into this instance ''' 
  • exist/trunk/xquery/moles2.0.xsd

    r4426 r4483  
    44        xmlns:moles="http://ndg.nerc.ac.uk/schema/moles2beta" 
    55        xmlns:atom="http://www.w3.org/2005/Atom" > 
    6         <xs:import namespace="http://www.w3.org/2005/Atom" schemaLocation="file:///home/cbyrom/eclipseWorkspace/ndgUtils-trunk/xquery/atom1.0.xsd" /> 
     6        <xs:import namespace="http://www.w3.org/2005/Atom" schemaLocation="atom1.0.xsd" /> 
    77        <xs:annotation> 
    88                <xs:documentation> 
Note: See TracChangeset for help on using the changeset viewer.