diff --git a/Makefile b/Makefile index 194dcab..10a2fdc 100644 --- a/Makefile +++ b/Makefile @@ -98,4 +98,9 @@ clean: test: + @echo "\nTESTS\n" cd test && python ./test.py + @echo "\nFLAKE8\n" + cd src && flake8 *.py | grep -v "line too long" || true + @echo "\nPYLINT\n" + cd src && pylint -dC -dR -rno *.py || true diff --git a/src/daemon.py b/src/daemon.py index aea9c0c..4e92ff8 100644 --- a/src/daemon.py +++ b/src/daemon.py @@ -53,7 +53,7 @@ class Daemon: # pragma: no cover # Kill the daemon and wait until the process is gone os.kill(pid, signal.SIGTERM) - for timeout in range(25): # 5 seconds + for _ in range(25): # 5 seconds time.sleep(0.2) if not self._pid_running(pid): break @@ -138,8 +138,8 @@ class Daemon: # pragma: no cover return pid - def _cleanup(self, signal=None, frame=None): - self.log.info("Received signal {0}".format(signal)) + def _cleanup(self, sig=None): + self.log.info("Received signal {0}".format(sig)) if os.path.exists(self.pid_file): os.unlink(self.pid_file) self.shutdown_cb() diff --git a/src/formconfig.py b/src/formconfig.py index b0a7e5e..331c84c 100644 --- a/src/formconfig.py +++ b/src/formconfig.py @@ -36,8 +36,8 @@ class FormConfig: for form_def in self.forms: if form_def.name == form_name: return form_def - else: - raise ValueError("No such form: {0}".format(form_name)) + + raise ValueError("No such form: {0}".format(form_name)) def get_visible_forms(self, username=None): """ diff --git a/src/formdefinition.py b/src/formdefinition.py index 49ecff2..61b63ff 100644 --- a/src/formdefinition.py +++ b/src/formdefinition.py @@ -88,54 +88,54 @@ class FormDefinition: def validate_integer(self, field_def, form_values): value = form_values[field_def['name']] - max = field_def.get('max', None) - min = field_def.get('min', None) + _max = field_def.get('max', None) + _min = field_def.get('min', None) try: value = int(value) except ValueError: raise ValidationError("Must be an integer number") - if min is not None and value < int(min): - raise ValidationError("Minimum value is {0}".format(min)) - if max is not None and value > int(max): - raise ValidationError("Maximum value is {0}".format(max)) + if _min is not None and value < int(_min): + raise ValidationError("Minimum value is {0}".format(_min)) + if _max is not None and value > int(_max): + raise ValidationError("Maximum value is {0}".format(_max)) return int(value) def validate_float(self, field_def, form_values): value = form_values[field_def['name']] - max = field_def.get('max', None) - min = field_def.get('min', None) + _max = field_def.get('max', None) + _min = field_def.get('min', None) try: value = float(value) except ValueError: raise ValidationError("Must be an real (float) number") - if min is not None and value < float(min): - raise ValidationError("Minimum value is {0}".format(min)) - if max is not None and value > float(max): - raise ValidationError("Maximum value is {0}".format(max)) + if _min is not None and value < float(_min): + raise ValidationError("Minimum value is {0}".format(_min)) + if _max is not None and value > float(_max): + raise ValidationError("Maximum value is {0}".format(_max)) return float(value) def validate_date(self, field_def, form_values): value = form_values[field_def['name']] - max = field_def.get('max', None) - min = field_def.get('min', None) + _max = field_def.get('max', None) + _min = field_def.get('min', None) try: value = datetime.datetime.strptime(value, '%Y-%m-%d').date() except ValueError: raise ValidationError("Invalid date, must be in form YYYY-MM-DD") - if min is not None: - if value < datetime.datetime.strptime(min, '%Y-%m-%d').date(): - raise ValidationError("Minimum value is {0}".format(min)) - if max is not None: - if value > datetime.datetime.strptime(max, '%Y-%m-%d').date(): - raise ValidationError("Maximum value is {0}".format(max)) + if _min is not None: + if value < datetime.datetime.strptime(_min, '%Y-%m-%d').date(): + raise ValidationError("Minimum value is {0}".format(_min)) + if _max is not None: + if value > datetime.datetime.strptime(_max, '%Y-%m-%d').date(): + raise ValidationError("Maximum value is {0}".format(_max)) return value @@ -166,10 +166,10 @@ class FormDefinition: maxlen = field_def.get('maxlen', None) if minlen is not None and len(value) < int(minlen): - raise ValidationError("minimum length is {0}".format(minlen)) + raise ValidationError("minimum length is {0}".format(minlen)) if maxlen is not None and len(value) > int(maxlen): - raise ValidationError("maximum length is {0}".format(maxlen)) + raise ValidationError("maximum length is {0}".format(maxlen)) return value @@ -178,7 +178,7 @@ class FormDefinition: minlen = field_def.get('minlen', None) if minlen is not None and len(value) < int(minlen): - raise ValidationError("minimum length is {0}".format(minlen)) + raise ValidationError("minimum length is {0}".format(minlen)) return value diff --git a/src/scriptform.py b/src/scriptform.py index ab63b7e..b0a8096 100755 --- a/src/scriptform.py +++ b/src/scriptform.py @@ -55,9 +55,12 @@ class ScriptForm: self.config_file = config_file self.cache = cache self.log = logging.getLogger('SCRIPTFORM') - self.get_form_config() # Init form config so it can raise errors about problems. + self.form_config_singleton = None self.websrv = None self.running = False + self.httpd = None + + self.get_form_config() # Init form config so it can raise errors about problems. def get_form_config(self): """ @@ -65,7 +68,7 @@ class ScriptForm: instance. If it has already been read, a cached version is returned. """ # Cache - if self.cache and hasattr(self, 'form_config_singleton'): + if self.cache and self.form_config_singleton is not None: return self.form_config_singleton config = json.load(file(self.config_file, 'r')) diff --git a/src/webapp.py b/src/webapp.py index a90e421..1e6f661 100644 --- a/src/webapp.py +++ b/src/webapp.py @@ -149,7 +149,7 @@ class WebAppHandler(BaseHTTPRequestHandler): def log_message(self, format, *args): """Overrides BaseHTTPRequestHandler which logs to the console. We log to our log file instead""" - self.scriptform.log.info("{} {}".format(self.address_string(), format%args)) + self.scriptform.log.info("{} {}".format(self.address_string(), args)) def do_GET(self): self._call(*self._parse(self.path)) @@ -189,9 +189,9 @@ class WebAppHandler(BaseHTTPRequestHandler): callable(getattr(self, method_name)): method_cb = getattr(self, method_name) elif path == '' and hasattr(self, 'index'): - method_cb = self.index + method_cb = getattr(self, 'index') elif hasattr(self, 'default'): - method_cb = self.default + method_cb = getattr(self, 'default') else: self.send_error(404, "Not found") return