pylint fixes.

pull/7/head
Ferry Boender 9 years ago
parent a106e9c364
commit 394022e2d3
  1. 5
      Makefile
  2. 6
      src/daemon.py
  3. 4
      src/formconfig.py
  4. 46
      src/formdefinition.py
  5. 7
      src/scriptform.py
  6. 6
      src/webapp.py

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

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

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

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

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

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

Loading…
Cancel
Save