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
f8593cc7
Commit
f8593cc7
authored
Jul 02, 2015
by
Jiri Tyr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding comment filter
parent
08ad05c8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
+80
-0
v1/ansible/runner/filter_plugins/core.py
+80
-0
No files found.
v1/ansible/runner/filter_plugins/core.py
View file @
f8593cc7
...
...
@@ -270,6 +270,83 @@ def get_encrypted_password(password, hashtype='sha512', salt=None):
def
to_uuid
(
string
):
return
str
(
uuid
.
uuid5
(
UUID_NAMESPACE_ANSIBLE
,
str
(
string
)))
def
comment
(
text
,
style
=
'plain'
,
**
kw
):
# Predefined comment types
comment_styles
=
{
'plain'
:
{
'decoration'
:
'# '
},
'erlang'
:
{
'decoration'
:
'
%
'
},
'c'
:
{
'decoration'
:
'// '
},
'cblock'
:
{
'beginning'
:
'/*'
,
'decoration'
:
' * '
,
'end'
:
' */'
},
'xml'
:
{
'beginning'
:
'<!--'
,
'decoration'
:
' - '
,
'end'
:
'-->'
}
}
# Pointer to the right comment type
style_params
=
comment_styles
[
style
]
if
'decoration'
in
kw
:
prepostfix
=
kw
[
'decoration'
]
else
:
prepostfix
=
style_params
[
'decoration'
]
# Default params
p
=
{
'newline'
:
'
\n
'
,
'beginning'
:
''
,
'prefix'
:
(
prepostfix
)
.
rstrip
(),
'prefix_count'
:
1
,
'decoration'
:
''
,
'postfix'
:
(
prepostfix
)
.
rstrip
(),
'postfix_count'
:
1
,
'end'
:
''
}
# Update default params
p
.
update
(
style_params
)
p
.
update
(
kw
)
# Compose substrings for the final string
str_beginning
=
''
if
p
[
'beginning'
]:
str_beginning
=
"
%
s
%
s"
%
(
p
[
'beginning'
],
p
[
'newline'
])
str_prefix
=
str
(
"
%
s
%
s"
%
(
p
[
'prefix'
],
p
[
'newline'
]))
*
int
(
p
[
'prefix_count'
])
str_text
=
(
"
%
s
%
s"
%
(
p
[
'decoration'
],
# Prepend each line of the text with the decorator
text
.
replace
(
p
[
'newline'
],
"
%
s
%
s"
%
(
p
[
'newline'
],
p
[
'decoration'
]))))
.
replace
(
# Remove trailing spaces when only decorator is on the line
"
%
s
%
s"
%
(
p
[
'decoration'
],
p
[
'newline'
]),
"
%
s
%
s"
%
(
p
[
'decoration'
]
.
rstrip
(),
p
[
'newline'
]))
str_postfix
=
p
[
'newline'
]
.
join
(
[
''
]
+
[
p
[
'postfix'
]
for
x
in
range
(
p
[
'postfix_count'
])])
str_end
=
''
if
p
[
'end'
]:
str_end
=
"
%
s
%
s"
%
(
p
[
'newline'
],
p
[
'end'
])
# Return the final string
return
"
%
s
%
s
%
s
%
s
%
s"
%
(
str_beginning
,
str_prefix
,
str_text
,
str_postfix
,
str_end
)
class
FilterModule
(
object
):
''' Ansible core jinja2 filters '''
...
...
@@ -348,4 +425,7 @@ class FilterModule(object):
# random stuff
'random'
:
rand
,
'shuffle'
:
randomize_list
,
# comment-style decoration of string
'comment'
:
comment
,
}
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