Skip to content
Snippets Groups Projects
Commit e7770790 authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

Merge branch 'mantis-1476' into develop

parents 14935049 32c53bd7
No related branches found
No related tags found
No related merge requests found
......@@ -562,38 +562,53 @@ class ApplicationProxy(object):
print ("Unsupported parameter type '%s' with key '%s'" %(self.GetParameterTypeAsString(paramType) ,paramKey))
return None
def __getattr__(self,attr):
"""
__get_attribute__ is called whenever an instance request an attribute.
eg: App.SetParameterString(), App.GetName() ..
__getattr__ is only called if the attribute is not found by __get_attribute__ call
So we keep hide the GetParameter** calls within this method so that it seems like
an obivous call for users. App.IN , App.OUT , where 'in' and 'out' are
parameters in the 'otb application' with instance App
"""
if attr is not None:
key_list = [k.upper() for k in self.GetParametersKeys(True)]
if attr in key_list:
return self.GetParameterValue(attr.lower())
else:
raise AttributeError("Parameter {} does not exist in the application.".format(attr.lower()))
def __setattr__(self, attr, value):
"""
__setattr__ is called if the attribute requested is not found in the attribute list.
So these attributes are supposed to be 'key' of parameters used. Here we
keep hide the SetParameter** calls within this method so that it seems like
an obivous call for users. App.IN='my-input-file-name' , App.OUT='my-output-file-name'w
here 'in' and 'out' are parameters in the 'otb application' with instance App
Ofcourse, we don't blindly accept any attributes as python, we check them against
list of existing parameters for application with 'self.GetParametersKeys(True)'
"""
if attr is not None:
key_list = [k.upper() for k in self.GetParametersKeys(True)]
if attr in key_list:
self.SetParameterValue(attr.lower(), value)
else:
raise AttributeError("Parameter {} does not exist in the application.".format(attr.lower()))
def __getattr__(self,name):
"""
__get_attribute__ is called whenever an instance request an attribute.
eg: App.SetParameterString(), App.GetName() ..
__getattr__ is only called if the attribute is not found by __get_attribute__ call
So we keep hide the GetParameter** calls within this method so that it seems like
an obivous call for users. App.IN , App.OUT , where 'in' and 'out' are
parameters in the 'otb application' with instance App
Since SWIG also uses this function, we have to copy their code before
using custom OTB behaviour
"""
if (name == "thisown"):
return self.this.own()
method = Application.__swig_getmethods__.get(name, None)
if method:
return method(self)
key_list = [k.upper() for k in self.GetParametersKeys(True)]
if name in key_list:
return self.GetParameterValue(name.lower())
raise AttributeError("'%s' object has no attribute '%s'" % (Application.__name__, name))
def __setattr__(self, name, value):
"""
__setattr__ is called if the attribute requested is not found in the attribute list.
So these attributes are supposed to be 'key' of parameters used. Here we
keep hide the SetParameter** calls within this method so that it seems like
an obivous call for users. App.IN='my-input-file-name' , App.OUT='my-output-file-name'w
here 'in' and 'out' are parameters in the 'otb application' with instance App
Ofcourse, we don't blindly accept any attributes as python, we check them against
list of existing parameters for application with 'self.GetParametersKeys(True)'
Since SWIG also uses this function, we have to copy their code before
using custom OTB behaviour
"""
if (name == "thisown"):
return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = Application.__swig_setmethods__.get(name, None)
if method:
return method(self, value)
key_list = [k.upper() for k in self.GetParametersKeys(True)]
if name in key_list:
self.SetParameterValue(name.lower(), value)
else:
raise AttributeError("You cannot add attributes to %s" % self)
}
}
......
......@@ -24,7 +24,7 @@ def test(otb, argv):
app = otb.Registry.CreateApplication('Rasterization')
try:
app.GetParameterInt('szx')
except RuntimeError, e:
except RuntimeError as e:
print( "Exception message : " + e.args[0] )
if e.args[0].startswith("boost::bad_any_cast"):
exit(1)
......
......@@ -42,7 +42,7 @@ def test(otb, argv):
app4.AddImageToParameterInputImageList("il",app2.GetParameterOutputImage("out"));
app4.AddImageToParameterInputImageList("il",app3.GetParameterOutputImage("out"));
app4.AddParameterStringList("il",argv[1])
app4.AddParameterStringList("il",argv[1])
app4.OUT = argv[2]
app4.ExecuteAndWriteOutput()
......@@ -22,7 +22,7 @@
# Example on the use of otb "pythonization"
#
def cm_assert(a,b):
print "debug print before assert check: '%s'== '%s'" %(a, b)
print("debug print before assert check: '%s'== '%s'" %(a, b))
assert a == b
def test(otb, argv):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment