Skip to content

Commit

Permalink
linter run.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeyklyukin committed May 15, 2015
1 parent ffc9456 commit eb7881f
Showing 1 changed file with 25 additions and 27 deletions.
52 changes: 25 additions & 27 deletions pg_view.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__appname__ = 'pg_view'
__version__ = '1.2.0'
__author__ = 'Oleksii Kliukin <[email protected]>'
__license__ = 'Apache 2.0'

import os
import os.path
import re
import stat
import sys
Expand All @@ -26,6 +20,12 @@
import traceback
import json

__appname__ = 'pg_view'
__version__ = '1.2.0'
__author__ = 'Oleksii Kliukin <[email protected]>'
__license__ = 'Apache 2.0'


if sys.hexversion >= 0x03000000:
import configparser as ConfigParser
from queue import Empty
Expand Down Expand Up @@ -195,7 +195,7 @@ def __init__(self, ticks_per_refresh=1, produce_diffs=True):

def postinit(self):
for l in self.transform_list_data, self.transform_dict_data, self.diff_generator_data, \
self.output_transform_data:
self.output_transform_data:
self.validate_list_out(l)
self.output_column_positions = self._calculate_output_column_positions()

Expand Down Expand Up @@ -451,10 +451,10 @@ def curses_cook_value(self, attname, raw_val, output_data):
elif str(raw_val) == 'False':
val = 'F'
if output_data.get('maxw', 0) > 0 and not self.notrim and len(str(val)) > output_data['maxw']:
# if the value is higher than maximum allowed width - trim it byt removing chars from the middle
# if the value is higher than maximum allowed width - trim it byt removing chars from the middle
val = self._trim_text_middle(val, output_data['maxw'])
if self.ncurses_custom_fields.get('append_column_headers') or output_data.get('column_header',
COHEADER.ch_default) == COHEADER.ch_prepend:
COHEADER.ch_default) == COHEADER.ch_prepend:
val = '{0}|{1}'.format(attname, val)
elif output_data.get('column_header', COHEADER.ch_default) == COHEADER.ch_append:
val = '{0}|{1}'.format(val, attname)
Expand Down Expand Up @@ -498,12 +498,12 @@ def _produce_diff_row(self, prev, cur):
if 'diff' in col and col['diff'] is False:
result[attname] = (cur[incol] if incol in cur else None)
elif 'fn' in col:
# if diff is True and fn is supplied - apply it to the current and previous row.
# if diff is True and fn is supplied - apply it to the current and previous row.
result[attname] = (col['fn'](incol, cur, prev) if cur.get(incol, None) is not None and prev.get(incol,
None) is not None else None)
else:
# default case - calculate the diff between the current attribute's values of
# old and new rows and divide it by the time interval passed between measurements.
# default case - calculate the diff between the current attribute's values of
# old and new rows and divide it by the time interval passed between measurements.
result[attname] = ((cur[incol] - prev[incol]) / self.diff_time if cur.get(incol, None) is not None
and prev.get(incol, None) is not None and self.diff_time >= 0 else None)
return result
Expand Down Expand Up @@ -668,8 +668,8 @@ def _transform_dict(self, l, custom_transformation_data=None):
else:
result[attname] = None
elif incol not in l:
# if the column is marked as optional and it's not present in the output data
# set None instead
# if the column is marked as optional and it's not present in the output data
# set None instead
result[attname] = None
if not ('optional' in col and col['optional']):
self.warn_non_optional_column(incol)
Expand Down Expand Up @@ -1132,7 +1132,6 @@ def ident(self):
def _get_psinfo(cmdline):
""" gets PostgreSQL process type from the command-line."""
pstype = 'unknown'
psactivity = ''
if cmdline is not None and len(cmdline) > 0:
# postgres: stats collector process
m = re.match(r'postgres:\s+(.*)\s+process\s*(.*)$', cmdline)
Expand Down Expand Up @@ -1181,7 +1180,7 @@ def refresh(self):
if proc_data:
result_row.update(proc_data)
if stat_data and pid in stat_data:
# ditto for the pg_stat_activity
# ditto for the pg_stat_activity
result_row.update(stat_data[pid])
# result is not empty - add it to the list of current rows
if result_row:
Expand Down Expand Up @@ -1249,11 +1248,11 @@ def _get_memory_usage(self, pid):
statm = None
fp = None
try:
fp = open(PgstatCollector.STATM_FILENAME.format(pid), 'r')
fp = open(self.STATM_FILENAME.format(pid), 'r')
statm = fp.read().strip().split()
logger.info("calculating memory for process {0}".format(pid))
except IOError as e:
logger.warning('Unable to read {0}: {1}, process memory information will be unavailable'.format(STATM_FILENAME.format(pid), e))
logger.warning('Unable to read {0}: {1}, process memory information will be unavailable'.format(self.format(pid), e))
finally:
fp and fp.close()
if statm and len(statm) >= 3:
Expand Down Expand Up @@ -1407,8 +1406,9 @@ def _read_pg_stat_activity(self):
def ncurses_produce_prefix(self):
return "{1} {0} {5} database connections: {2} of {4} allocated,\
{3} active\n".format(self.dbver,
self.dbname, self.total_connections, self.active_connections, self.max_connections,
self.recovery_status)
self.dbname, self.total_connections,
self.active_connections, self.max_connections,
self.recovery_status)

def diff(self):
""" we only diff backend processes if new one is not idle and use pid to identify processes """
Expand Down Expand Up @@ -1656,7 +1656,7 @@ def _read_proc_stat(self):
# otherwise, the line is probably empty or bogus and should be skipped
result = self._transform_input(raw_result)
except IOError:
logger.error('Unable to read {0}, global data will be unavailable'.format(SystemStatCollector.PROC_STAT_FILENAME))
logger.error('Unable to read {0}, global data will be unavailable'.format(self.PROC_STAT_FILENAME))
return result

def _cpu_time_diff(self, colname, cur, prev):
Expand Down Expand Up @@ -1854,7 +1854,6 @@ def get_io_data(self, pnames):
fp and fp.close()
return result


def output(self, method):
return super(self.__class__, self).output(method, before_string='PostgreSQL partitions:', after_string='\n')

Expand Down Expand Up @@ -2088,7 +2087,7 @@ def _read_load_average(self):
def _load_avg_state(self, row, col):
state = {}
load_avg_str = row[self.output_column_positions[col['out']]]
if load_avg_str == None:
if not load_avg_str:
return {}
# load average consists of 3 values.
load_avg_vals = load_avg_str.split()
Expand Down Expand Up @@ -2381,7 +2380,7 @@ def color_text(self, status_map, highlight, text):
status = status_map[no]
color = self._status_to_color(status, highlight)
elif -1 in status_map:
# -1 is catchall for all fields (i.e for queries)
# -1 is catchall for all fields (i.e for queries)
status = status_map[-1]
color = self._status_to_color(status, highlight)
else:
Expand Down Expand Up @@ -2429,9 +2428,8 @@ def help(self):
self.print_text(y, 0, "Press 'h' to exit this screen")

def show_collector_data(self, collector, clock=False):

if collector not in self.data or len(self.data[collector]) <= 0 or len(self.data[collector].get('rows', ())) \
<= 0 and not self.data[collector]['prefix']:
if collector not in self.data or len(self.data[collector]) <= 0 or\
len(self.data[collector].get('rows', ())) <= 0 and not self.data[collector]['prefix']:
return

rows = self.data[collector]['rows']
Expand Down

0 comments on commit eb7881f

Please sign in to comment.