mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
Clean up imports in utils, add nicer recursion depth limit check.
This commit is contained in:
parent
60d64251f8
commit
19a2fc00dc
1 changed files with 8 additions and 4 deletions
|
@ -25,7 +25,9 @@ import codecs
|
||||||
import jinja2
|
import jinja2
|
||||||
import yaml
|
import yaml
|
||||||
import optparse
|
import optparse
|
||||||
from operator import methodcaller
|
import operator
|
||||||
|
from ansible import errors
|
||||||
|
import ansible.constants as C
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import json
|
import json
|
||||||
|
@ -37,8 +39,6 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from md5 import md5 as _md5
|
from md5 import md5 as _md5
|
||||||
|
|
||||||
from ansible import errors
|
|
||||||
import ansible.constants as C
|
|
||||||
|
|
||||||
###############################################################
|
###############################################################
|
||||||
# UTILITY FUNCTIONS FOR COMMAND LINE TOOLS
|
# UTILITY FUNCTIONS FOR COMMAND LINE TOOLS
|
||||||
|
@ -278,7 +278,11 @@ def template(text, vars, setup_cache=None):
|
||||||
''' run a text buffer through the templating engine
|
''' run a text buffer through the templating engine
|
||||||
until it no longer changes '''
|
until it no longer changes '''
|
||||||
prev_text = ''
|
prev_text = ''
|
||||||
|
depth = 0
|
||||||
while prev_text != text:
|
while prev_text != text:
|
||||||
|
depth = depth + 1
|
||||||
|
if (depth > 20):
|
||||||
|
raise errors.AnsibleError("template recursion depth exceeded")
|
||||||
prev_text = text
|
prev_text = text
|
||||||
text = _template(text, vars, setup_cache)
|
text = _template(text, vars, setup_cache)
|
||||||
return text
|
return text
|
||||||
|
@ -343,7 +347,7 @@ def md5(filename):
|
||||||
class SortedOptParser(optparse.OptionParser):
|
class SortedOptParser(optparse.OptionParser):
|
||||||
'''Optparser which sorts the options by opt before outputting --help'''
|
'''Optparser which sorts the options by opt before outputting --help'''
|
||||||
def format_help(self, formatter=None):
|
def format_help(self, formatter=None):
|
||||||
self.option_list.sort(key=methodcaller('get_opt_string'))
|
self.option_list.sort(key=operator.methodcaller('get_opt_string'))
|
||||||
return optparse.OptionParser.format_help(self, formatter=None)
|
return optparse.OptionParser.format_help(self, formatter=None)
|
||||||
|
|
||||||
def base_parser(constants=C, usage="", output_opts=False, runas_opts=False, async_opts=False, connect_opts=False):
|
def base_parser(constants=C, usage="", output_opts=False, runas_opts=False, async_opts=False, connect_opts=False):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue