Skip to content

Commit

Permalink
Fixed setup.py, flake8 stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rsiera committed Dec 5, 2016
1 parent 6b259a5 commit 4e0e35d
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 42 deletions.
10 changes: 4 additions & 6 deletions pg_view/models/clients.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import sys
import psycopg2

from pg_view.exceptions import NotConnectedError, NoPidConnectionError, DuplicatedConnectionError
from pg_view.parsers import ProcNetParser, ProcWorker
from pg_view.models.collector_pg import dbversion_as_float
from pg_view.models.collector_base import logger

if sys.hexversion >= 0x03000000:
pass
else:
pass

import psycopg2

from pg_view.parsers import ProcNetParser, ProcWorker
from pg_view.models.collector_pg import dbversion_as_float
from pg_view.models.collector_base import logger


def read_postmaster_pid(work_directory, dbname):
""" Parses the postgres directory tree and extracts the pid of the postmaster process """
Expand Down
3 changes: 2 additions & 1 deletion pg_view/models/collector_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def _produce_diff_row(self, prev, cur):
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.
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)
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.
Expand Down
5 changes: 4 additions & 1 deletion pg_view/models/collector_pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def get_proc_data(self, pid):
'starttime': datetime.fromtimestamp(process.create_time()),
'locked_by': process.username(),
'guest_time': cpu_times.guest if hasattr(cpu_times, 'guest') else 0.0,
'delayacct_blkio_ticks': cpu_times.delayacct_blkio_ticks if hasattr(cpu_times, 'delayacct_blkio_ticks') else 0,
'delayacct_blkio_ticks': self.delayactt_blkio_ticks_or_default(cpu_times),
}

io_stats = self.get_io_counters(process)
Expand All @@ -327,6 +327,9 @@ def get_proc_data(self, pid):
result['cmdline'] = process.cmdline()[0].strip()
return result

def delayactt_blkio_ticks_or_default(self, cpu_times):
return cpu_times.delayacct_blkio_ticks if hasattr(cpu_times, 'delayacct_blkio_ticks') else 0

def get_io_counters(self, process):
if not hasattr(process, 'io_counters'):
return {}
Expand Down
4 changes: 2 additions & 2 deletions pg_view/models/displayers.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ def curses_cook_value(self, attname, raw_val, output_data):
if output_data.get('maxw', 0) > 0 and not self.notrim and len(str(val)) > output_data['maxw']:
# if the value is larger than the maximum allowed width - trim it by removing chars from the middle
val = self._trim_text_middle(val, output_data['maxw'])
if self.ncurses_custom_fields.get('prepend_column_headers') or output_data.get('column_header',
COLHEADER.ch_default) == COLHEADER.ch_prepend:
if self.ncurses_custom_fields.get('prepend_column_headers') or output_data.get(
'column_header', COLHEADER.ch_default) == COLHEADER.ch_prepend:
header_position = COLHEADER.ch_prepend
elif output_data.get('column_header', COLHEADER.ch_default) == COLHEADER.ch_append:
header_position = COLHEADER.ch_append
Expand Down
11 changes: 8 additions & 3 deletions pg_view/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ def color_value(self, val, xcol, status_map, highlight, result):

def help(self):
y = 0
self.print_text(y, 0, '{0} {1} - a monitor for PostgreSQL related system statistics'.format(__appname__, __version__),
self.COLOR_NORMAL | curses.A_BOLD)
self.print_text(y, 0, '{0} {1} - a monitor for PostgreSQL related system statistics'.format(
__appname__, __version__), self.COLOR_NORMAL | curses.A_BOLD)
y += 1
self.print_text(y, 0, 'Distributed under the terms of {0} license'.format(__license__))
y += 2
Expand Down Expand Up @@ -394,7 +394,12 @@ def display_prefix(self, collector, header):
def display_header(self, layout, align, types):
for field in layout:
text = self._align_field(
field, '', layout[field]['width'], align.get(field, COLALIGN.ca_none), types.get(field, COLTYPES.ct_string))
field,
'',
layout[field]['width'],
align.get(field, COLALIGN.ca_none),
types.get(field, COLTYPES.ct_string)
)
self.screen.addnstr(
self.next_y, layout[field]['start'], text, layout[field]['width'], self.COLOR_NORMAL | curses.A_BOLD)

Expand Down
2 changes: 1 addition & 1 deletion pg_view/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_pg_version_from_file(self, proc_pid, pg_dir):
try:
data = read_file(PG_VERSION_FILENAME).strip()
version = self._version_or_value_error(data)
except os.error as e:
except os.error:
logger.error('unable to read version number from PG_VERSION directory {0}, have to skip it'.format(pg_dir))
except ValueError:
logger.error("PG_VERSION doesn't contain a valid version number: {0}".format(data))
Expand Down
4 changes: 4 additions & 0 deletions pg_view/pathmagic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
30 changes: 13 additions & 17 deletions pg_view/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,31 @@
from __future__ import absolute_import

import logging
import os
import sys
import time
import traceback
from multiprocessing import JoinableQueue # for then number of cpus
from optparse import OptionParser

