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): ...@@ -562,38 +562,53 @@ class ApplicationProxy(object):
print ("Unsupported parameter type '%s' with key '%s'" %(self.GetParameterTypeAsString(paramType) ,paramKey)) print ("Unsupported parameter type '%s' with key '%s'" %(self.GetParameterTypeAsString(paramType) ,paramKey))
return None return None
def __getattr__(self,attr): def __getattr__(self,name):
""" """
__get_attribute__ is called whenever an instance request an attribute. __get_attribute__ is called whenever an instance request an attribute.
eg: App.SetParameterString(), App.GetName() .. eg: App.SetParameterString(), App.GetName() ..
__getattr__ is only called if the attribute is not found by __get_attribute__ call __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 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 an obivous call for users. App.IN , App.OUT , where 'in' and 'out' are
parameters in the 'otb application' with instance App parameters in the 'otb application' with instance App
""" Since SWIG also uses this function, we have to copy their code before
if attr is not None: using custom OTB behaviour
key_list = [k.upper() for k in self.GetParametersKeys(True)] """
if attr in key_list: if (name == "thisown"):
return self.GetParameterValue(attr.lower()) return self.this.own()
else: method = Application.__swig_getmethods__.get(name, None)
raise AttributeError("Parameter {} does not exist in the application.".format(attr.lower())) if method:
return method(self)
def __setattr__(self, attr, value): key_list = [k.upper() for k in self.GetParametersKeys(True)]
""" if name in key_list:
__setattr__ is called if the attribute requested is not found in the attribute list. return self.GetParameterValue(name.lower())
So these attributes are supposed to be 'key' of parameters used. Here we raise AttributeError("'%s' object has no attribute '%s'" % (Application.__name__, name))
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 def __setattr__(self, name, value):
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 __setattr__ is called if the attribute requested is not found in the attribute list.
list of existing parameters for application with 'self.GetParametersKeys(True)' 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
if attr is not None: an obivous call for users. App.IN='my-input-file-name' , App.OUT='my-output-file-name'w
key_list = [k.upper() for k in self.GetParametersKeys(True)] here 'in' and 'out' are parameters in the 'otb application' with instance App
if attr in key_list: Ofcourse, we don't blindly accept any attributes as python, we check them against
self.SetParameterValue(attr.lower(), value) list of existing parameters for application with 'self.GetParametersKeys(True)'
else: Since SWIG also uses this function, we have to copy their code before
raise AttributeError("Parameter {} does not exist in the application.".format(attr.lower())) 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): ...@@ -24,7 +24,7 @@ def test(otb, argv):
app = otb.Registry.CreateApplication('Rasterization') app = otb.Registry.CreateApplication('Rasterization')
try: try:
app.GetParameterInt('szx') app.GetParameterInt('szx')
except RuntimeError, e: except RuntimeError as e:
print( "Exception message : " + e.args[0] ) print( "Exception message : " + e.args[0] )
if e.args[0].startswith("boost::bad_any_cast"): if e.args[0].startswith("boost::bad_any_cast"):
exit(1) exit(1)
......
...@@ -42,7 +42,7 @@ def test(otb, argv): ...@@ -42,7 +42,7 @@ def test(otb, argv):
app4.AddImageToParameterInputImageList("il",app2.GetParameterOutputImage("out")); app4.AddImageToParameterInputImageList("il",app2.GetParameterOutputImage("out"));
app4.AddImageToParameterInputImageList("il",app3.GetParameterOutputImage("out")); app4.AddImageToParameterInputImageList("il",app3.GetParameterOutputImage("out"));
app4.AddParameterStringList("il",argv[1]) app4.AddParameterStringList("il",argv[1])
app4.OUT = argv[2] app4.OUT = argv[2]
app4.ExecuteAndWriteOutput() app4.ExecuteAndWriteOutput()
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
# Example on the use of otb "pythonization" # Example on the use of otb "pythonization"
# #
def cm_assert(a,b): 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 assert a == b
def test(otb, argv): 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