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