import os

path = os.path.dirname(os.path.dirname(__file__))
sys.path.insert(0, path)

from pg_view.outputs import CommonOutput, CursesOutput
import pg_view.consts as consts
from pg_view.factories import get_displayer_by_class
from pg_view.models.collector_base import BaseStatCollector
from pg_view.models.displayers import OUTPUT_METHOD
import pg_view.models.collector_base
import pg_view.pathmagic
from pg_view.exceptions import InvalidConnectionParamError, NotConnectedError, NoPidConnectionError, \
DuplicatedConnectionError
from pg_view.factories import get_displayer_by_class
from pg_view.helpers import process_groups, read_configuration, validate_autodetected_conn_param
from pg_view.models.clients import make_cluster_desc, DBClient
from pg_view.models.collector_host import HostStatCollector
from pg_view.models.collector_memory import MemoryStatCollector
from pg_view.models.collector_partition import PartitionStatCollector, DetachedDiskStatCollector
from pg_view.models.collector_pg import PgStatCollector
from pg_view.models.collector_system import SystemStatCollector
from pg_view.validators import get_valid_output_methods, output_method_is_valid
from pg_view.models.consumers import DiskCollectorConsumer
from pg_view.models.clients import make_cluster_desc, DBClient
from pg_view.models.displayers import OUTPUT_METHOD
from pg_view.outputs import CommonOutput, CursesOutput
from pg_view.parsers import ProcWorker
from pg_view.helpers import process_groups, read_configuration, validate_autodetected_conn_param
from pg_view.exceptions import InvalidConnectionParamError, NotConnectedError, NoPidConnectionError, \
DuplicatedConnectionError
from pg_view.validators import get_valid_output_methods, output_method_is_valid

try:
import psycopg2
Expand Down Expand Up @@ -227,8 +223,8 @@ def main():
try:
cluster = db_client.establish_user_defined_connection(instance, clusters)
except (NotConnectedError, NoPidConnectionError):
pg_view.models.collector_base.logger.error(
'failed to acquire details about the database cluster {0}, the server will be skipped'.format(instance))
msg = 'failed to acquire details about the database cluster {0}, the server will be skipped'
pg_view.models.collector_base.logger.error(msg.format(instance))
except DuplicatedConnectionError:
pass
else:
Expand Down Expand Up @@ -288,7 +284,7 @@ def main():

# initialize the disks stat collector process and create an exchange queue
q = JoinableQueue(1)
work_directories = [cluster['wd'] for cluster in clusters if 'wd' in cluster]
work_directories = [cl['wd'] for cl in clusters if 'wd' in cl]

collector = DetachedDiskStatCollector(q, work_directories)
collector.start()
Expand Down
25 changes: 14 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
import os
import glob
import inspect
import os
import sys

import setuptools
from setuptools.command.test import test as TestCommand
from setuptools import setup
from setuptools.command.test import test as TestCommand

__location__ = os.path.join(os.getcwd(), os.path.dirname(inspect.getfile(inspect.currentframe())))


def read_module(path):
data = {}
with open(path, 'r') as fd:
exec(fd.read(), data)
exec (fd.read(), data)
return data


meta = read_module('pg_view/outputs.py')
NAME = 'pg-view'
MAIN_MODULE = 'pg_view'
Expand Down Expand Up @@ -50,9 +51,12 @@ def read_module(path):


class PyTest(TestCommand):

user_options = [('cov=', None, 'Run coverage'), ('cov-xml=', None, 'Generate junit xml report'), ('cov-html=',
None, 'Generate junit html report'), ('junitxml=', None, 'Generate xml of test results')]
user_options = [
('cov=', None, 'Run coverage'),
('cov-xml=', None, 'Generate junit xml report'),
('cov-html=', None, 'Generate junit html report'),
('junitxml=', None, 'Generate xml of test results')
]

def initialize_options(self):
TestCommand.initialize_options(self)
Expand Down Expand Up @@ -100,7 +104,6 @@ def setup_package():
install_reqs = get_install_requirements('requirements.txt')

command_options = {'test': {'cov': ('setup.py', MAIN_MODULE), 'cov_xml': ('setup.py', True)}}

setup(
name=NAME,
version=VERSION,
Expand All @@ -113,12 +116,12 @@ def setup_package():
long_description=read('README.rst'),
classifiers=CLASSIFIERS,
test_suite='tests',
py_modules=['pg_view/view'],
py_modules=[os.path.splitext(i)[0] for i in glob.glob(os.path.join(MAIN_MODULE, "*.py"))],
packages=setuptools.find_packages(exclude=['tests']),
install_requires=install_reqs,
setup_requires=['flake8'],
cmdclass=cmdclass,
tests_require=['pytest-cov', 'pytest', 'mock'],
tests_require=['pytest-cov', 'pytest', 'mock', 'freezegun'],
command_options=command_options,
entry_points={'console_scripts': CONSOLE_SCRIPTS},
)
Expand Down

0 comments on commit 4e0e35d

Please sign in to comment.