From b1ca65087cc3173d1eae31696292f33f55dc12ac Mon Sep 17 00:00:00 2001 From: Ferry Boender Date: Mon, 22 Jul 2019 10:26:24 +0200 Subject: [PATCH] Code quality and linting fixes --- build.sla | 9 ++++++++- src/daemon.py | 2 +- src/formdefinition.py | 2 +- src/formrender.py | 4 ++-- src/scriptform.py | 7 ++++--- src/webserver.py | 9 ++++----- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/build.sla b/build.sla index c6189cc..8d7fedb 100644 --- a/build.sla +++ b/build.sla @@ -11,9 +11,16 @@ PROG="scriptform" test () { # Run tests ROOTDIR="$(pwd)" + + # Unit / integration tests cd test && python ./test.py + + # Code quality linting (flake8) cd $ROOTDIR - cd src && flake8 *.py || true + # E402 == module level import not at top of file + #cd src && flake8 --extend-ignore=E402 *.py || true + + # Code quality linting (pylint) cd $ROOTDIR cd src && pylint --reports=n -dR -d star-args -d no-member *.py || true cd $ROOTDIR diff --git a/src/daemon.py b/src/daemon.py index 7668fee..e2264e6 100644 --- a/src/daemon.py +++ b/src/daemon.py @@ -161,7 +161,7 @@ class Daemon(object): # pragma: no cover return pid - def _cleanup(self, sig=None, frame=None): + def _cleanup(self, sig=None): """ Remove pid files and call registered shutodnw callbacks. """ diff --git a/src/formdefinition.py b/src/formdefinition.py index 4c1cf65..5e7e0d8 100644 --- a/src/formdefinition.py +++ b/src/formdefinition.py @@ -100,7 +100,7 @@ class FormDefinition(object): field_def = self.get_field_def(field_name) field_type = field_def['type'] - validate_cb = getattr(self, 'validate_{0}'.format(field_type), None) + validate_cb = getattr(self, 'validate_{0}'.format(field_type)) return validate_cb(field_def, form_values) def validate_string(self, field_def, form_values): diff --git a/src/formrender.py b/src/formrender.py index 911e282..817a060 100644 --- a/src/formrender.py +++ b/src/formrender.py @@ -101,8 +101,8 @@ class FormRender(object): """ params = self.cast_params(kwargs) method_name = 'r_field_{0}'.format(field_type) - method = getattr(self, method_name, None) - field = method(**params) + method = getattr(self, method_name) + field = method(**params) # pylint: disable=not-callable if 'required' in kwargs and kwargs['required'] is True: return HTML_REQUIRED.format(field) diff --git a/src/scriptform.py b/src/scriptform.py index d353148..5d997bb 100755 --- a/src/scriptform.py +++ b/src/scriptform.py @@ -6,9 +6,6 @@ Main ScriptForm program """ import sys -if hasattr(sys, 'dont_write_bytecode'): - sys.dont_write_bytecode = True - import optparse import os import json @@ -17,6 +14,10 @@ import thread import hashlib import socket +if hasattr(sys, 'dont_write_bytecode'): + sys.dont_write_bytecode = True + +# pylint: disable=wrong-import-position from daemon import Daemon from formdefinition import FormDefinition from formconfig import FormConfig diff --git a/src/webserver.py b/src/webserver.py index 276754a..7880b3b 100644 --- a/src/webserver.py +++ b/src/webserver.py @@ -4,7 +4,6 @@ Basic web server / framework. from SocketServer import ThreadingMixIn import BaseHTTPServer -from BaseHTTPServer import BaseHTTPRequestHandler import urlparse import cgi @@ -30,25 +29,25 @@ class ThreadedHTTPServer(ThreadingMixIn, BaseHTTPServer.HTTPServer): pass -class RequestHandler(BaseHTTPRequestHandler): +class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): """ Basic web server request handler. Handles GET and POST requests. You should inherit from this class and implement h_ methods for handling requests. If no path is set, it dispatches to the 'index' or 'default' method. """ - def log_message(self, fmt, *args): + def log_message(self, fmt, *args): # pylint: disable=arguments-differ """Overrides BaseHTTPRequestHandler which logs to the console. We log to our log file instead""" fmt = "{0} {1}" self.scriptform.log.info(fmt.format(self.address_string(), args)) - def do_GET(self): + def do_GET(self): # pylint: disable=invalid-name """ Handle a GET request. """ self._call(*self._parse(self.path.lstrip('/'))) - def do_POST(self): + def do_POST(self): # pylint: disable=invalid-name """ Handle a POST request. """