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