Code quality and linting fixes

pull/7/head
Ferry Boender 5 years ago
parent 95c1499060
commit b1ca65087c
  1. 9
      build.sla
  2. 2
      src/daemon.py
  3. 2
      src/formdefinition.py
  4. 4
      src/formrender.py
  5. 7
      src/scriptform.py
  6. 9
      src/webserver.py

@ -11,9 +11,16 @@ PROG="scriptform"
test () { test () {
# Run tests # Run tests
ROOTDIR="$(pwd)" ROOTDIR="$(pwd)"
# Unit / integration tests
cd test && python ./test.py cd test && python ./test.py
# Code quality linting (flake8)
cd $ROOTDIR 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 $ROOTDIR
cd src && pylint --reports=n -dR -d star-args -d no-member *.py || true cd src && pylint --reports=n -dR -d star-args -d no-member *.py || true
cd $ROOTDIR cd $ROOTDIR

@ -161,7 +161,7 @@ class Daemon(object): # pragma: no cover
return pid return pid
def _cleanup(self, sig=None, frame=None): def _cleanup(self, sig=None):
""" """
Remove pid files and call registered shutodnw callbacks. Remove pid files and call registered shutodnw callbacks.
""" """

@ -100,7 +100,7 @@ class FormDefinition(object):
field_def = self.get_field_def(field_name) field_def = self.get_field_def(field_name)
field_type = field_def['type'] 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) return validate_cb(field_def, form_values)
def validate_string(self, field_def, form_values): def validate_string(self, field_def, form_values):

@ -101,8 +101,8 @@ class FormRender(object):
""" """
params = self.cast_params(kwargs) params = self.cast_params(kwargs)
method_name = 'r_field_{0}'.format(field_type) method_name = 'r_field_{0}'.format(field_type)
method = getattr(self, method_name, None) method = getattr(self, method_name)
field = method(**params) field = method(**params) # pylint: disable=not-callable
if 'required' in kwargs and kwargs['required'] is True: if 'required' in kwargs and kwargs['required'] is True:
return HTML_REQUIRED.format(field) return HTML_REQUIRED.format(field)

@ -6,9 +6,6 @@ Main ScriptForm program
""" """
import sys import sys
if hasattr(sys, 'dont_write_bytecode'):
sys.dont_write_bytecode = True
import optparse import optparse
import os import os
import json import json
@ -17,6 +14,10 @@ import thread
import hashlib import hashlib
import socket import socket
if hasattr(sys, 'dont_write_bytecode'):
sys.dont_write_bytecode = True
# pylint: disable=wrong-import-position
from daemon import Daemon from daemon import Daemon
from formdefinition import FormDefinition from formdefinition import FormDefinition
from formconfig import FormConfig from formconfig import FormConfig

@ -4,7 +4,6 @@ Basic web server / framework.
from SocketServer import ThreadingMixIn from SocketServer import ThreadingMixIn
import BaseHTTPServer import BaseHTTPServer
from BaseHTTPServer import BaseHTTPRequestHandler
import urlparse import urlparse
import cgi import cgi
@ -30,25 +29,25 @@ class ThreadedHTTPServer(ThreadingMixIn, BaseHTTPServer.HTTPServer):
pass pass
class RequestHandler(BaseHTTPRequestHandler): class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
""" """
Basic web server request handler. Handles GET and POST requests. You should Basic web server request handler. Handles GET and POST requests. You should
inherit from this class and implement h_ methods for handling requests. inherit from this class and implement h_ methods for handling requests.
If no path is set, it dispatches to the 'index' or 'default' method. 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 """Overrides BaseHTTPRequestHandler which logs to the console. We log
to our log file instead""" to our log file instead"""
fmt = "{0} {1}" fmt = "{0} {1}"
self.scriptform.log.info(fmt.format(self.address_string(), args)) 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. Handle a GET request.
""" """
self._call(*self._parse(self.path.lstrip('/'))) self._call(*self._parse(self.path.lstrip('/')))
def do_POST(self): def do_POST(self): # pylint: disable=invalid-name
""" """
Handle a POST request. Handle a POST request.
""" """

Loading…
Cancel
Save