casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables
parameter_check.py
Go to the documentation of this file.
00001 def parameter_checktype(arg_names,arg_values,arg_types):
00002         for k in range(0,len(arg_names)):
00003                 if not len(arg_names)==1:
00004                         if not isinstance(arg_values[k],arg_types[k]): 
00005                                 print " *** "
00006                                 print " "
00007                                 raise TypeError, "Expected '%s' to be '%s'; was '%s'. \n  \n *** " % (arg_names[k],arg_types[k], type(arg_values[k]))
00008                         else:
00009                                 pass
00010                 else:
00011                         if not isinstance(arg_values[0],arg_types):
00012                                 print " *** "
00013                                 print " "
00014                                 raise TypeError, "Expected '%s' to be '%s'; was '%s'. \n \n  *** " % (arg_names,arg_types,type(arg_values))
00015                         else:
00016                                 pass
00017 
00018 def parameter_checkmenu(arg_name,arg_value,arg_options):
00019         try:
00020                 arg_options.index(arg_value)
00021         except ValueError, e:
00022                 print " *** "
00023                 print " "
00024                 raise ValueError, "'%s' is not an option for '%s'; must be one of: %s. \n \n  *** " % (arg_value, arg_name, arg_options)
00025 
00026 
00027 def parameter_checklist(arg_name,arg_value,arg_options):
00028         # We assume that arg_value is a string, we need to first break
00029         # make it into a list.
00030         arg_list=[arg_value];
00031         if ( arg_value.find( "," ) > -1 ):
00032                 arg_list=arg_value.split( "," );
00033         elif ( arg_value.find( " " ) > -1 ):
00034                 arg_list=arg_value.split( " " );
00035 
00036         
00037         # Now check each element to see if it is valid.
00038         # Note that we check with UPPERCASE values to eliminate case
00039         # senstivity, and remove trailing and leading spaces
00040         for value in arg_list[:] :
00041                 try:
00042                         arg_options.index(value.upper().strip())
00043                 except ValueError, e:
00044                         print " *** "
00045                         print " "
00046                         raise ValueError, "'%s' is not an option for '%s'; must be one of: %s. \n \n  *** " % (arg_value, value, arg_options)
00047         
00048 
00049 #def parameter_checkrage(arg_name,arg_value,arg_range):
00050 
00051 def parameter_printvalues(arg_names,arg_values,arg_types):
00052         for k in range(0,len(arg_names)):
00053                 print "Parameter: %s is: %s and has type %s." % (arg_names[k],arg_values[k],type(arg_values[k]))
00054