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
301edb5b
Commit
301edb5b
authored
Aug 11, 2012
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use StringIO for output concatenation, minor other tweaks to previous commit
parent
3cc564c1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
21 deletions
+24
-21
lib/ansible/utils.py
+24
-21
No files found.
lib/ansible/utils.py
View file @
301edb5b
...
...
@@ -28,6 +28,7 @@ from ansible import errors
from
ansible
import
__version__
import
ansible.constants
as
C
import
time
import
StringIO
VERBOSITY
=
0
...
...
@@ -120,6 +121,7 @@ def json_loads(data):
def
parse_json
(
raw_data
):
''' this version for module return data only '''
# ignore stuff like tcgetattr spewage or other warnings
data
=
filter_leading_non_json_lines
(
raw_data
)
try
:
...
...
@@ -417,29 +419,30 @@ def do_encrypt(result, encrypt, salt_size=None, salt=None):
return
result
def
last_non_blank_line
(
lines
):
all_lines
=
lines
.
splitlines
()
def
last_non_blank_line
(
buf
):
all_lines
=
buf
.
splitlines
()
all_lines
.
reverse
()
for
line
in
all_lines
:
if
(
len
(
line
)
>
0
):
return
line
return
""
# we shouldn't come here (no lines?) but let's pretend nothing happend
# We can't return all lines here because calling code expects only one
# line. And since we don't know which line to return we return an empty
# line.
def
is_valid_json_line
(
line
):
return
line
.
startswith
(
'='
)
or
line
.
startswith
(
'{'
)
or
line
.
startswith
(
'['
)
def
filter_leading_non_json_lines
(
lines
):
'''
we need to filter anything which starts not with '{', '[', ', '=' or is an empty line.
But we filter only leading lines since multiline JSON is valid. '''
filtered_lines
=
''
no_more
_filtering
=
False
for
line
in
lines
.
splitlines
():
if
(
no_more_filtering
or
is_valid_json_line
(
line
)
):
no_more
_filtering
=
True
filtered_lines
+=
line
+
'
\n
'
return
filtered_lines
# shouldn't occur unless there's no output
return
""
def
filter_leading_non_json_lines
(
buf
):
'''
used to avoid random output from SSH at the top of JSON output, like messages from
tcagetattr, or where dropbear spews MOTD on every single command (which is nuts).
need to filter anything which starts not with '{', '[', ', '=' or is an empty line.
filter only leading lines since multiline JSON is valid.
'''
filtered_lines
=
StringIO
.
StringIO
()
stop
_filtering
=
False
for
line
in
buf
.
splitlines
():
if
stop_filtering
or
"="
in
line
or
line
.
startswith
(
'{'
)
or
line
.
startswith
(
'['
):
stop
_filtering
=
True
filtered_lines
.
write
(
line
+
'
\n
'
)
return
filtered_lines
.
getvalue
()
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