Bulk autopep8 (modules)

As agreed in 2017-12-07 Core meeting bulk fix pep8 issues

Generated using:
autopep8 1.3.3 (pycodestyle: 2.3.1)
autopep8 -r  --max-line-length 160 --in-place --ignore E305,E402,E722,E741 lib/ansible/modules

Manually fix issues that autopep8 has introduced
This commit is contained in:
John Barker 2017-12-07 16:27:06 +00:00 committed by John R Barker
parent d13d7e9404
commit c57a7f05e1
314 changed files with 3462 additions and 3383 deletions

View file

@ -99,6 +99,7 @@ def ext_exists(cursor, ext):
cursor.execute(query, {'ext': ext})
return cursor.rowcount == 1
def ext_delete(cursor, ext):
if ext_exists(cursor, ext):
query = "DROP EXTENSION \"%s\"" % ext
@ -107,6 +108,7 @@ def ext_delete(cursor, ext):
else:
return False
def ext_create(cursor, ext):
if not ext_exists(cursor, ext):
query = 'CREATE EXTENSION "%s"' % ext
@ -119,6 +121,7 @@ def ext_create(cursor, ext):
# Module execution.
#
def main():
module = AnsibleModule(
argument_spec=dict(
@ -130,7 +133,7 @@ def main():
ext=dict(required=True, aliases=['name']),
state=dict(default="present", choices=["absent", "present"]),
),
supports_check_mode = True
supports_check_mode=True
)
if not postgresqldb_found:
@ -145,13 +148,13 @@ def main():
# check which values are empty and don't include in the **kw
# dictionary
params_map = {
"login_host":"host",
"login_user":"user",
"login_password":"password",
"port":"port"
"login_host": "host",
"login_user": "user",
"login_password": "password",
"port": "port"
}
kw = dict( (params_map[k], v) for (k, v) in module.params.items()
if k in params_map and v != '' )
kw = dict((params_map[k], v) for (k, v) in module.params.items()
if k in params_map and v != '')
try:
db_connection = psycopg2.connect(database=db, **kw)
# Enable autocommit so we can create databases

View file

@ -161,18 +161,21 @@ def lang_exists(cursor, lang):
cursor.execute(query)
return cursor.rowcount > 0
def lang_istrusted(cursor, lang):
"""Checks if language is trusted for db"""
query = "SELECT lanpltrusted FROM pg_language WHERE lanname='%s'" % lang
cursor.execute(query)
return cursor.fetchone()[0]
def lang_altertrust(cursor, lang, trust):
"""Changes if language is trusted for db"""
query = "UPDATE pg_language SET lanpltrusted = %s WHERE lanname=%s"
cursor.execute(query, (trust, lang))
return True
def lang_add(cursor, lang, trust):
"""Adds language for db"""
if trust:
@ -182,6 +185,7 @@ def lang_add(cursor, lang, trust):
cursor.execute(query)
return True
def lang_drop(cursor, lang, cascade):
"""Drops language for db"""
cursor.execute("SAVEPOINT ansible_pgsql_lang_drop")
@ -197,6 +201,7 @@ def lang_drop(cursor, lang, cascade):
cursor.execute("RELEASE SAVEPOINT ansible_pgsql_lang_drop")
return True
def main():
module = AnsibleModule(
argument_spec=dict(
@ -212,7 +217,7 @@ def main():
cascade=dict(type='bool', default='no'),
fail_on_drop=dict(type='bool', default='yes'),
),
supports_check_mode = True
supports_check_mode=True
)
db = module.params["db"]
@ -227,14 +232,14 @@ def main():
module.fail_json(msg="the python psycopg2 module is required")
params_map = {
"login_host":"host",
"login_user":"user",
"login_password":"password",
"port":"port",
"db":"database"
"login_host": "host",
"login_user": "user",
"login_password": "password",
"port": "port",
"db": "database"
}
kw = dict( (params_map[k], v) for (k, v) in module.params.items()
if k in params_map and v != "" )
kw = dict((params_map[k], v) for (k, v) in module.params.items()
if k in params_map and v != "")
try:
db_connection = psycopg2.connect(**kw)
cursor = db_connection.cursor()

View file

@ -125,6 +125,7 @@ def set_owner(cursor, schema, owner):
cursor.execute(query)
return True
def get_schema_info(cursor, schema):
query = """
SELECT schema_owner AS owner
@ -134,11 +135,13 @@ def get_schema_info(cursor, schema):
cursor.execute(query, {'schema': schema})
return cursor.fetchone()
def schema_exists(cursor, schema):
query = "SELECT schema_name FROM information_schema.schemata WHERE schema_name = %(schema)s"
cursor.execute(query, {'schema': schema})
return cursor.rowcount == 1
def schema_delete(cursor, schema):
if schema_exists(cursor, schema):
query = "DROP SCHEMA %s" % pg_quote_identifier(schema, 'schema')
@ -147,6 +150,7 @@ def schema_delete(cursor, schema):
else:
return False
def schema_create(cursor, schema, owner):
if not schema_exists(cursor, schema):
query_fragments = ['CREATE SCHEMA %s' % pg_quote_identifier(schema, 'schema')]
@ -162,6 +166,7 @@ def schema_create(cursor, schema, owner):
else:
return False
def schema_matches(cursor, schema, owner):
if not schema_exists(cursor, schema):
return False
@ -176,6 +181,7 @@ def schema_matches(cursor, schema, owner):
# Module execution.
#
def main():
module = AnsibleModule(
argument_spec=dict(
@ -189,7 +195,7 @@ def main():
database=dict(default="postgres"),
state=dict(default="present", choices=["absent", "present"]),
),
supports_check_mode = True
supports_check_mode=True
)
if not postgresqldb_found:
@ -205,13 +211,13 @@ def main():
# check which values are empty and don't include in the **kw
# dictionary
params_map = {
"login_host":"host",
"login_user":"user",
"login_password":"password",
"port":"port"
"login_host": "host",
"login_user": "user",
"login_password": "password",
"port": "port"
}
kw = dict( (params_map[k], v) for (k, v) in module.params.items()
if k in params_map and v != '' )
kw = dict((params_map[k], v) for (k, v) in module.params.items()
if k in params_map and v != '')
# If a login_unix_socket is specified, incorporate it here.
is_localhost = "host" not in kw or kw["host"] == "" or kw["host"] == "localhost"