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
8e45fa9b
Commit
8e45fa9b
authored
Apr 30, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moving display-related functions to new module in utils
parent
6069ff6e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
71 additions
and
41 deletions
+71
-41
lib/ansible/utils/__init__.py
+8
-41
lib/ansible/utils/display_functions.py
+63
-0
No files found.
lib/ansible/utils/__init__.py
View file @
8e45fa9b
...
...
@@ -25,8 +25,9 @@ import optparse
import
operator
from
ansible
import
errors
from
ansible
import
__version__
from
ansible.utils.plugins
import
*
from
ansible.utils
import
template
from
ansible.utils.display_functions
import
*
from
ansible.utils.plugins
import
*
from
ansible.callbacks
import
display
import
ansible.constants
as
C
import
ast
...
...
@@ -42,7 +43,6 @@ import warnings
import
traceback
import
getpass
import
sys
import
textwrap
import
json
#import vault
...
...
@@ -50,10 +50,6 @@ from vault import VaultLib
VERBOSITY
=
0
# list of all deprecation messages to prevent duplicate display
deprecations
=
{}
warns
=
{}
MAX_FILE_SIZE_FOR_DIFF
=
1
*
1024
*
1024
try
:
...
...
@@ -75,7 +71,12 @@ except:
KEYCZAR_AVAILABLE
=
False
try
:
from
Crypto.pct_warnings
import
PowmInsecureWarning
try
:
# some versions of pycrypto may not have this?
from
Crypto.pct_warnings
import
PowmInsecureWarning
except
ImportError
:
PowmInsecureWarning
=
RuntimeWarning
with
warnings
.
catch_warnings
(
record
=
True
)
as
warning_handler
:
warnings
.
simplefilter
(
"error"
,
PowmInsecureWarning
)
try
:
...
...
@@ -1127,40 +1128,6 @@ def listify_lookup_plugin_terms(terms, basedir, inject):
return
terms
def
deprecated
(
msg
,
version
,
removed
=
False
):
''' used to print out a deprecation message.'''
if
not
removed
and
not
C
.
DEPRECATION_WARNINGS
:
return
if
not
removed
:
if
version
:
new_msg
=
"
\n
[DEPRECATION WARNING]:
%
s. This feature will be removed in version
%
s."
%
(
msg
,
version
)
else
:
new_msg
=
"
\n
[DEPRECATION WARNING]:
%
s. This feature will be removed in a future release."
%
(
msg
)
new_msg
=
new_msg
+
" Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
\n\n
"
else
:
raise
errors
.
AnsibleError
(
"[DEPRECATED]:
%
s. Please update your playbooks."
%
msg
)
wrapped
=
textwrap
.
wrap
(
new_msg
,
79
)
new_msg
=
"
\n
"
.
join
(
wrapped
)
+
"
\n
"
if
new_msg
not
in
deprecations
:
display
(
new_msg
,
color
=
'purple'
,
stderr
=
True
)
deprecations
[
new_msg
]
=
1
def
warning
(
msg
):
new_msg
=
"
\n
[WARNING]:
%
s"
%
msg
wrapped
=
textwrap
.
wrap
(
new_msg
,
79
)
new_msg
=
"
\n
"
.
join
(
wrapped
)
+
"
\n
"
if
new_msg
not
in
warns
:
display
(
new_msg
,
color
=
'bright purple'
,
stderr
=
True
)
warns
[
new_msg
]
=
1
def
system_warning
(
msg
):
if
C
.
SYSTEM_WARNINGS
:
warning
(
msg
)
def
combine_vars
(
a
,
b
):
if
C
.
DEFAULT_HASH_BEHAVIOUR
==
"merge"
:
...
...
lib/ansible/utils/display_functions.py
0 → 100644
View file @
8e45fa9b
# (c) 2014, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import
textwrap
from
ansible
import
constants
as
C
from
ansible
import
errors
from
ansible.callbacks
import
display
__all__
=
[
'deprecated'
,
'warning'
,
'system_warning'
]
# list of all deprecation messages to prevent duplicate display
deprecations
=
{}
warns
=
{}
def
deprecated
(
msg
,
version
,
removed
=
False
):
''' used to print out a deprecation message.'''
if
not
removed
and
not
C
.
DEPRECATION_WARNINGS
:
return
if
not
removed
:
if
version
:
new_msg
=
"
\n
[DEPRECATION WARNING]:
%
s. This feature will be removed in version
%
s."
%
(
msg
,
version
)
else
:
new_msg
=
"
\n
[DEPRECATION WARNING]:
%
s. This feature will be removed in a future release."
%
(
msg
)
new_msg
=
new_msg
+
" Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
\n\n
"
else
:
raise
errors
.
AnsibleError
(
"[DEPRECATED]:
%
s. Please update your playbooks."
%
msg
)
wrapped
=
textwrap
.
wrap
(
new_msg
,
79
)
new_msg
=
"
\n
"
.
join
(
wrapped
)
+
"
\n
"
if
new_msg
not
in
deprecations
:
display
(
new_msg
,
color
=
'purple'
,
stderr
=
True
)
deprecations
[
new_msg
]
=
1
def
warning
(
msg
):
new_msg
=
"
\n
[WARNING]:
%
s"
%
msg
wrapped
=
textwrap
.
wrap
(
new_msg
,
79
)
new_msg
=
"
\n
"
.
join
(
wrapped
)
+
"
\n
"
if
new_msg
not
in
warns
:
display
(
new_msg
,
color
=
'bright purple'
,
stderr
=
True
)
warns
[
new_msg
]
=
1
def
system_warning
(
msg
):
if
C
.
SYSTEM_WARNINGS
:
warning
(
msg
)
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