From 186210af8a607fea129ade78c836d19682ecffb8 Mon Sep 17 00:00:00 2001
From: Andrey Klychkov <aaklychkov@mail.ru>
Date: Tue, 18 Jun 2019 13:03:16 +0300
Subject: [PATCH] postgresql modules: remove unused imports, remove blank lines
 after docstrings

---
 .../database/postgresql/postgresql_copy.py    |  5 --
 .../database/postgresql/postgresql_idx.py     |  6 --
 .../database/postgresql/postgresql_info.py    | 57 +++++--------------
 .../postgresql/postgresql_membership.py       |  3 +-
 .../database/postgresql/postgresql_owner.py   |  6 +-
 .../database/postgresql/postgresql_ping.py    |  5 +-
 .../database/postgresql/postgresql_query.py   |  2 -
 .../postgresql/postgresql_sequence.py         |  1 -
 .../database/postgresql/postgresql_set.py     |  1 -
 .../database/postgresql/postgresql_slot.py    |  2 -
 .../database/postgresql/postgresql_table.py   |  3 +-
 .../postgresql/postgresql_tablespace.py       | 11 +---
 12 files changed, 19 insertions(+), 83 deletions(-)

diff --git a/lib/ansible/modules/database/postgresql/postgresql_copy.py b/lib/ansible/modules/database/postgresql/postgresql_copy.py
index d4515010822..45810b31dd6 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_copy.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_copy.py
@@ -180,7 +180,6 @@ from ansible.module_utils.postgres import (
     exec_sql,
     postgres_common_argument_spec,
 )
-from ansible.module_utils._text import to_native
 from ansible.module_utils.six import iteritems
 
 
@@ -220,7 +219,6 @@ class PgCopyData(object):
 
     def copy_from(self):
         """Implements COPY FROM command behavior."""
-
         self.src = self.module.params['copy_from']
         self.dst = self.module.params['dst']
 
@@ -251,7 +249,6 @@ class PgCopyData(object):
 
     def copy_to(self):
         """Implements COPY TO command behavior."""
-
         self.src = self.module.params['src']
         self.dst = self.module.params['copy_to']
 
@@ -287,7 +284,6 @@ class PgCopyData(object):
 
     def __transform_options(self):
         """Transform options dict into a suitable string."""
-
         for (key, val) in iteritems(self.module.params['options']):
             if key.upper() in self.opt_need_quotes:
                 self.module.params['options'][key] = "'%s'" % val
@@ -305,7 +301,6 @@ class PgCopyData(object):
                 It can be SQL SELECT statement that was passed
                 instead of the table name.
         """
-
         if 'SELECT ' in table.upper():
             # In this case table is actually SQL SELECT statement.
             # If SQL fails, it's handled by exec_sql():
diff --git a/lib/ansible/modules/database/postgresql/postgresql_idx.py b/lib/ansible/modules/database/postgresql/postgresql_idx.py
index f0100aa5ca1..6d711ebf9cd 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_idx.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_idx.py
@@ -227,13 +227,11 @@ except ImportError:
     pass
 
 from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.database import SQLParseError
 from ansible.module_utils.postgres import (
     connect_to_db,
     exec_sql,
     postgres_common_argument_spec,
 )
-from ansible.module_utils._text import to_native
 
 
 VALID_IDX_TYPES = ('BTREE', 'HASH', 'GIST', 'SPGIST', 'GIN', 'BRIN')
@@ -295,7 +293,6 @@ class Index(object):
 
         Return self.info dict.
         """
-
         self.__exists_in_db()
         return self.info
 
@@ -304,7 +301,6 @@ class Index(object):
 
         Return True if the index exists, otherwise, return False.
         """
-
         query = ("SELECT i.schemaname, i.tablename, i.tablespace, "
                  "pi.indisvalid, c.reloptions "
                  "FROM pg_catalog.pg_indexes AS i "
@@ -347,7 +343,6 @@ class Index(object):
         Kwargs:
             concurrent (bool) -- build index in concurrent mode, default True
         """
-
         if self.exists:
             return False
 
