casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
regression_utility.py
Go to the documentation of this file.
00001 import string
00002 import inspect
00003 import sys
00004 import os
00005 import shutil
00006 
00007 a=inspect.stack()
00008 stacklevel=0
00009 for k in range(len(a)):
00010     if (string.find(a[k][1], 'ipython console') > 0):
00011         stacklevel=k
00012 myf=sys._getframe(stacklevel).f_globals
00013 casalog=myf['casalog']
00014 
00015 #
00016 # Utils
00017 #
00018 def note(message, priority="INFO", origin="regression_utility", ntime=None, postcli='F'):
00019     #if not ntime:  #if (ntime==None):
00020     #    ntime=time.asctime()
00021     #print ntime, priority, origin, message
00022     if postcli: print message
00023     casalog.postLocally(message, priority, origin)
00024 ###
00025 def info(message):
00026     #note(message,origin='regression_utility')
00027     #print message
00028     casalog.postLocally(message, priority="INFO", origin="regression_utility")
00029 
00030 def fail(message=""):
00031     casalog.postLocally(message, priority="SEVERE", origin='regression_utility')
00032     #print message
00033     raise RuntimeError, message
00034 
00035 ###
00036 def stop(message=""):
00037     note(message ,priority='SEVERE', origin='regression_utility')
00038     raise RuntimeError, message
00039 
00040 ###
00041 def cleanup(dir):
00042     if (os.path.isdir(dir)):
00043         info("Cleaning up directory "+dir)
00044         def errFunc(raiser, problemPath, excInfo):
00045             #print raiser.__name__,'failed on',problemPath
00046             note(raiser.__name__+'failed on'+problemPath,"SEVERE")
00047             raise RuntimeError, "Cleanup of " + dir + " fails!"
00048         shutil.rmtree(dir,0,errFunc)
00049     return True
00050 
00051 ###
00052 def maketestdir(testdir):
00053     if not cleanup(testdir):
00054         note("Cleanup of "+testdir+" failed","SEVERE")
00055         return False
00056     try:
00057         os.mkdir(testdir)
00058     except IOError, e:
00059         note(e, "SEVERE")
00060         raise RuntimeError, "mkdir " + testdir + " fails!"