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
bf41f220
Commit
bf41f220
authored
Jul 24, 2014
by
Michael DeHaan
Committed by
James Cammarata
Jul 24, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Smush ds removal
parent
fb738bd7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
45 deletions
+10
-45
lib/ansible/utils/__init__.py
+4
-26
lib/ansible/utils/splitter.py
+6
-0
test/units/TestUtils.py
+0
-19
No files found.
lib/ansible/utils/__init__.py
View file @
bf41f220
...
...
@@ -28,7 +28,7 @@ from ansible import __version__
from
ansible.utils.display_functions
import
*
from
ansible.utils.plugins
import
*
from
ansible.callbacks
import
display
from
ansible.utils.splitter
import
split_args
from
ansible.utils.splitter
import
split_args
,
unquote
import
ansible.constants
as
C
import
ast
import
time
...
...
@@ -418,28 +418,6 @@ def merge_module_args(current_args, new_args):
module_args
=
"
%
s=
%
s
%
s"
%
(
k
,
pipes
.
quote
(
v
),
module_args
)
return
module_args
.
strip
()
def
smush_braces
(
data
):
''' smush Jinaj2 braces so unresolved templates like {{ foo }} don't get parsed weird by key=value code '''
while
'{{ '
in
data
:
data
=
data
.
replace
(
'{{ '
,
'{{'
)
while
' }}'
in
data
:
data
=
data
.
replace
(
' }}'
,
'}}'
)
return
data
def
smush_ds
(
data
):
# things like key={{ foo }} are not handled by shlex.split well, so preprocess any YAML we load
# so we do not have to call smush elsewhere
if
type
(
data
)
==
list
:
return
[
smush_ds
(
x
)
for
x
in
data
]
elif
type
(
data
)
==
dict
:
for
(
k
,
v
)
in
data
.
items
():
data
[
k
]
=
smush_ds
(
v
)
return
data
elif
isinstance
(
data
,
basestring
):
return
smush_braces
(
data
)
else
:
return
data
def
parse_yaml
(
data
,
path_hint
=
None
):
''' convert a yaml string to a data structure. Also supports JSON, ssssssh!!!'''
...
...
@@ -458,7 +436,7 @@ def parse_yaml(data, path_hint=None):
# else this is pretty sure to be a YAML document
loaded
=
yaml
.
safe_load
(
data
)
return
smush_ds
(
loaded
)
return
loaded
def
process_common_errors
(
msg
,
probline
,
column
):
replaced
=
probline
.
replace
(
" "
,
""
)
...
...
@@ -640,7 +618,7 @@ def parse_kv(args):
# attempting to split a unicode here does bad things
args
=
args
.
encode
(
'utf-8'
)
try
:
vargs
=
s
hlex
.
split
(
args
,
posix
=
True
)
vargs
=
s
plit_args
(
args
)
except
ValueError
,
ve
:
if
'no closing quotation'
in
str
(
ve
)
.
lower
():
raise
errors
.
AnsibleError
(
"error parsing argument string, try quoting the entire line."
)
...
...
@@ -650,7 +628,7 @@ def parse_kv(args):
for
x
in
vargs
:
if
"="
in
x
:
k
,
v
=
x
.
split
(
"="
,
1
)
options
[
k
]
=
v
options
[
k
]
=
unquote
(
v
)
return
options
def
merge_hash
(
a
,
b
):
...
...
lib/ansible/utils/splitter.py
View file @
bf41f220
...
...
@@ -149,3 +149,9 @@ def split_args(args):
params
=
[
x
.
decode
(
'utf-8'
)
for
x
in
params
]
return
params
def
unquote
(
data
):
''' removes first and last quotes from a string, if the string starts and ends with the same quotes '''
if
len
(
data
)
>
0
and
(
data
[
0
]
==
'"'
and
data
[
-
1
]
==
'"'
or
data
[
0
]
==
"'"
and
data
[
-
1
]
==
"'"
):
return
data
[
1
:
-
1
]
return
data
test/units/TestUtils.py
View file @
bf41f220
...
...
@@ -245,24 +245,6 @@ class TestUtils(unittest.TestCase):
# Just a string
self
.
assertEqual
(
ansible
.
utils
.
parse_json
(
'foo'
),
dict
(
failed
=
True
,
parsed
=
False
,
msg
=
'foo'
))
def
test_smush_braces
(
self
):
self
.
assertEqual
(
ansible
.
utils
.
smush_braces
(
'{{ foo}}'
),
'{{foo}}'
)
self
.
assertEqual
(
ansible
.
utils
.
smush_braces
(
'{{foo }}'
),
'{{foo}}'
)
self
.
assertEqual
(
ansible
.
utils
.
smush_braces
(
'{{ foo }}'
),
'{{foo}}'
)
def
test_smush_ds
(
self
):
# list
self
.
assertEqual
(
ansible
.
utils
.
smush_ds
([
'foo={{ foo }}'
]),
[
'foo={{foo}}'
])
# dict
self
.
assertEqual
(
ansible
.
utils
.
smush_ds
(
dict
(
foo
=
'{{ foo }}'
)),
dict
(
foo
=
'{{foo}}'
))
# string
self
.
assertEqual
(
ansible
.
utils
.
smush_ds
(
'foo={{ foo }}'
),
'foo={{foo}}'
)
# int
self
.
assertEqual
(
ansible
.
utils
.
smush_ds
(
0
),
0
)
def
test_parse_yaml
(
self
):
#json
self
.
assertEqual
(
ansible
.
utils
.
parse_yaml
(
'{"foo": "bar"}'
),
dict
(
foo
=
'bar'
))
...
...
@@ -680,7 +662,6 @@ class TestUtils(unittest.TestCase):
def
test_split_args
(
self
):
# split_args is a smarter shlex.split for the needs of the way ansible uses it
# TODO: FIXME: should this survive, retire smush_ds
def
_split_info
(
input
,
desired
,
actual
):
print
"SENT: "
,
input
...
...
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