casa
$Rev:20696$
|
00001 # 00002 # This file was generated using xslt from its XML file 00003 # 00004 # Copyright 2008, Associated Universities Inc., Washington DC 00005 # 00006 import sys 00007 import os 00008 from casac import * 00009 import string 00010 import time 00011 import inspect 00012 import gc 00013 import numpy 00014 from odict import odict 00015 from task_find import find 00016 from task_find import casalog 00017 00018 class find_pg_: 00019 __name__ = "find" 00020 00021 def __init__(self) : 00022 self.__bases__ = (find_pg_,) 00023 self.__doc__ = self.__call__.__doc__ 00024 00025 00026 def __call__(self, matchstring=None, async=None): 00027 00028 """Find string in tasks, task names, parameter names: 00029 00030 Find string in tasks, task names, parameter names: 00031 00032 Lists the following: 00033 1) All of the task names that have the string 00034 2) All of the tasks whose contents (e.g., documentation, 00035 parameters, etc) have the string 00036 3) All of the parameter names that have the string 00037 00038 Keyword arguments: 00039 matchstring -- String to match in the documentation 00040 default: ''; example: matchstring='vis' 00041 00042 """ 00043 a=inspect.stack() 00044 stacklevel=0 00045 for k in range(len(a)): 00046 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00047 stacklevel=k 00048 break 00049 myf=sys._getframe(stacklevel).f_globals 00050 myf['__last_task'] = 'find' 00051 myf['taskname'] = 'find' 00052 ### 00053 myf['update_params'](func=myf['taskname'],printtext=False) 00054 ### 00055 ### 00056 #Handle globals or user over-ride of arguments 00057 # 00058 function_signature_defaults=dict(zip(self.__call__.func_code.co_varnames,self.__call__.func_defaults)) 00059 useLocalDefaults = False 00060 00061 for item in function_signature_defaults.iteritems(): 00062 key,val = item 00063 keyVal = eval(key) 00064 if (keyVal == None): 00065 #user hasn't set it - use global/default 00066 pass 00067 else: 00068 #user has set it - use over-ride 00069 if (key != 'self') : 00070 useLocalDefaults = True 00071 #myf[key]=keyVal 00072 00073 myparams = {} 00074 if useLocalDefaults : 00075 for item in function_signature_defaults.iteritems(): 00076 key,val = item 00077 keyVal = eval(key) 00078 exec('myparams[key] = keyVal') 00079 if (keyVal == None): 00080 exec('myparams[key] = '+ key + ' = self.itsdefault(key)') 00081 keyVal = eval(key) 00082 if(type(keyVal) == dict) : 00083 exec('myparams[key] = ' + key + ' = keyVal[len(keyVal)-1][\'value\']') 00084 00085 else : 00086 uselessvariable = None 00087 myparams['matchstring'] = matchstring = myf['matchstring'] 00088 00089 00090 result = None 00091 00092 # 00093 # The following is work around to avoid a bug with current python translation 00094 # 00095 mytmp = {} 00096 00097 mytmp['matchstring'] = matchstring 00098 pathname='file:///'+os.environ.get('CASAPATH').split()[0]+'/share/xml/' 00099 trec = casac.utils().torecord(pathname+'find.xml') 00100 00101 casalog.origin('find') 00102 if not trec.has_key('find') or not casac.utils().verify(mytmp, trec['find']) : 00103 return False 00104 00105 00106 try : 00107 casalog.post('') 00108 casalog.post('##########################################') 00109 casalog.post('##### Begin Task: find #####') 00110 casalog.post('') 00111 result = find(matchstring) 00112 casalog.post('') 00113 casalog.post('##### End Task: find #####') 00114 casalog.post('##########################################') 00115 00116 00117 # saveinputs for individule engine has no use 00118 # saveinputs should alos be removed from casa_in_py.py 00119 # 00120 # 00121 # saveinputs = myf['saveinputs'] 00122 # saveinputs('find', 'find.last', myparams) 00123 # 00124 # 00125 except Exception, instance: 00126 #print '**** Error **** ',instance 00127 pass 00128 00129 gc.collect() 00130 return result 00131 # 00132 # 00133 ## 00134 # def paramgui(self, useGlobals=True): 00135 # """ 00136 # Opens a parameter GUI for this task. If useGlobals is true, then any relevant global parameter settings are used. 00137 # """ 00138 # import paramgui 00139 # 00140 # a=inspect.stack() 00141 # stacklevel=0 00142 # for k in range(len(a)): 00143 # if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00144 # stacklevel=k 00145 # break 00146 # myf = sys._getframe(stacklevel).f_globals 00147 # 00148 # if useGlobals: 00149 # paramgui.setGlobals(myf) 00150 # else: 00151 # paramgui.setGlobals({}) 00152 # 00153 # paramgui.runTask('find', myf['_ip']) 00154 # paramgui.setGlobals({}) 00155 # 00156 # 00157 # 00158 # 00159 def defaults(self, param=None): 00160 a=inspect.stack() 00161 stacklevel=0 00162 for k in range(len(a)): 00163 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00164 stacklevel=k 00165 break 00166 myf=sys._getframe(stacklevel).f_globals 00167 a = odict() 00168 a['matchstring'] = '' 00169 00170 a['async']=False 00171 00172 ### This function sets the default values but also will return the list of 00173 ### parameters or the default value of a given parameter 00174 if(param == None): 00175 myf['__set_default_parameters'](a) 00176 elif(param == 'paramkeys'): 00177 return a.keys() 00178 else: 00179 if(a.has_key(param)): 00180 #if(type(a[param]) == dict) : 00181 # return a[param][len(a[param])-1]['value'] 00182 #else : 00183 return a[param] 00184 00185 00186 # 00187 # 00188 def check_params(self, param=None, value=None): 00189 a=inspect.stack() 00190 stacklevel=0 00191 for k in range(len(a)): 00192 if (string.find(a[k][1], 'ipython console') > 0) or (string.find(a[k][1], '<string>') >= 0): 00193 stacklevel=k 00194 break 00195 myf=sys._getframe(stacklevel).f_globals 00196 00197 # print 'param:', param, 'value:', value 00198 try : 00199 if str(type(value)) != "<type 'instance'>" : 00200 value0 = value 00201 value = myf['cu'].expandparam(param, value) 00202 matchtype = False 00203 if(type(value) == numpy.ndarray): 00204 if(type(value) == type(value0)): 00205 myf[param] = value.tolist() 00206 else: 00207 #print 'value:', value, 'value0:', value0 00208 #print 'type(value):', type(value), 'type(value0):', type(value0) 00209 myf[param] = value0 00210 if type(value0) != list : 00211 matchtype = True 00212 else : 00213 myf[param] = value 00214 value = myf['cu'].verifyparam({param:value}) 00215 if matchtype: 00216 value = False 00217 except Exception, instance: 00218 #ignore the exception and just return it unchecked 00219 myf[param] = value 00220 return value 00221 00222 # 00223 # 00224 def description(self, key='find', subkey=None): 00225 desc={'find': 'Find string in tasks, task names, parameter names:', 00226 'matchstring': 'String to match in the documentation', 00227 00228 'async': 'If true the taskname must be started using find(...)' 00229 } 00230 00231 if(desc.has_key(key)) : 00232 return desc[key] 00233 00234 def itsdefault(self, paramname) : 00235 a = {} 00236 a['matchstring'] = '' 00237 00238 if a.has_key(paramname) : 00239 return a[paramname] 00240 find_pg = find_pg_()