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
25e67bb7
Commit
25e67bb7
authored
Aug 06, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
text wrap now adapts to terminal
parent
80cb6921
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
5 deletions
+18
-5
lib/ansible/utils/display.py
+18
-5
No files found.
lib/ansible/utils/display.py
View file @
25e67bb7
...
...
@@ -19,6 +19,7 @@
from
__future__
import
(
absolute_import
,
division
,
print_function
)
__metaclass__
=
type
import
fcntl
import
textwrap
import
os
import
random
...
...
@@ -27,6 +28,8 @@ import sys
import
time
import
logging
import
getpass
from
struct
import
unpack
,
pack
from
termios
import
TIOCGWINSZ
from
multiprocessing
import
Lock
from
ansible
import
constants
as
C
...
...
@@ -57,6 +60,7 @@ class Display:
def
__init__
(
self
,
verbosity
=
0
):
self
.
columns
=
None
self
.
verbosity
=
verbosity
# list of all deprecation messages to prevent duplicate display
...
...
@@ -68,6 +72,7 @@ class Display:
self
.
noncow
=
os
.
getenv
(
"ANSIBLE_COW_SELECTION"
,
None
)
self
.
set_cowsay_info
()
self
.
_set_column_width
()
def
set_cowsay_info
(
self
):
...
...
@@ -161,8 +166,8 @@ class Display:
else
:
raise
AnsibleError
(
"[DEPRECATED]:
%
s. Please update your playbooks."
%
msg
)
wrapped
=
textwrap
.
wrap
(
new_msg
,
79
,
replace_whitespace
=
False
,
drop_whitespace
=
False
)
new_msg
=
"
\n
"
.
join
(
wrapped
)
wrapped
=
textwrap
.
wrap
(
new_msg
,
self
.
columns
,
replace_whitespace
=
False
,
drop_whitespace
=
False
)
new_msg
=
"
\n
"
.
join
(
wrapped
)
+
"
\n
"
if
new_msg
not
in
self
.
_deprecations
:
self
.
display
(
new_msg
.
strip
(),
color
=
'purple'
,
stderr
=
True
)
...
...
@@ -170,7 +175,7 @@ class Display:
def
warning
(
self
,
msg
):
new_msg
=
"
\n
[WARNING]:
%
s"
%
msg
wrapped
=
textwrap
.
wrap
(
new_msg
,
79
)
wrapped
=
textwrap
.
wrap
(
new_msg
,
self
.
columns
)
new_msg
=
"
\n
"
.
join
(
wrapped
)
+
"
\n
"
if
new_msg
not
in
self
.
_warns
:
self
.
display
(
new_msg
,
color
=
'bright purple'
,
stderr
=
True
)
...
...
@@ -194,7 +199,7 @@ class Display:
#FIXME: make this dynamic on tty size (look and ansible-doc)
msg
=
msg
.
strip
()
star_len
=
(
80
-
len
(
msg
))
star_len
=
(
self
.
columns
+
1
-
len
(
msg
))
if
star_len
<
0
:
star_len
=
3
stars
=
"*"
*
star_len
...
...
@@ -217,7 +222,7 @@ class Display:
def
error
(
self
,
msg
,
wrap_text
=
True
):
if
wrap_text
:
new_msg
=
"
\n
[ERROR]:
%
s"
%
msg
wrapped
=
textwrap
.
wrap
(
new_msg
,
79
)
wrapped
=
textwrap
.
wrap
(
new_msg
,
self
.
columns
)
new_msg
=
"
\n
"
.
join
(
wrapped
)
+
"
\n
"
else
:
new_msg
=
msg
...
...
@@ -239,3 +244,11 @@ class Display:
msg
=
to_bytes
(
msg
)
return
msg
def
_set_column_width
(
self
):
if
os
.
isatty
(
0
):
tty_size
=
unpack
(
'HHHH'
,
fcntl
.
ioctl
(
0
,
TIOCGWINSZ
,
pack
(
'HHHH'
,
0
,
0
,
0
,
0
)))[
1
]
else
:
tty_size
=
0
self
.
columns
=
max
(
79
,
tty_size
)
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