pylint fixes.

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

@ -98,4 +98,9 @@ clean:
test: test:
@echo "\nTESTS\n"
cd test && python ./test.py 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 # Kill the daemon and wait until the process is gone
os.kill(pid, signal.SIGTERM) os.kill(pid, signal.SIGTERM)
for timeout in range(25): # 5 seconds for _ in range(25): # 5 seconds
time.sleep(0.2) time.sleep(0.2)
if not self._pid_running(pid): if not self._pid_running(pid):
break break
@ -138,8 +138,8 @@ class Daemon: # pragma: no cover
return pid return pid
def _cleanup(self, signal=None, frame=None): def _cleanup(self, sig=None):
self.log.info("Received signal {0}".format(signal)) self.log.info("Received signal {0}".format(sig))
if os.path.exists(self.pid_file): if os.path.exists(self.pid_file):
os.unlink(self.pid_file) os.unlink(self.pid_file)
self.shutdown_cb() self.shutdown_cb()

@ -36,7 +36,7 @@ class FormConfig:
for form_def in self.forms: for form_def in self.forms:
if form_def.name == form_name: if form_def.name == form_name:
return form_def 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): def get_visible_forms(self, username=None):

@ -88,54 +88,54 @@ class FormDefinition:
def validate_integer(self, field_def, form_values): def validate_integer(self, field_def, form_values):
value = form_values[field_def['name']] value = form_values[field_def['name']]
max = field_def.get('max', None) _max = field_def.get('max', None)
min = field_def.get('min', None) _min = field_def.get('min', None)
try: try:
value = int(value) value = int(value)
except ValueError: except ValueError:
raise ValidationError("Must be an integer number") raise ValidationError("Must be an integer number")
if min is not None and value < int(min): if _min is not None and value < int(_min):
raise ValidationError("Minimum value is {0}".format(min)) raise ValidationError("Minimum value is {0}".format(_min))
if max is not None and value > int(max): if _max is not None and value > int(_max):
raise ValidationError("Maximum value is {0}".format(max)) raise ValidationError("Maximum value is {0}".format(_max))
return int(value) return int(value)
def validate_float(self, field_def, form_values): def validate_float(self, field_def, form_values):
value = form_values[field_def['name']] value = form_values[field_def['name']]
max = field_def.get('max', None) _max = field_def.get('max', None)
min = field_def.get('min', None) _min = field_def.get('min', None)
try: try:
value = float(value) value = float(value)
except ValueError: except ValueError:
raise ValidationError("Must be an real (float) number") raise ValidationError("Must be an real (float) number")
if min is not None and value < float(min): if _min is not None and value < float(_min):
raise ValidationError("Minimum value is {0}".format(min)) raise ValidationError("Minimum value is {0}".format(_min))
if max is not None and value > float(max): if _max is not None and value > float(_max):
raise ValidationError("Maximum value is {0}".format(max)) raise ValidationError("Maximum value is {0}".format(_max))
return float(value) return float(value)
def validate_date(self, field_def, form_values): def validate_date(self, field_def, form_values):
value = form_values[field_def['name']] value = form_values[field_def['name']]
max = field_def.get('max', None) _max = field_def.get('max', None)
min = field_def.get('min', None) _min = field_def.get('min', None)
try: try:
value = datetime.datetime.strptime(value, '%Y-%m-%d').date() value = datetime.datetime.strptime(value, '%Y-%m-%d').date()
except ValueError: except ValueError:
raise ValidationError("Invalid date, must be in form YYYY-MM-DD") raise ValidationError("Invalid date, must be in form YYYY-MM-DD")
if min is not None: if _min is not None:
if value < datetime.datetime.strptime(min, '%Y-%m-%d').date(): if value < datetime.datetime.strptime(_min, '%Y-%m-%d').date():
raise ValidationError("Minimum value is {0}".format(min)) raise ValidationError("Minimum value is {0}".format(_min))
if max is not None: if _max is not None:
if value > datetime.datetime.strptime(max, '%Y-%m-%d').date(): if value > datetime.datetime.strptime(_max, '%Y-%m-%d').date():
raise ValidationError("Maximum value is {0}".format(max)) raise ValidationError("Maximum value is {0}".format(_max))
return value return value

@ -55,9 +55,12 @@ class ScriptForm:
self.config_file = config_file self.config_file = config_file
self.cache = cache self.cache = cache
self.log = logging.getLogger('SCRIPTFORM') 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.websrv = None
self.running = False 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): def get_form_config(self):
""" """
@ -65,7 +68,7 @@ class ScriptForm:
instance. If it has already been read, a cached version is returned. instance. If it has already been read, a cached version is returned.
""" """
# Cache # 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 return self.form_config_singleton
config = json.load(file(self.config_file, 'r')) config = json.load(file(self.config_file, 'r'))

@ -149,7 +149,7 @@ class WebAppHandler(BaseHTTPRequestHandler):
def log_message(self, format, *args): def log_message(self, format, *args):
"""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"""
self.scriptform.log.info("{} {}".format(self.address_string(), format%args)) self.scriptform.log.info("{} {}".format(self.address_string(), args))
def do_GET(self): def do_GET(self):
self._call(*self._parse(self.path)) self._call(*self._parse(self.path))
@ -189,9 +189,9 @@ class WebAppHandler(BaseHTTPRequestHandler):
callable(getattr(self, method_name)): callable(getattr(self, method_name)):
method_cb = getattr(self, method_name) method_cb = getattr(self, method_name)
elif path == '' and hasattr(self, 'index'): elif path == '' and hasattr(self, 'index'):
method_cb = self.index method_cb = getattr(self, 'index')
elif hasattr(self, 'default'): elif hasattr(self, 'default'):
method_cb = self.default method_cb = getattr(self, 'default')
else: else:
self.send_error(404, "Not found") self.send_error(404, "Not found")
return return

Loading…
Cancel
Save