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 () {
# 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

@ -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.
"""

@ -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):

@ -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)

@ -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

@ -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.
"""

Loading…
Cancel
Save