Package wsatools :: Package DbConnect :: Module CuSession
[hide private]

Module CuSession

source code

Curation session. Provides a class design framework that performs all the actions necessary of any data curation activity for the archive where a log is required to be recorded. Also provides a framework for updating the database correctly. All curation tasks should inherit from this class.

Usage

Inheriting from CuSession

Simplest, basic design (see CuSession class documentation for explanation of individual aspects):

 from wsatools.CLI                 import CLI
 from wsatools.DbConnect.CuSession import CuSession
 from wsatools.Logger              import Logger

 class MyCu33(CuSession):
     ''' The first sentence of this description should describe the
         script's purpose for the command-line interface help screen, and
         thus be written with the mandatory arguments in context.
     '''
     # Override these parameters if defaults not satisfactory
     cuNum = 33
     _autoCommit = True
     _useWorkDir = True
     _cleanUpDir = True

     def _onRun(self):
         ''' Tasks this CU performs.
         '''
         # perform tasks

 # Executing script
 cli = CLI(MyCu33.__name__, "$Revision: 9646 $", MyCu33.__doc__)
 Logger.addMessage(cli.getProgDetails())
 cu = MyCu33(cli=cli)
 cu.run()

Individual curation tasks that inherit this class should override the _onRun() method to define their behaviour, and then invoke the CuSession.run() method to perform the curation task, which performs the exception handling for _onRun(). Override _onException() to perform tidy-up tasks following an exception. For example, to prevent files on the catalogue load server share directory from being deleted on curation failure then override the _onException() set the shareFileID member variable to None:

 def _onException(self):
     CuSession._onException(self)
     self.shareFileID = None

If the task has a mandatory arguments then these should be defined by overriding the constructor. Always call the CuSession.__init__() method first, and expand upon its interface.

Programme curation considerations

If curating a single programme then initialise the curation session with that programme's ID. For curating multiple programmes add programmeIDs to the programmeID member variable at the appropriate time somewhere within the _onRun() method, e.g.:

 def _onRun(self):
     self.programmeID.add(101)

If you don't wish for the ProgrammeCurationHistory to be ever updated on curation failure, even with success=no flags, then override the _onException() method to reset the programmeID member variable:

 def _onException(self):
     CuSession._onException(self)
     self.programmeID = set()

Author: R.S. Collins

Organization: WFAU, IfA, University of Edinburgh

Warning: If a CuError is thrown the ACH is not updated, but the log-file is still written. On the next run this log-file will be overwritten, unless the log-file mode is append (like for parallel CUs) - which could be confusing, might be a good idea to change this behaviour...

To Do: Should the success flag be in ACH, and the PCH not updated at all if rolledback = True, in all cases?

Classes [hide private]
  CuSession
A curation session.
Variables [hide private]
  __package__ = 'wsatools.DbConnect'