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