1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Port postgresql module to python3 (#4579)

Iteritems is no longer a dict method in Python3, replace it with
the six wrapper.
This commit is contained in:
Michael Scherer 2016-08-31 17:08:12 +02:00 committed by Matt Clay
parent 839d5b6de4
commit f59af7d29e
2 changed files with 18 additions and 20 deletions

View file

@ -114,6 +114,7 @@ except ImportError:
postgresqldb_found = False postgresqldb_found = False
else: else:
postgresqldb_found = True postgresqldb_found = True
from ansible.module_utils.six import iteritems
class NotSupportedError(Exception): class NotSupportedError(Exception):
pass pass
@ -261,7 +262,7 @@ def main():
"login_password":"password", "login_password":"password",
"port":"port" "port":"port"
} }
kw = dict( (params_map[k], v) for (k, v) in module.params.iteritems() kw = dict( (params_map[k], v) for (k, v) in iteritems(module.params)
if k in params_map and v != '' ) if k in params_map and v != '' )
# If a login_unix_socket is specified, incorporate it here. # If a login_unix_socket is specified, incorporate it here.

View file

@ -170,6 +170,7 @@ except ImportError:
postgresqldb_found = False postgresqldb_found = False
else: else:
postgresqldb_found = True postgresqldb_found = True
from ansible.module_utils.six import iteritems
_flags = ('SUPERUSER', 'CREATEROLE', 'CREATEUSER', 'CREATEDB', 'INHERIT', 'LOGIN', 'REPLICATION') _flags = ('SUPERUSER', 'CREATEROLE', 'CREATEUSER', 'CREATEDB', 'INHERIT', 'LOGIN', 'REPLICATION')
VALID_FLAGS = frozenset(itertools.chain(_flags, ('NO%s' % f for f in _flags))) VALID_FLAGS = frozenset(itertools.chain(_flags, ('NO%s' % f for f in _flags)))
@ -421,15 +422,13 @@ def revoke_privileges(cursor, user, privs):
changed = False changed = False
for type_ in privs: for type_ in privs:
revoke_func = { for name, privileges in iteritems(privs[type_]):
'table':revoke_table_privilege, # Check that any of the privileges requested to be removed are
'database':revoke_database_privilege # currently granted to the user
}[type_] differences = check_funcs[type_](cursor, user, name, privileges)
for name, privileges in privs[type_].iteritems(): if differences[0]:
for privilege in privileges: revoke_funcs[type_](cursor, user, name, privileges)
changed = revoke_func(cursor, user, name, privilege)\ changed = True
or changed
return changed return changed
def grant_privileges(cursor, user, privs): def grant_privileges(cursor, user, privs):
@ -441,15 +440,13 @@ def grant_privileges(cursor, user, privs):
changed = False changed = False
for type_ in privs: for type_ in privs:
grant_func = { for name, privileges in iteritems(privs[type_]):
'table':grant_table_privilege, # Check that any of the privileges requested for the user are
'database':grant_database_privilege # currently missing
}[type_] differences = check_funcs[type_](cursor, user, name, privileges)
for name, privileges in privs[type_].iteritems(): if differences[2]:
for privilege in privileges: grant_funcs[type_](cursor, user, name, privileges)
changed = grant_func(cursor, user, name, privilege)\ changed = True
or changed
return changed return changed
def parse_role_attrs(role_attr_flags): def parse_role_attrs(role_attr_flags):
@ -574,7 +571,7 @@ def main():
"port":"port", "port":"port",
"db":"database" "db":"database"
} }
kw = dict( (params_map[k], v) for (k, v) in module.params.iteritems() kw = dict( (params_map[k], v) for (k, v) in iteritems(module.params)
if k in params_map and v != "" ) if k in params_map and v != "" )
# If a login_unix_socket is specified, incorporate it here. # If a login_unix_socket is specified, incorporate it here.