Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
63c54035
Commit
63c54035
authored
Mar 23, 2015
by
Toshio Kuratomi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get rid of iteritems usage when we only care about the keys
parent
fdf51e9a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
6 deletions
+9
-6
v2/ansible/playbook/base.py
+9
-6
No files found.
v2/ansible/playbook/base.py
View file @
63c54035
...
@@ -97,6 +97,9 @@ class Base:
...
@@ -97,6 +97,9 @@ class Base:
def
munge
(
self
,
ds
):
def
munge
(
self
,
ds
):
''' infrequently used method to do some pre-processing of legacy terms '''
''' infrequently used method to do some pre-processing of legacy terms '''
### FIXME: Can't find any classes with methods named
# _munge_base_class.__name__ so maybe Base.munge should be reduced down
# to return ds
for
base_class
in
self
.
__class__
.
mro
():
for
base_class
in
self
.
__class__
.
mro
():
method
=
getattr
(
self
,
"_munge_
%
s"
%
base_class
.
__name__
.
lower
(),
None
)
method
=
getattr
(
self
,
"_munge_
%
s"
%
base_class
.
__name__
.
lower
(),
None
)
if
method
:
if
method
:
...
@@ -132,7 +135,7 @@ class Base:
...
@@ -132,7 +135,7 @@ class Base:
# FIXME: we currently don't do anything with private attributes but
# FIXME: we currently don't do anything with private attributes but
# may later decide to filter them out of 'ds' here.
# may later decide to filter them out of 'ds' here.
for
(
name
,
attribute
)
in
iteritems
(
self
.
_get_base_attributes
()
):
for
name
in
self
.
_get_base_attributes
(
):
# copy the value over unless a _load_field method is defined
# copy the value over unless a _load_field method is defined
if
name
in
ds
:
if
name
in
ds
:
method
=
getattr
(
self
,
'_load_
%
s'
%
name
,
None
)
method
=
getattr
(
self
,
'_load_
%
s'
%
name
,
None
)
...
@@ -151,7 +154,7 @@ class Base:
...
@@ -151,7 +154,7 @@ class Base:
return
self
return
self
def
get_ds
(
self
):
def
get_ds
(
self
):
try
:
try
:
return
getattr
(
self
,
'_ds'
)
return
getattr
(
self
,
'_ds'
)
except
AttributeError
:
except
AttributeError
:
return
None
return
None
...
@@ -168,7 +171,7 @@ class Base:
...
@@ -168,7 +171,7 @@ class Base:
not map to attributes for this object.
not map to attributes for this object.
'''
'''
valid_attrs
=
[
name
for
(
name
,
attribute
)
in
iteritems
(
self
.
_get_base_attributes
())]
valid_attrs
=
frozenset
(
name
for
name
in
self
.
_get_base_attributes
())
for
key
in
ds
:
for
key
in
ds
:
if
key
not
in
valid_attrs
:
if
key
not
in
valid_attrs
:
raise
AnsibleParserError
(
"'
%
s' is not a valid attribute for a
%
s"
%
(
key
,
self
.
__class__
.
__name__
),
obj
=
ds
)
raise
AnsibleParserError
(
"'
%
s' is not a valid attribute for a
%
s"
%
(
key
,
self
.
__class__
.
__name__
),
obj
=
ds
)
...
@@ -191,7 +194,7 @@ class Base:
...
@@ -191,7 +194,7 @@ class Base:
new_me
=
self
.
__class__
()
new_me
=
self
.
__class__
()
for
(
name
,
attribute
)
in
iteritems
(
self
.
_get_base_attributes
()
):
for
name
in
self
.
_get_base_attributes
(
):
setattr
(
new_me
,
name
,
getattr
(
self
,
name
))
setattr
(
new_me
,
name
,
getattr
(
self
,
name
))
new_me
.
_loader
=
self
.
_loader
new_me
.
_loader
=
self
.
_loader
...
@@ -223,7 +226,7 @@ class Base:
...
@@ -223,7 +226,7 @@ class Base:
try
:
try
:
# if the attribute contains a variable, template it now
# if the attribute contains a variable, template it now
value
=
templar
.
template
(
getattr
(
self
,
name
))
value
=
templar
.
template
(
getattr
(
self
,
name
))
# run the post-validator if present
# run the post-validator if present
method
=
getattr
(
self
,
'_post_validate_
%
s'
%
name
,
None
)
method
=
getattr
(
self
,
'_post_validate_
%
s'
%
name
,
None
)
if
method
:
if
method
:
...
@@ -262,7 +265,7 @@ class Base:
...
@@ -262,7 +265,7 @@ class Base:
repr
=
dict
()
repr
=
dict
()
for
(
name
,
attribute
)
in
iteritems
(
self
.
_get_base_attributes
()
):
for
name
in
self
.
_get_base_attributes
(
):
repr
[
name
]
=
getattr
(
self
,
name
)
repr
[
name
]
=
getattr
(
self
,
name
)
# serialize the uuid field
# serialize the uuid field
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment