From 2dcbe101b49dd942adbc78e61bf8011d3e8e1d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= Date: Wed, 12 Dec 2018 22:53:49 +0000 Subject: Fix most of the pylint output, and hide away some that is not needed. Again, this is not ready for CI yet unfortunately :( --- .pylintrc | 12 +++ glucometerutils/common.py | 9 +- glucometerutils/drivers/accuchek_reports.py | 57 +++++++----- glucometerutils/drivers/fsinsulinx.py | 2 +- glucometerutils/drivers/fslibre.py | 2 +- glucometerutils/drivers/fsoptium.py | 101 +++++++++++---------- glucometerutils/drivers/fsprecisionneo.py | 10 +- glucometerutils/drivers/otultra2.py | 100 ++++++++++---------- glucometerutils/drivers/otverio2015.py | 6 +- glucometerutils/drivers/otverioiq.py | 2 +- glucometerutils/drivers/sdcodefree.py | 21 +++-- glucometerutils/glucometer.py | 57 ++++++------ glucometerutils/support/freestyle.py | 5 +- glucometerutils/support/hiddevice.py | 10 +- glucometerutils/support/lifescan.py | 12 ++- .../support/lifescan_binary_protocol.py | 20 ++-- glucometerutils/support/serial.py | 4 +- 17 files changed, 228 insertions(+), 202 deletions(-) create mode 100644 .pylintrc diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..34485a1 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,12 @@ +[MESSAGE CONTROL] +disable= + duplicate-code, + too-few-public-methods, + too-many-branches, + too-many-locals, + too-many-nested-blocks, + too-many-return-statements, + too-many-statements, + +[BASIC] +good-names = i, j, k, e, _ diff --git a/glucometerutils/common.py b/glucometerutils/common.py index 8ffa724..7d7f0db 100644 --- a/glucometerutils/common.py +++ b/glucometerutils/common.py @@ -6,20 +6,17 @@ __email__ = 'flameeyes@flameeyes.eu' __copyright__ = 'Copyright © 2013, Diego Elio Pettenò' __license__ = 'MIT' -import collections import datetime import enum import textwrap try: from typing import Sequence, Text -except: +except ImportError: pass import attr -from glucometerutils import exceptions - class Unit(enum.Enum): MG_DL = 'mg/dL' MMOL_L = 'mmol/L' @@ -56,8 +53,8 @@ def convert_glucose_unit(value, from_unit, to_unit): if from_unit == Unit.MG_DL: return round(value / 18.0, 2) - else: - return round(value * 18.0, 0) + + return round(value * 18.0, 0) @attr.s class GlucoseReading: diff --git a/glucometerutils/drivers/accuchek_reports.py b/glucometerutils/drivers/accuchek_reports.py index 49c698d..a29f0c6 100644 --- a/glucometerutils/drivers/accuchek_reports.py +++ b/glucometerutils/drivers/accuchek_reports.py @@ -26,8 +26,8 @@ from glucometerutils import common from glucometerutils import exceptions _UNIT_MAP = { - 'mmol/l': common.Unit.MMOL_L, - 'mg/dl': common.Unit.MG_DL, + 'mmol/l': common.Unit.MMOL_L, + 'mg/dl': common.Unit.MG_DL, } _DATE_CSV_KEY = 'Date' @@ -47,17 +47,18 @@ _TIME_FORMAT = '%H:%M' _DATETIME_FORMAT = ' '.join((_DATE_FORMAT, _TIME_FORMAT)) -class Device(object): +class Device: def __init__(self, device): if not device or not os.path.isdir(device): raise exceptions.CommandLineError( - '--device parameter is required, should point to mount path for the ' - 'meter.') + '--device parameter is required, should point to mount path ' + 'for the meter.') - report_files = glob.glob(os.path.join(device, '*', 'Reports', '*.csv')) + reports_path = os.path.join(device, '*', 'Reports', '*.csv') + report_files = glob.glob(reports_path) if not report_files: raise exceptions.ConnectionFailed( - 'No report file found in path "%s".' % reports_path) + 'No report file found in path "%s".' % reports_path) self.report_file = report_files[0] @@ -68,23 +69,28 @@ class Device(object): next(self.report) return csv.DictReader( - self.report, delimiter=';', skipinitialspace=True, quoting=csv.QUOTE_NONE) + self.report, + delimiter=';', + skipinitialspace=True, + quoting=csv.QUOTE_NONE) def connect(self): - self.report = open(self.report_file, 'r', newline='\r\n', encoding='utf-8') + self.report = open( + self.report_file, 'r', newline='\r\n', encoding='utf-8') def disconnect(self): self.report.close() def get_meter_info(self): return common.MeterInfo( - '%s glucometer' % self.get_model(), - serial_number=self.get_serial_number(), - native_unit=self.get_glucose_unit()) + '%s glucometer' % self.get_model(), + serial_number=self.get_serial_number(), + native_unit=self.get_glucose_unit()) def get_model(self): # $device/MODEL/Reports/*.csv - return os.path.basename(os.path.dirname(os.path.dirname(self.report_file))) + return os.path.basename( + os.path.dirname(os.path.dirname(self.report_file))) def get_serial_number(self): self.report.seek(0) @@ -99,23 +105,24 @@ class Device(object): return _UNIT_MAP[record[_UNIT_CSV_KEY]] def get_datetime(self): - raise NotImplemented + raise NotImplementedError def set_datetime(self, date=None): - raise NotImplemented + raise NotImplementedError def zero_log(self): - raise NotImplemented + raise NotImplementedError - def _extract_datetime(self, record): + def _extract_datetime(self, record): # pylint: disable=no-self-use # Date and time are in separate column, but we want to parse them # together. date_and_time = ' '.join((record[_DATE_CSV_KEY], record[_TIME_CSV_KEY])) return datetime.datetime.strptime(date_and_time, _DATETIME_FORMAT) - def _extract_meal(self, record): + def _extract_meal(self, record): # pylint: disable=no-self-use if record[_AFTER_MEAL_CSV_KEY] and record[_BEFORE_MEAL_CSV_KEY]: - raise InvalidResponse('Reading cannot be before and after meal.') + raise exceptions.InvalidResponse( + 'Reading cannot be before and after meal.') elif record[_AFTER_MEAL_CSV_KEY]: return common.Meal.AFTER elif record[_BEFORE_MEAL_CSV_KEY]: @@ -129,9 +136,9 @@ class Device(object): continue yield common.GlucoseReading( - self._extract_datetime(record), - common.convert_glucose_unit( - float(record[_RESULT_CSV_KEY]), - _UNIT_MAP[record[_UNIT_CSV_KEY]], - common.Unit.MG_DL), - meal=self._extract_meal(record)) + self._extract_datetime(record), + common.convert_glucose_unit( + float(record[_RESULT_CSV_KEY]), + _UNIT_MAP[record[_UNIT_CSV_KEY]], + common.Unit.MG_DL), + meal=self._extract_meal(record)) diff --git a/glucometerutils/drivers/fsinsulinx.py b/glucometerutils/drivers/fsinsulinx.py index 15bc131..fbde9ba 100644 --- a/glucometerutils/drivers/fsinsulinx.py +++ b/glucometerutils/drivers/fsinsulinx.py @@ -55,7 +55,7 @@ class Device(freestyle.FreeStyleHidDevice): 'Software version: ' + self._get_version(),), native_unit=self.get_glucose_unit()) - def get_glucose_unit(self): + def get_glucose_unit(self): # pylint: disable=no-self-use """Returns the glucose unit of the device.""" return common.Unit.MG_DL diff --git a/glucometerutils/drivers/fslibre.py b/glucometerutils/drivers/fslibre.py index 6e3988c..5341573 100644 --- a/glucometerutils/drivers/fslibre.py +++ b/glucometerutils/drivers/fslibre.py @@ -205,7 +205,7 @@ class Device(freestyle.FreeStyleHidDevice): """Overridden function as the command is not compatible.""" return self._send_text_command(b'$sn?').rstrip('\r\n') - def get_glucose_unit(self): + def get_glucose_unit(self): # pylint: disable=no-self-use """Returns the glucose unit of the device.""" # TODO(Flameeyes): figure out how to identify the actual unit on the # device. diff --git a/glucometerutils/drivers/fsoptium.py b/glucometerutils/drivers/fsoptium.py index 395494c..618fffa 100644 --- a/glucometerutils/drivers/fsoptium.py +++ b/glucometerutils/drivers/fsoptium.py @@ -29,8 +29,8 @@ from glucometerutils.support import serial _CLOCK_RE = re.compile( - r'^Clock:\t(?P[A-Z][a-z]{2}) (?P[0-9]{2}) (?P[0-9]{4})\t' - r'(?P