Changeset 4037 for exist/trunk


Ignore:
Timestamp:
10/07/08 15:24:37 (11 years ago)
Author:
cbyrom
Message:

Add new keyword to DocumentRetrieve?, includeDocNameData - if this is
set to True, a dict is returned with the docname being the key and the
data being the value + also add some logging and tidy up logic.

Location:
exist/trunk/python/ndgUtils
Files:
2 edited

Legend:

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

    r4025 r4037  
    2424                           'NDG-B0':'moles','NDG-B1':'molesObjectType','MDIP':'moles2mdip'} 
    2525 
    26     def get(self,repository,schema,localID,targetCollection='/db/discovery/moles'): 
    27  
     26    def get(self,repository,schema,localID,targetCollection='/db/discovery/moles', includeDocNameData=False): 
     27        ''' 
     28        @keyword includeDocNameData: if True, a dictionary is returned, instead of the dataset, with the key 
     29        being the name of the document and the entry being the dataset 
     30        ''' 
     31        docName = "" 
    2832        if schema in ['NDG-A0', 'NumSim', 'G_ATOM']: 
    2933            ''' These documents are stored in their own native format and have their 
     
    3337            print xquery 
    3438            id,summary=self.executeQuery(xquery) 
    35             if summary['hits']==1: 
    36                 r=self.retrieve(id,0,{}) 
    37                 self.sessionRelease(id) 
    38             else: 
    39                 raise ValueError('Unable to obtain %s document [%s] (hits=%s)'%(schema,localID,summary['hits'])) 
     39            if summary['hits'] != 1: 
     40                raise ValueError('Unable to obtain single %s document [%s] (hits=%s)'%(schema,localID,summary['hits'])) 
     41 
     42            docName = summary['documents'][0][0] 
     43            r=self.retrieve(id,0,{}) 
     44            self.sessionRelease(id) 
     45            if includeDocNameData: 
     46                return {docName: r} 
    4047            return r 
    4148         
    4249        elif schema[0:5] == 'NDG-B' or schema in self.knownQueries: 
    43              
    4450            ''' These documents are stored in moles, and need to be converted or extracted 
    4551            directly ''' 
     
    5359                hits=summary['hits'] 
    5460             
    55                 if hits!=1: self.error('%s documents returned! '%hits,targetCollection,repository,'NDG-B0',localID) 
     61                if hits!=1:  
     62                    self.error('%s documents returned! '%hits,targetCollection,repository,'NDG-B0',localID) 
    5663             
    5764                # get output type  
     
    7885                self.error('Document Query returned [%s] hits'%hits,targetCollection,repository,schema,localID) 
    7986              
     87            docName = summary['documents'][0][0] 
    8088            # now let's get it and return it  
    8189            r=self.retrieve(id,0,{}) 
     
    8391            raise TypeError('Unknown Schema "%s" in URI'%schema) 
    8492        self.sessionRelease(id) 
     93        if includeDocNameData: 
     94            return {docName: r} 
    8595        return r 
     96     
     97     
    8698    def error(self,string,t,r,s,l): 
    8799        raise ValueError,string+' for %s:%s:%s in %s'%(r,s,l,t) 
  • exist/trunk/python/ndgUtils/eXistConnector.py

    r4025 r4037  
    11# Code inspired by example on eXist website. 
    2 import urllib2, base64, urllib, urlparse, httplib, xmlrpclib, types, os 
     2import urllib2, base64, urllib, urlparse, httplib, xmlrpclib, types, os, logging 
    33 
    44class InstanceObject(object): 
     
    117117    def createCollection(self,collectionPath): 
    118118        ''' Create a collection in the eXist database at collectionPath ''' 
     119        logging.info("Creating collection: '%s'" %collectionPath) 
    119120        r=self.xmlrpc.createCollection(collectionPath) 
     121        logging.info("Collection created") 
    120122        return r 
    121123     
Note: See TracChangeset for help on using the changeset viewer.