mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 22:00:22 -07:00
Move uses of to_bytes, to_text, to_native to use the module_utils version (#17423)
We couldn't copy to_unicode, to_bytes, to_str into module_utils because of licensing. So once created it we had two sets of functions that did the same things but had different implementations. To remedy that, this change removes the ansible.utils.unicode versions of those functions.
This commit is contained in:
parent
7a9395b5e0
commit
4ed88512e4
89 changed files with 759 additions and 894 deletions
|
@ -39,18 +39,16 @@ import sys
|
|||
from ansible import constants as C
|
||||
from ansible.cli import CLI
|
||||
from ansible.errors import AnsibleError
|
||||
|
||||
from ansible.executor.task_queue_manager import TaskQueueManager
|
||||
from ansible.inventory import Inventory
|
||||
from ansible.module_utils._text import to_native, to_text
|
||||
from ansible.parsing.dataloader import DataLoader
|
||||
from ansible.parsing.splitter import parse_kv
|
||||
from ansible.playbook.play import Play
|
||||
from ansible.vars import VariableManager
|
||||
from ansible.plugins import module_loader
|
||||
from ansible.utils import module_docs
|
||||
from ansible.utils.color import stringc
|
||||
from ansible.utils.unicode import to_unicode, to_str
|
||||
from ansible.plugins import module_loader
|
||||
|
||||
from ansible.vars import VariableManager
|
||||
|
||||
try:
|
||||
from __main__ import display
|
||||
|
@ -152,11 +150,11 @@ class ConsoleCLI(CLI, cmd.Cmd):
|
|||
continue
|
||||
elif module.startswith('_'):
|
||||
fullpath = '/'.join([path,module])
|
||||
if os.path.islink(fullpath): # avoids aliases
|
||||
if os.path.islink(fullpath): # avoids aliases
|
||||
continue
|
||||
module = module.replace('_', '', 1)
|
||||
|
||||
module = os.path.splitext(module)[0] # removes the extension
|
||||
module = os.path.splitext(module)[0] # removes the extension
|
||||
yield module
|
||||
|
||||
def default(self, arg, forceshell=False):
|
||||
|
@ -192,11 +190,11 @@ class ConsoleCLI(CLI, cmd.Cmd):
|
|||
)
|
||||
play = Play().load(play_ds, variable_manager=self.variable_manager, loader=self.loader)
|
||||
except Exception as e:
|
||||
display.error(u"Unable to build command: %s" % to_unicode(e))
|
||||
display.error(u"Unable to build command: %s" % to_text(e))
|
||||
return False
|
||||
|
||||
try:
|
||||
cb = 'minimal' #FIXME: make callbacks configurable
|
||||
cb = 'minimal' # FIXME: make callbacks configurable
|
||||
# now create a task queue manager to execute the play
|
||||
self._tqm = None
|
||||
try:
|
||||
|
@ -225,8 +223,8 @@ class ConsoleCLI(CLI, cmd.Cmd):
|
|||
display.error('User interrupted execution')
|
||||
return False
|
||||
except Exception as e:
|
||||
display.error(to_unicode(e))
|
||||
#FIXME: add traceback in very very verbose mode
|
||||
display.error(to_text(e))
|
||||
# FIXME: add traceback in very very verbose mode
|
||||
return False
|
||||
|
||||
def emptyline(self):
|
||||
|
@ -379,7 +377,7 @@ class ConsoleCLI(CLI, cmd.Cmd):
|
|||
else:
|
||||
completions = [x.name for x in self.inventory.list_hosts(self.options.cwd)]
|
||||
|
||||
return [to_str(s)[offs:] for s in completions if to_str(s).startswith(to_str(mline))]
|
||||
return [to_native(s)[offs:] for s in completions if to_native(s).startswith(to_native(mline))]
|
||||
|
||||
def completedefault(self, text, line, begidx, endidx):
|
||||
if line.split()[0] in self.modules:
|
||||
|
@ -394,7 +392,6 @@ class ConsoleCLI(CLI, cmd.Cmd):
|
|||
oc, a, _ = module_docs.get_docstring(in_path)
|
||||
return oc['options'].keys()
|
||||
|
||||
|
||||
def run(self):
|
||||
|
||||
super(ConsoleCLI, self).run()
|
||||
|
@ -410,7 +407,6 @@ class ConsoleCLI(CLI, cmd.Cmd):
|
|||
self.pattern = self.args[0]
|
||||
self.options.cwd = self.pattern
|
||||
|
||||
|
||||
# dynamically add modules as commands
|
||||
self.modules = self.list_modules()
|
||||
for module in self.modules:
|
||||
|
@ -465,4 +461,3 @@ class ConsoleCLI(CLI, cmd.Cmd):
|
|||
atexit.register(readline.write_history_file, histfile)
|
||||
self.set_prompt()
|
||||
self.cmdloop()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue