mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-09-29 13:03:22 -07:00
simplify string formatting in some modules (#10727)
* simplify string formatting in some modules * add changelog frag
This commit is contained in:
parent
3cc4f28fd7
commit
6f40eff632
10 changed files with 23 additions and 13 deletions
10
changelogs/fragments/10727-python-idioms-3.yml
Normal file
10
changelogs/fragments/10727-python-idioms-3.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
minor_changes:
|
||||||
|
- filesize - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
|
||||||
|
- iptables_state - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
|
||||||
|
- manageiq_group - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
|
||||||
|
- manageiq_tenant - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
|
||||||
|
- mssql_db - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
|
||||||
|
- openbsd_pkg - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
|
||||||
|
- ufw - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
|
||||||
|
- xenserver_facts - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
|
||||||
|
- zfs_facts - minor refactor to simplify string formatting (https://github.com/ansible-collections/community.general/pull/10727).
|
|
@ -304,7 +304,7 @@ def split_size_unit(string, isint=False):
|
||||||
Support optional space(s) between the numeric value and the unit.
|
Support optional space(s) between the numeric value and the unit.
|
||||||
"""
|
"""
|
||||||
unit = re.sub(r'(\d|\.)', r'', string).strip()
|
unit = re.sub(r'(\d|\.)', r'', string).strip()
|
||||||
value = float(re.sub(r'%s' % unit, r'', string).strip())
|
value = float(re.sub(unit, r'', string).strip())
|
||||||
if isint and unit in ('B', ''):
|
if isint and unit in ('B', ''):
|
||||||
if int(value) != value:
|
if int(value) != value:
|
||||||
raise AssertionError("invalid blocksize value: bytes require an integer value")
|
raise AssertionError("invalid blocksize value: bytes require an integer value")
|
||||||
|
|
|
@ -414,7 +414,7 @@ def main():
|
||||||
COMMANDARGS.extend(['--table', table])
|
COMMANDARGS.extend(['--table', table])
|
||||||
|
|
||||||
if wait is not None:
|
if wait is not None:
|
||||||
TESTCOMMAND.extend(['--wait', '%s' % wait])
|
TESTCOMMAND.extend(['--wait', '%d' % wait])
|
||||||
|
|
||||||
if modprobe is not None:
|
if modprobe is not None:
|
||||||
b_modprobe = to_bytes(modprobe, errors='surrogate_or_strict')
|
b_modprobe = to_bytes(modprobe, errors='surrogate_or_strict')
|
||||||
|
@ -502,7 +502,7 @@ def main():
|
||||||
MAINCOMMAND.insert(0, bin_iptables_restore)
|
MAINCOMMAND.insert(0, bin_iptables_restore)
|
||||||
|
|
||||||
if wait is not None:
|
if wait is not None:
|
||||||
MAINCOMMAND.extend(['--wait', '%s' % wait])
|
MAINCOMMAND.extend(['--wait', '%d' % wait])
|
||||||
|
|
||||||
if _back is not None:
|
if _back is not None:
|
||||||
b_back = to_bytes(_back, errors='surrogate_or_strict')
|
b_back = to_bytes(_back, errors='surrogate_or_strict')
|
||||||
|
|
|
@ -251,7 +251,7 @@ class ManageIQgroup(object):
|
||||||
if not tenant_res:
|
if not tenant_res:
|
||||||
self.module.fail_json(msg="Tenant '%s' not found in manageiq" % tenant_name)
|
self.module.fail_json(msg="Tenant '%s' not found in manageiq" % tenant_name)
|
||||||
if len(tenant_res) > 1:
|
if len(tenant_res) > 1:
|
||||||
self.module.fail_json(msg="Multiple tenants found in manageiq with name '%s" % tenant_name)
|
self.module.fail_json(msg="Multiple tenants found in manageiq with name '%s'" % tenant_name)
|
||||||
tenant = tenant_res[0]
|
tenant = tenant_res[0]
|
||||||
return tenant
|
return tenant
|
||||||
else:
|
else:
|
||||||
|
@ -276,7 +276,7 @@ class ManageIQgroup(object):
|
||||||
if not role_res:
|
if not role_res:
|
||||||
self.module.fail_json(msg="Role '%s' not found in manageiq" % role_name)
|
self.module.fail_json(msg="Role '%s' not found in manageiq" % role_name)
|
||||||
if len(role_res) > 1:
|
if len(role_res) > 1:
|
||||||
self.module.fail_json(msg="Multiple roles found in manageiq with name '%s" % role_name)
|
self.module.fail_json(msg="Multiple roles found in manageiq with name '%s'" % role_name)
|
||||||
return role_res[0]
|
return role_res[0]
|
||||||
else:
|
else:
|
||||||
# No role name or role id supplied
|
# No role name or role id supplied
|
||||||
|
|
|
@ -214,7 +214,7 @@ class ManageIQTenant(object):
|
||||||
self.module.fail_json(msg="Parent tenant '%s' not found in manageiq" % parent)
|
self.module.fail_json(msg="Parent tenant '%s' not found in manageiq" % parent)
|
||||||
|
|
||||||
if len(parent_tenant_res) > 1:
|
if len(parent_tenant_res) > 1:
|
||||||
self.module.fail_json(msg="Multiple parent tenants not found in manageiq with name '%s" % parent)
|
self.module.fail_json(msg="Multiple parent tenants not found in manageiq with name '%s'" % parent)
|
||||||
|
|
||||||
parent_tenant = parent_tenant_res[0]
|
parent_tenant = parent_tenant_res[0]
|
||||||
parent_id = int(parent_tenant['id'])
|
parent_id = int(parent_tenant['id'])
|
||||||
|
|
|
@ -210,7 +210,7 @@ def main():
|
||||||
rc, stdout, stderr = db_import(conn, cursor, module, db, target)
|
rc, stdout, stderr = db_import(conn, cursor, module, db, target)
|
||||||
|
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
module.fail_json(msg="%s" % stderr)
|
module.fail_json(msg=stderr)
|
||||||
else:
|
else:
|
||||||
module.exit_json(changed=True, db=db, msg=stdout)
|
module.exit_json(changed=True, db=db, msg=stdout)
|
||||||
else:
|
else:
|
||||||
|
@ -229,7 +229,7 @@ def main():
|
||||||
rc, stdout, stderr = db_import(conn, cursor, module, db, target)
|
rc, stdout, stderr = db_import(conn, cursor, module, db, target)
|
||||||
|
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
module.fail_json(msg="%s" % stderr)
|
module.fail_json(msg=stderr)
|
||||||
else:
|
else:
|
||||||
module.exit_json(changed=True, db=db, msg=stdout)
|
module.exit_json(changed=True, db=db, msg=stdout)
|
||||||
|
|
||||||
|
|
|
@ -576,7 +576,7 @@ def upgrade_packages(pkg_spec, module):
|
||||||
pkg_spec['*'] = {}
|
pkg_spec['*'] = {}
|
||||||
|
|
||||||
# Attempt to upgrade all packages.
|
# Attempt to upgrade all packages.
|
||||||
pkg_spec['*']['rc'], pkg_spec['*']['stdout'], pkg_spec['*']['stderr'] = execute_command("%s" % upgrade_cmd, module)
|
pkg_spec['*']['rc'], pkg_spec['*']['stdout'], pkg_spec['*']['stderr'] = execute_command(upgrade_cmd, module)
|
||||||
|
|
||||||
# Try to find any occurrence of a package changing version like:
|
# Try to find any occurrence of a package changing version like:
|
||||||
# "bzip2-1.0.6->1.0.6p0: ok".
|
# "bzip2-1.0.6->1.0.6p0: ok".
|
||||||
|
|
|
@ -546,7 +546,7 @@ def main():
|
||||||
insert_to = None
|
insert_to = None
|
||||||
cmd.append([insert_to is not None, "insert %s" % insert_to])
|
cmd.append([insert_to is not None, "insert %s" % insert_to])
|
||||||
cmd.append([value])
|
cmd.append([value])
|
||||||
cmd.append([params['direction'], "%s" % params['direction']])
|
cmd.append([params['direction'], params['direction']])
|
||||||
cmd.append([params['interface'], "on %s" % params['interface']])
|
cmd.append([params['interface'], "on %s" % params['interface']])
|
||||||
cmd.append([params['interface_in'], "in on %s" % params['interface_in']])
|
cmd.append([params['interface_in'], "in on %s" % params['interface_in']])
|
||||||
cmd.append([params['interface_out'], "out on %s" % params['interface_out']])
|
cmd.append([params['interface_out'], "out on %s" % params['interface_out']])
|
||||||
|
|
|
@ -178,7 +178,7 @@ def main():
|
||||||
try:
|
try:
|
||||||
session = get_xenapi_session()
|
session = get_xenapi_session()
|
||||||
except XenAPI.Failure as e:
|
except XenAPI.Failure as e:
|
||||||
module.fail_json(msg='%s' % e)
|
module.fail_json(msg=str(e))
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'xenserver_version': obj.version,
|
'xenserver_version': obj.version,
|
||||||
|
|
|
@ -188,9 +188,9 @@ class ZFSFacts(object):
|
||||||
cmd.append('-p')
|
cmd.append('-p')
|
||||||
if self.recurse:
|
if self.recurse:
|
||||||
cmd.append('-r')
|
cmd.append('-r')
|
||||||
if int(self.depth) != 0:
|
if self.depth != 0:
|
||||||
cmd.append('-d')
|
cmd.append('-d')
|
||||||
cmd.append('%s' % self.depth)
|
cmd.append('%d' % self.depth)
|
||||||
if self.type:
|
if self.type:
|
||||||
cmd.append('-t')
|
cmd.append('-t')
|
||||||
cmd.append(','.join(self.type))
|
cmd.append(','.join(self.type))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue