Go to the documentation of this file.00001 """
00002 Functions used in converting other functions into tasks.
00003
00004 Use: import taskutil
00005 """
00006
00007 import inspect, string, sys
00008
00009 def get_global_namespace(ns_label='ipython console'):
00010 """
00011 Returns a dictionary of the globals in the lowest stacklevel containing
00012 ns_label in its label.
00013 """
00014 a=inspect.stack()
00015 stacklevel=0
00016 for k in range(len(a)):
00017 if (string.find(a[k][1], 'ipython console') > 0):
00018 stacklevel=k
00019
00020 return sys._getframe(stacklevel).f_globals
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 def check_param_types(taskname, arg_desc):
00042 """
00043 Checks the values of taskname's arguments against their allowed types.
00044 Suitable for tasks without any menu parameters.
00045 Returns None if everything seems OK, and the exception otherwise (after
00046 printing an error message).
00047 """
00048 e = None
00049 arg_names = arg_desc.keys()
00050 arg_values=[]
00051 arg_types =[]
00052 for arg in arg_names:
00053 arg_values.append(arg_desc[arg][0])
00054 arg_types.append(arg_desc[arg][1])
00055 try:
00056 parameter_checktype(arg_names, arg_values, arg_types)
00057 except TypeError, e:
00058 print taskname, "-- TypeError: ", e
00059 except ValueError, e:
00060 print taskname, " -- OptionError: ", e
00061 return e
00062
00063 def startlog(casalog, taskname):
00064 """
00065 Starts an entry in casalogger for taskname.
00066 """
00067 casalog.origin(taskname)
00068 casalog.post('')
00069 casalog.post('###############################################')
00070 casalog.post('### Begin Task: ' + taskname + ' ' * (27 - len(taskname)) + '###')
00071 return
00072
00073 def endlog(casalog, taskname):
00074 """
00075 Finishes an entry in casalogger for taskname.
00076 """
00077 casalog.post('### End of task: ' + taskname + ' ' * (29 - len(taskname)) + '###')
00078 casalog.post('###############################################')
00079 casalog.post('')
00080 return