@@ -398,7 +393,6 @@ class Index(object):
                 default False
             concurrent (bool) -- build index in concurrent mode, default True
         """
-
         changed = False
         if not self.exists:
             return False
diff --git a/lib/ansible/modules/database/postgresql/postgresql_info.py b/lib/ansible/modules/database/postgresql/postgresql_info.py
index f9e1763674a..08a5e0daf0c 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_info.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_info.py
@@ -474,11 +474,9 @@ except ImportError:
     # from ansible.module_utils.postgres
     pass
 
-from ansible.module_utils.basic import AnsibleModule, missing_required_lib
-from ansible.module_utils.database import SQLParseError
+from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils.postgres import connect_to_db, postgres_common_argument_spec
 from ansible.module_utils._text import to_native
-from ansible.module_utils.six import iteritems
 
 
 # ===========================================
@@ -544,9 +542,7 @@ class PgClusterInfo(object):
         }
 
     def collect(self, val_list=False):
-        """
-        Collect information based on 'filter' option.
-        """
+        """Collect information based on 'filter' option."""
         subset_map = {
             "version": self.get_pg_version,
             "tablespaces": self.get_tablespaces,
@@ -598,9 +594,7 @@ class PgClusterInfo(object):
         return self.pg_info
 
     def get_tablespaces(self):
-        """
-        Get information about tablespaces.
-        """
+        """Get information about tablespaces."""
         # Check spcoption exists:
         opt = self.__exec_sql("SELECT column_name "
                               "FROM information_schema.columns "
@@ -632,9 +626,7 @@ class PgClusterInfo(object):
         self.pg_info["tablespaces"] = ts_dict
 
     def get_ext_info(self):
-        """
-        Get information about existing extensions.
-        """
+        """Get information about existing extensions."""
         # Check that pg_extension exists:
         res = self.__exec_sql("SELECT EXISTS (SELECT 1 FROM "
                               "information_schema.tables "
@@ -666,9 +658,7 @@ class PgClusterInfo(object):
         return ext_dict
 
     def get_role_info(self):
-        """
-        Get information about roles (in PgSQL groups and users are roles).
-        """
+        """Get information about roles (in PgSQL groups and users are roles)."""
         query = ("SELECT r.rolname, r.rolsuper, r.rolcanlogin, "
                  "r.rolvaliduntil, "
                  "ARRAY(SELECT b.rolname "
@@ -691,9 +681,7 @@ class PgClusterInfo(object):
         self.pg_info["roles"] = rol_dict
 
     def get_rslot_info(self):
-        """
-        Get information about replication slots if exist.
-        """
+        """Get information about replication slots if exist."""
         # Check that pg_replication_slots exists:
         res = self.__exec_sql("SELECT EXISTS (SELECT 1 FROM "
                               "information_schema.tables "
@@ -721,9 +709,7 @@ class PgClusterInfo(object):
         self.pg_info["repl_slots"] = rslot_dict
 
     def get_settings(self):
-        """
-        Get server settings.
-        """
+        """Get server settings."""
         # Check pending restart column exists:
         pend_rest_col_exists = self.__exec_sql("SELECT 1 FROM information_schema.columns "
                                                "WHERE table_name = 'pg_settings' "
@@ -789,9 +775,7 @@ class PgClusterInfo(object):
         self.pg_info["settings"] = set_dict
 
     def get_repl_info(self):
-        """
-        Get information about replication if the server is a master.
-        """
+        """Get information about replication if the server is a master."""
         # Check that pg_replication_slots exists:
         res = self.__exec_sql("SELECT EXISTS (SELECT 1 FROM "
                               "information_schema.tables "
@@ -823,9 +807,7 @@ class PgClusterInfo(object):
         self.pg_info["replications"] = repl_dict
 
     def get_lang_info(self):
-        """
-        Get information about current supported languages.
-        """
+        """Get information about current supported languages."""
         query = ("SELECT l.lanname, a.rolname, l.lanacl "
                  "FROM pg_language AS l "
                  "JOIN pg_authid AS a ON l.lanowner = a.oid")
@@ -840,9 +822,7 @@ class PgClusterInfo(object):
         return lang_dict
 
     def get_namespaces(self):
-        """
-        Get information about namespaces.
-        """
+        """Get information about namespaces."""
         query = ("SELECT n.nspname, a.rolname, n.nspacl "
                  "FROM pg_catalog.pg_namespace AS n "
                  "JOIN pg_authid AS a ON a.oid = n.nspowner")
@@ -858,9 +838,7 @@ class PgClusterInfo(object):
         return nsp_dict
 
     def get_pg_version(self):
-        """
-        Get major and minor PostgreSQL server version.
-        """
+        """Get major and minor PostgreSQL server version."""
         query = "SELECT version()"
         raw = self.__exec_sql(query)[0][0]
         raw = raw.split()[1].split('.')
@@ -870,10 +848,7 @@ class PgClusterInfo(object):
         )
 
     def get_db_info(self):
-        """
-        Get information about the current database.
-        """
-
+        """Get information about the current database."""
         # Following query returns:
         # Name, Owner, Encoding, Collate, Ctype, Access Priv, Size
         query = ("SELECT d.datname, "
@@ -912,15 +887,11 @@ class PgClusterInfo(object):
         self.pg_info["databases"] = db_dict
 
     def __get_pretty_val(self, setting):
-        """
-        Get setting's value represented by SHOW command.
-        """
+        """Get setting's value represented by SHOW command."""
         return self.__exec_sql("SHOW %s" % setting)[0][0]
 
     def __exec_sql(self, query):
-        """
-        Execute SQL and return the result.
-        """
+        """Execute SQL and return the result."""
         try:
             self.cursor.execute(query)
             res = self.cursor.fetchall()
diff --git a/lib/ansible/modules/database/postgresql/postgresql_membership.py b/lib/ansible/modules/database/postgresql/postgresql_membership.py
index 55c1b14468e..a121bccc76d 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_membership.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_membership.py
@@ -143,13 +143,12 @@ except ImportError:
     pass
 
 from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.database import SQLParseError, pg_quote_identifier
+from ansible.module_utils.database import pg_quote_identifier
 from ansible.module_utils.postgres import (
     connect_to_db,
     exec_sql,
     postgres_common_argument_spec,
 )
-from ansible.module_utils._text import to_native
 
 
 class PgMembership(object):
diff --git a/lib/ansible/modules/database/postgresql/postgresql_owner.py b/lib/ansible/modules/database/postgresql/postgresql_owner.py
index d837b49c978..37ec8256c5a 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_owner.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_owner.py
@@ -157,13 +157,12 @@ except ImportError:
     pass
 
 from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.database import SQLParseError, pg_quote_identifier
+from ansible.module_utils.database import pg_quote_identifier
 from ansible.module_utils.postgres import (
     connect_to_db,
     exec_sql,
     postgres_common_argument_spec,
 )
-from ansible.module_utils._text import to_native
 
 
 class PgOwnership(object):
@@ -225,7 +224,6 @@ class PgOwnership(object):
             fail_on_role (bool): If True, fail when a role from old_owners does not exist.
                 Otherwise just warn and continue.
         """
-
         roles = []
         for r in old_owners:
             if self.check_role_exists(r, fail_on_role):
@@ -251,7 +249,6 @@ class PgOwnership(object):
             obj_type (str): Type of object (like database, table, view, etc.).
             obj_name (str): Object name.
         """
-
         self.obj_name = obj_name
         self.obj_type = obj_type
 
@@ -286,7 +283,6 @@ class PgOwnership(object):
 
     def __is_owner(self):
         """Return True if self.role is the current object owner."""
-
         if self.obj_type == 'table':
             query = ("SELECT 1 FROM pg_tables WHERE tablename = '%s' "
                      "AND tableowner = '%s'" % (self.obj_name, self.role))
diff --git a/lib/ansible/modules/database/postgresql/postgresql_ping.py b/lib/ansible/modules/database/postgresql/postgresql_ping.py
index a3ac5aa7d3c..12bb3792bf4 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_ping.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_ping.py
@@ -78,15 +78,12 @@ except ImportError:
     # from ansible.module_utils.postgres
     pass
 
-from ansible.module_utils.basic import AnsibleModule, missing_required_lib
-from ansible.module_utils.database import SQLParseError
+from ansible.module_utils.basic import AnsibleModule
 from ansible.module_utils.postgres import (
     connect_to_db,
     exec_sql,
     postgres_common_argument_spec,
 )
-from ansible.module_utils._text import to_native
-from ansible.module_utils.six import iteritems
 
 
 # ===========================================
diff --git a/lib/ansible/modules/database/postgresql/postgresql_query.py b/lib/ansible/modules/database/postgresql/postgresql_query.py
index d5397839982..2823afefa1c 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_query.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_query.py
@@ -145,9 +145,7 @@ except ImportError:
     # ansible.module_utils.postgres
     pass
 
-import ansible.module_utils.postgres as pgutils
 from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.database import SQLParseError
 from ansible.module_utils.postgres import connect_to_db, postgres_common_argument_spec
 from ansible.module_utils._text import to_native
 
diff --git a/lib/ansible/modules/database/postgresql/postgresql_sequence.py b/lib/ansible/modules/database/postgresql/postgresql_sequence.py
index d74d97cdb23..0890ecc7460 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_sequence.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_sequence.py
@@ -289,7 +289,6 @@ from ansible.module_utils.postgres import (
     exec_sql,
     postgres_common_argument_spec,
 )
-from ansible.module_utils._text import to_native
 
 
 class Sequence(object):
diff --git a/lib/ansible/modules/database/postgresql/postgresql_set.py b/lib/ansible/modules/database/postgresql/postgresql_set.py
index a1e79724a66..57b8b31cd6c 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_set.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_set.py
@@ -165,7 +165,6 @@ except Exception:
 from copy import deepcopy
 
 from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.database import SQLParseError
 from ansible.module_utils.postgres import connect_to_db, postgres_common_argument_spec
 from ansible.module_utils._text import to_native
 
diff --git a/lib/ansible/modules/database/postgresql/postgresql_slot.py b/lib/ansible/modules/database/postgresql/postgresql_slot.py
index a9c35969868..3427764bd66 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_slot.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_slot.py
@@ -149,13 +149,11 @@ except ImportError:
     pass
 
 from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.database import SQLParseError
 from ansible.module_utils.postgres import (
     connect_to_db,
     exec_sql,
     postgres_common_argument_spec,
 )
-from ansible.module_utils._text import to_native
 
 
 # ===========================================
diff --git a/lib/ansible/modules/database/postgresql/postgresql_table.py b/lib/ansible/modules/database/postgresql/postgresql_table.py
index c06f40142c8..20b99d77abd 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_table.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_table.py
@@ -236,13 +236,12 @@ except ImportError:
     pass
 
 from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.database import SQLParseError, pg_quote_identifier
+from ansible.module_utils.database import pg_quote_identifier
 from ansible.module_utils.postgres import (
     connect_to_db,
     exec_sql,
     postgres_common_argument_spec,
 )
-from ansible.module_utils._text import to_native
 
 
 # ===========================================
diff --git a/lib/ansible/modules/database/postgresql/postgresql_tablespace.py b/lib/ansible/modules/database/postgresql/postgresql_tablespace.py
index ff093ef0c4d..e34136f29b5 100644
--- a/lib/ansible/modules/database/postgresql/postgresql_tablespace.py
+++ b/lib/ansible/modules/database/postgresql/postgresql_tablespace.py
@@ -172,13 +172,12 @@ except ImportError:
     pass
 
 from ansible.module_utils.basic import AnsibleModule
-from ansible.module_utils.database import SQLParseError, pg_quote_identifier
+from ansible.module_utils.database import pg_quote_identifier
 from ansible.module_utils.postgres import (
     connect_to_db,
     exec_sql,
     postgres_common_argument_spec,
 )
-from ansible.module_utils._text import to_native
 
 
 class PgTablespace(object):
@@ -218,7 +217,6 @@ class PgTablespace(object):
 
     def get_info(self):
         """Get tablespace information."""
-
         # Check that spcoptions exists:
         opt = exec_sql(self, "SELECT 1 FROM information_schema.columns "
                              "WHERE table_name = 'pg_tablespace' "
@@ -275,7 +273,6 @@ class PgTablespace(object):
         args:
             location (str) -- tablespace directory path in the FS
         """
-
         query = ("CREATE TABLESPACE %s LOCATION '%s'" % (pg_quote_identifier(self.name, 'database'), location))
         return exec_sql(self, query, ddl=True)
 
@@ -284,7 +281,6 @@ class PgTablespace(object):
 
         Return True if success, otherwise, return False.
         """
-
         return exec_sql(self, "DROP TABLESPACE %s" % pg_quote_identifier(self.name, 'database'), ddl=True)
 
     def set_owner(self, new_owner):
@@ -295,7 +291,6 @@ class PgTablespace(object):
         args:
             new_owner (str) -- name of a new owner for the tablespace"
         """
-
         if new_owner == self.owner:
             return False
 
@@ -310,7 +305,6 @@ class PgTablespace(object):
         args:
             newname (str) -- new name for the tablespace"
         """
-
         query = "ALTER TABLESPACE %s RENAME TO %s" % (pg_quote_identifier(self.name, 'database'), newname)
         self.new_name = newname
         return exec_sql(self, query, ddl=True)
@@ -324,7 +318,6 @@ class PgTablespace(object):
         args:
             new_settings (list) -- list of new settings
         """
-
         # settings must be a dict {'key': 'value'}
         if self.opt_not_supported:
             return False
@@ -351,7 +344,6 @@ class PgTablespace(object):
         args:
             setting (str) -- string in format "setting_name = 'setting_value'"
         """
-
         query = "ALTER TABLESPACE %s RESET (%s)" % (pg_quote_identifier(self.name, 'database'), setting)
         return exec_sql(self, query, ddl=True)
 
@@ -363,7 +355,6 @@ class PgTablespace(object):
         args:
             setting (str) -- string in format "setting_name = 'setting_value'"
         """
-
         query = "ALTER TABLESPACE %s SET (%s)" % (pg_quote_identifier(self.name, 'database'), setting)
         return exec_sql(self, query, ddl=True)