mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-31 05:19:09 -07:00
[PR #9379/22035608 backport][stable-10] plugins: replace to_native(), to_text(), str() with str() where possible or leave it away in f-string formatting (#9444)
plugins: replace to_native(), to_text(), str() with str() where possible or leave it away in f-string formatting (#9379)
* Replace to_native(), to_text(), str() with str() where possible or leave it away in f-string formatting.
* Improve formulation.
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
* Use more f-strings.
* Remove unicode prefix for strings.
---------
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
(cherry picked from commit 2203560867
)
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
parent
0acaad60c8
commit
151f6c9ce3
34 changed files with 111 additions and 99 deletions
|
@ -195,17 +195,15 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
p = Popen(cmd_list, stdout=PIPE, stderr=PIPE, env=my_env)
|
||||
stdout, stderr = p.communicate()
|
||||
if p.returncode != 0:
|
||||
raise AnsibleError('Failed to run cmd=%s, rc=%s, stderr=%s' %
|
||||
(cmd_list, p.returncode, to_native(stderr)))
|
||||
raise AnsibleError(f'Failed to run cmd={cmd_list}, rc={p.returncode}, stderr={to_native(stderr)}')
|
||||
|
||||
try:
|
||||
t_stdout = to_text(stdout, errors='surrogate_or_strict')
|
||||
except UnicodeError as e:
|
||||
raise AnsibleError('Invalid (non unicode) input returned: %s' % to_native(e)) from e
|
||||
raise AnsibleError(f'Invalid (non unicode) input returned: {e}') from e
|
||||
|
||||
except Exception as e:
|
||||
raise AnsibleParserError('Failed to parse %s: %s' %
|
||||
(to_native(path), to_native(e))) from e
|
||||
raise AnsibleParserError(f'Failed to parse {to_native(path)}: {e}') from e
|
||||
|
||||
results = {'_meta': {'hostvars': {}}}
|
||||
self.get_jails(t_stdout, results)
|
||||
|
@ -220,16 +218,16 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
p = Popen(cmd_get_properties, stdout=PIPE, stderr=PIPE, env=my_env)
|
||||
stdout, stderr = p.communicate()
|
||||
if p.returncode != 0:
|
||||
raise AnsibleError('Failed to run cmd=%s, rc=%s, stderr=%s' %
|
||||
(cmd_get_properties, p.returncode, to_native(stderr)))
|
||||
raise AnsibleError(
|
||||
f'Failed to run cmd={cmd_get_properties}, rc={p.returncode}, stderr={to_native(stderr)}')
|
||||
|
||||
try:
|
||||
t_stdout = to_text(stdout, errors='surrogate_or_strict')
|
||||
except UnicodeError as e:
|
||||
raise AnsibleError('Invalid (non unicode) input returned: %s' % to_native(e)) from e
|
||||
raise AnsibleError(f'Invalid (non unicode) input returned: {e}') from e
|
||||
|
||||
except Exception as e:
|
||||
raise AnsibleError('Failed to get properties: %s' % to_native(e)) from e
|
||||
raise AnsibleError(f'Failed to get properties: {e}') from e
|
||||
|
||||
self.get_properties(t_stdout, results, hostname)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue