Changes between Initial Version and Version 1 of MOLES/dirupload,


Ignore:
Timestamp:
17/11/08 15:52:57 (12 years ago)
Author:
lawrence
Comment:

sample MOLES uploading code

Legend:

Unmodified
Added
Removed
Modified
  • MOLES/dirupload,

    v1 v1  
     1== Simple MOLES upload == 
     2 
     3The following code fragment can be used to upload an entire directory of MOLES documents into eXist. 
     4{{{ 
     5#!python 
     6# 
     7# Simple Routine to load a directory of files into a specific eXist Collection 
     8# 
     9import os 
     10from ndgUtils.eXistInterface import ndg_eXist 
     11 
     12def loadCollection(dirName,collectionName,db='chinook.badc.rl.ac.uk'): 
     13    '''walk a directory, load a document ''' 
     14    xmldb=ndg_eXist(db=db) 
     15    for root,dirs,files in os.walk(dirName): 
     16        for n in files: 
     17            print n 
     18            f=open(os.path.join(dirName,n),'r') 
     19            doc=f.read() 
     20            path='/'.join([collectionName,n]) 
     21            try: 
     22                r=xmldb.storeXML(doc,path) 
     23            except Exception,e: 
     24                print str(e) 
     25if __name__=="__main__": 
     26    import sys 
     27    collection,directory=tuple(sys.argv[1:]) 
     28    print 'Storing %s into collection %s'%(directory,collection) 
     29    loadCollection(directory,collection) 
     30}}}