Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2019-12-28 13:35:18 +0100
committerArthur de Jong <arthur@arthurdejong.org>2019-12-30 21:50:35 +0100
commitdc6b2ff25ec3064afc6256d45a6255a1e62154d5 (patch)
treecc5432068f46447337a642a948e760c5b14fb082
parentee95a12a7783c1c57be9392f121e8db13a153746 (diff)
Add flake8 tests
-rw-r--r--munin.py18
-rw-r--r--setup.cfg10
-rw-r--r--tox.ini21
-rw-r--r--web.py10
4 files changed, 46 insertions, 13 deletions
diff --git a/munin.py b/munin.py
index a784228..6ad125c 100644
--- a/munin.py
+++ b/munin.py
@@ -1,6 +1,6 @@
# Python module to get data from Munin data files
-# Copyright (C) 2018 Arthur de Jong
+# Copyright (C) 2018-2019 Arthur de Jong
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
@@ -81,13 +81,13 @@ def get_info():
if key not in ('graph_data_size', 'update_rate'):
fields[field][key] = value
# clean up field information
- for field, field_info in fields.items():
+ for _field, field_info in fields.items():
# remove graph=no from negative fields
negative = field_info.get('negative')
if negative:
fields[negative].pop('graph', None)
# remove graph = no and replace by removing draw
- if field_info.pop('graph', '').lower() in ('false', 'no' ,'0'):
+ if field_info.pop('graph', '').lower() in ('false', 'no', '0'):
field_info.pop('draw', None)
else:
field_info.setdefault('draw', 'LINE')
@@ -142,13 +142,13 @@ def get_raw_values(group, host, graph, start, end, resolution=300, minmax=True):
for f in _get_rrd_files(group, host, graph):
field = '-'.join(f.split('-')[2:-1])
filename = os.path.join(group, f)
- for time, value in _fetch_rrd(filename, start, end, resolution, 'AVERAGE'):
- data[time][field] = value
+ for time_, value in _fetch_rrd(filename, start, end, resolution, 'AVERAGE'):
+ data[time_][field] = value
if minmax:
- for time, value in _fetch_rrd(filename, start, end, resolution, 'MIN'):
- data[time][field + '.min'] = value
- for time, value in _fetch_rrd(filename, start, end, resolution, 'MAX'):
- data[time][field + '.max'] = value
+ for time_, value in _fetch_rrd(filename, start, end, resolution, 'MIN'):
+ data[time_][field + '.min'] = value
+ for time_, value in _fetch_rrd(filename, start, end, resolution, 'MAX'):
+ data[time_][field + '.max'] = value
return [dict(time=k, **v) for k, v in sorted(data.items())]
diff --git a/setup.cfg b/setup.cfg
index 6a1d706..869dc81 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -32,3 +32,13 @@ group=root
[bdist_wheel]
universal=1
+
+[flake8]
+ignore =
+ D100,D103 # no extensive docstrings yet
+ P103 # no exrernal dependencies
+max-line-length = 120
+
+[isort]
+lines_after_imports = 2
+multi_line_output = 4
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..d6b214b
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,21 @@
+[tox]
+envlist = flake8
+
+[testenv:flake8]
+skip_install = true
+deps = flake8
+ flake8-author
+ flake8-blind-except
+ flake8-bugbear
+ flake8-class-newline
+ flake8-commas
+ flake8-deprecated
+ flake8-docstrings
+ flake8-exact-pin
+ flake8-isort
+ flake8-print
+ flake8-quotes
+ flake8-tidy-imports
+ flake8-tuple
+ pep8-naming
+commands = flake8 .
diff --git a/web.py b/web.py
index f5cf8b3..39547dc 100644
--- a/web.py
+++ b/web.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2018 Arthur de Jong
+# Copyright (C) 2018-2019 Arthur de Jong
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
@@ -19,13 +19,13 @@
# DEALINGS IN THE SOFTWARE.
import cgi
-import datetime
import json
import os
import sys
import time
-from munin import *
+from munin import get_info, get_resolutions, get_values
+
sys.stdout = sys.stderr
@@ -38,9 +38,11 @@ def static_serve(environ, start_response):
content_type = 'text/javascript'
elif path.endswith('.css'):
content_type = 'text/css'
+ csp = "default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; " + \
+ "script-src 'self' 'unsafe-eval'; frame-ancestors 'none'"
start_response('200 OK', [
('Content-Type', content_type),
- ('Content-Security-Policy', "default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-eval'; frame-ancestors 'none'")])
+ ('Content-Security-Policy', csp)])
return [open(os.path.join('static', path), 'rb').read()]