Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main Repositories
otb
Commits
c5e303bc
Commit
c5e303bc
authored
7 years ago
by
Guillaume Pasero
Browse files
Options
Downloads
Patches
Plain Diff
BUG: Mantis-1476: add specific SWIG code into __setattr__ and __getattr__
parent
b9ec696e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Modules/Wrappers/SWIG/src/otbApplication.i
+47
-32
47 additions, 32 deletions
Modules/Wrappers/SWIG/src/otbApplication.i
with
47 additions
and
32 deletions
Modules/Wrappers/SWIG/src/otbApplication.i
+
47
−
32
View file @
c5e303bc
...
...
@@ -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)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment