From ec82bf842d2c8537bf020909cfd406ec0ec3f023 Mon Sep 17 00:00:00 2001 From: Sandro Bonazzola Date: Tue, 4 Feb 2014 15:15:10 +0000 Subject: [PATCH 11/72] postgresql: minor fixes - pep8 / style fixes - Avoid redefining built-in 'file' Signed-off-by: Sandro Bonazzola Signed-off-by: Bryn M. Reeves --- sos/plugins/postgresql.py | 60 ++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/sos/plugins/postgresql.py b/sos/plugins/postgresql.py index 0a8e5ac..478faff 100644 --- a/sos/plugins/postgresql.py +++ b/sos/plugins/postgresql.py @@ -4,6 +4,7 @@ import tempfile from sos.plugins import Plugin, RedHatPlugin, UbuntuPlugin, DebianPlugin from sos.utilities import find + class PostgreSQL(Plugin): """PostgreSQL related information""" @@ -14,26 +15,31 @@ class PostgreSQL(Plugin): tmp_dir = None option_list = [ - ("pghome", 'PostgreSQL server home directory.', '', '/var/lib/pgsql'), - ("username", 'username for pg_dump', '', 'postgres'), - ("password", 'password for pg_dump', '', ''), - ("dbname", 'database name to dump for pg_dump', '', ''), + ('pghome', 'PostgreSQL server home directory.', '', '/var/lib/pgsql'), + ('username', 'username for pg_dump', '', 'postgres'), + ('password', 'password for pg_dump', '', ''), + ('dbname', 'database name to dump for pg_dump', '', ''), ] def pg_dump(self): dest_file = os.path.join(self.tmp_dir, "sos_pgdump.tar") old_env_pgpassword = os.environ.get("PGPASSWORD") os.environ["PGPASSWORD"] = self.get_option("password") - (status, output, rtime) = self.call_ext_prog("pg_dump %s -U %s -w -f %s -F t" % - (self.get_option("dbname"), - self.get_option("username"), - dest_file)) + (status, output, rtime) = self.call_ext_prog( + "pg_dump %s -U %s -w -f %s -F t" % ( + self.get_option("dbname"), + self.get_option("username"), + dest_file + ) + ) if old_env_pgpassword is not None: os.environ["PGPASSWORD"] = old_env_pgpassword if (status == 0): self.add_copy_spec(dest_file) else: - self.add_alert("ERROR: Unable to execute pg_dump. Error(%s)" % (output)) + self.add_alert( + "ERROR: Unable to execute pg_dump. Error(%s)" % (output) + ) def setup(self): if self.get_option("dbname"): @@ -41,13 +47,16 @@ class PostgreSQL(Plugin): self.tmp_dir = tempfile.mkdtemp() self.pg_dump() else: - self.add_alert("WARN: password must be supplied to dump a database.") + self.add_alert( + "WARN: password must be supplied to dump a database." + ) def postproc(self): import shutil if self.tmp_dir: shutil.rmtree(self.tmp_dir) + class RedHatPostgreSQL(PostgreSQL, RedHatPlugin): """PostgreSQL related information for Red Hat distributions""" @@ -55,14 +64,27 @@ class RedHatPostgreSQL(PostgreSQL, RedHatPlugin): super(RedHatPostgreSQL, self).setup() # Copy PostgreSQL log files. - for file in find("*.log", self.get_option("pghome")): - self.add_copy_spec(file) + for filename in find("*.log", self.get_option("pghome")): + self.add_copy_spec(filename) # Copy PostgreSQL config files. - for file in find("*.conf", self.get_option("pghome")): - self.add_copy_spec(file) + for filename in find("*.conf", self.get_option("pghome")): + self.add_copy_spec(filename) + + self.add_copy_spec( + os.path.join( + self.get_option("pghome"), + "data", + "PG_VERSION" + ) + ) + self.add_copy_spec( + os.path.join( + self.get_option("pghome"), + "data", + "postmaster.opts" + ) + ) - self.add_copy_spec(os.path.join(self.get_option("pghome"), "data" , "PG_VERSION")) - self.add_copy_spec(os.path.join(self.get_option("pghome"), "data" , "postmaster.opts")) class DebianPostgreSQL(PostgreSQL, DebianPlugin, UbuntuPlugin): """PostgreSQL related information for Debian/Ubuntu distributions""" @@ -78,8 +100,4 @@ class DebianPostgreSQL(PostgreSQL, DebianPlugin, UbuntuPlugin): self.add_copy_spec("/var/lib/postgresql/*/main/PG_VERSION") self.add_copy_spec("/var/lib/postgresql/*/main/postmaster.opts") - - - - - +# vim: expandtab tabstop=4 shiftwidth=4 -- 1.9.3