Changeset 4590


Ignore:
Timestamp:
11/12/08 09:46:37 (11 years ago)
Author:
cbyrom
Message:

Add new class to allow eXist doc backups to be done in a separate,
asynchronous thread + add debug keyword to allow more detailed output
from schema validation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgUtils/lib/existdbclient.py

    r4580 r4590  
    1919        import elementtree.ElementTree as ET 
    2020 
     21from threading import Thread 
     22 
     23class backingUpThread(Thread): 
     24     
     25   def __init__ (self, existClient, doc, collection, fileName): 
     26       logging.info("Setting up thread to run backup for file, '%s'" %fileName) 
     27       Thread.__init__(self) 
     28       self.ec = existClient 
     29       self.doc = doc 
     30       self.collection = collection 
     31       self.fileName = fileName 
     32       logging.info("- finished setting up thread") 
     33       
     34   def run(self): 
     35       logging.info("Running thread to perform backup of file, '%s'" %self.fileName) 
     36       self.ec.createEXistFile(self.doc, self.collection, self.fileName) 
     37       logging.info("- finished backing up file") 
     38         
     39 
    2140class eXistDBClient: 
    2241     
     
    102121         
    103122 
    104     def checkAtomSchemaCompliance(self, atomPath, atom = None): 
     123    def checkAtomSchemaCompliance(self, atomPath, atom = None, isDebug = False): 
    105124        ''' 
    106125        Validate the specified atom in eXist with the atom schemae in eXist 
     
    109128        - since it may not already exist there.  Once validation is completed, the 
    110129        file will be removed from eXist. 
     130        @keyword isDebug: if True, return full error details, otherwise only return 
     131        a summary 
    111132        @return array: containing any errors found - NB, if an empty array is returned, 
    112133        this indicates successful validation 
     
    151172                level = error.attrib.get('level') 
    152173                repeat = error.attrib.get('repeat') 
    153                 errorMessage = "%s at line %s, column %s: %s" %(level, lineNo, colNo, error.text) 
     174                errorText = error.text 
     175                # remove the meaningless error type from message 
     176                if errorText.startswith('cvc-'): 
     177                    errorText = ':'.join(errorText.split(':')[1:]) 
     178                errorMessage = "%s at line %s, column %s: %s" %(level, lineNo, colNo, errorText) 
    154179                if repeat: 
    155180                    errorMessage += " (%s times)" %repeat 
    156                 # only return basic error message to users - the log file will contain the full error 
    157                 errors.append(error.text)#errorMessage) 
     181 
     182                if isDebug: 
     183                    errors.append(errorMessage) 
     184                else: 
     185                    errors.append(errorText) 
    158186                logging.info(errorMessage) 
    159187        else: 
     
    254282    def isNewEXistFile(self, docPath): 
    255283        ''' 
    256         Backup a file that exists in the eXist DB 
    257         @param docPath: path of file in eXist to backup 
     284        Test if a file already exists in eXist 
     285        @param docPath: path of file in eXist to look up 
     286        @return: True if a new file, False if otherwise 
    258287        ''' 
    259288        logging.info("Checking if file, '%s', exists in eXist DB" %docPath) 
     
    286315        - NB, this really just creates a new file with the same contents in a  
    287316        backup dir 
     317        - to improve efficiency, spawn this process as a new thread since we 
     318        don't need to worry about the outcome 
    288319        @param collection: path of the collection to store the file in 
    289320        @param fileName: name of file to add in eXist 
     
    310341        fileName = self.__addTimeStamp(fileName) 
    311342        docPath = collection + fileName 
    312  
    313         logging.debug("Now creating backup file, '%s'" %fileName) 
    314         self.createEXistFile(doc, collection, fileName) 
    315          
    316         logging.info("File backed up in eXist") 
     343         
     344        # run the back up in a separate thread 
     345        thread = backingUpThread(self, doc, collection, fileName) 
     346        thread.start() 
     347 
    317348        return docPath 
    318349 
Note: See TracChangeset for help on using the changeset viewer.