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
e7a096c4
Commit
e7a096c4
authored
May 28, 2015
by
Brian Coca
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cowsay is back!
parent
e5190327
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
0 deletions
+50
-0
lib/ansible/utils/display.py
+50
-0
No files found.
lib/ansible/utils/display.py
View file @
e7a096c4
...
...
@@ -20,6 +20,9 @@ from __future__ import (absolute_import, division, print_function)
__metaclass__
=
type
import
textwrap
import
os
import
random
import
subprocess
import
sys
from
ansible
import
constants
as
C
...
...
@@ -37,6 +40,31 @@ class Display:
self
.
_warns
=
{}
self
.
_errors
=
{}
self
.
cowsay
=
None
self
.
noncow
=
os
.
getenv
(
"ANSIBLE_COW_SELECTION"
,
None
)
self
.
set_cowsay_info
()
def
set_cowsay_info
(
self
):
if
not
C
.
ANSIBLE_NOCOWS
:
if
os
.
path
.
exists
(
"/usr/bin/cowsay"
):
self
.
cowsay
=
"/usr/bin/cowsay"
elif
os
.
path
.
exists
(
"/usr/games/cowsay"
):
self
.
cowsay
=
"/usr/games/cowsay"
elif
os
.
path
.
exists
(
"/usr/local/bin/cowsay"
):
# BSD path for cowsay
self
.
cowsay
=
"/usr/local/bin/cowsay"
elif
os
.
path
.
exists
(
"/opt/local/bin/cowsay"
):
# MacPorts path for cowsay
self
.
cowsay
=
"/opt/local/bin/cowsay"
if
self
.
cowsay
and
self
.
noncow
==
'random'
:
cmd
=
subprocess
.
Popen
([
self
.
cowsay
,
"-l"
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
out
,
err
)
=
cmd
.
communicate
()
cows
=
out
.
split
()
cows
.
append
(
False
)
self
.
noncow
=
random
.
choice
(
cows
)
def
display
(
self
,
msg
,
color
=
None
,
stderr
=
False
,
screen_only
=
False
,
log_only
=
False
):
msg2
=
msg
if
color
:
...
...
@@ -125,6 +153,14 @@ class Display:
Prints a header-looking line with stars taking up to 80 columns
of width (3 columns, minimum)
'''
if
self
.
cowsay
:
try
:
self
.
banner_cowsay
(
msg
)
return
except
OSError
:
# somebody cleverly deleted cowsay or something during the PB run. heh.
pass
msg
=
msg
.
strip
()
star_len
=
(
80
-
len
(
msg
))
if
star_len
<
0
:
...
...
@@ -132,6 +168,20 @@ class Display:
stars
=
"*"
*
star_len
self
.
display
(
"
\n
%
s
%
s"
%
(
msg
,
stars
),
color
=
color
)
def
banner_cowsay
(
self
,
msg
,
color
=
None
):
if
": ["
in
msg
:
msg
=
msg
.
replace
(
"["
,
""
)
if
msg
.
endswith
(
"]"
):
msg
=
msg
[:
-
1
]
runcmd
=
[
self
.
cowsay
,
"-W"
,
"60"
]
if
self
.
noncow
:
runcmd
.
append
(
'-f'
)
runcmd
.
append
(
self
.
noncow
)
runcmd
.
append
(
msg
)
cmd
=
subprocess
.
Popen
(
runcmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
(
out
,
err
)
=
cmd
.
communicate
()
self
.
display
(
"
%
s
\n
"
%
out
,
color
=
color
)
def
error
(
self
,
msg
):
new_msg
=
"
\n
[ERROR]:
%
s"
%
msg
wrapped
=
textwrap
.
wrap
(
new_msg
,
79
)
...
...
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