Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2019-12-29 17:15:14 +0100
committerArthur de Jong <arthur@arthurdejong.org>2019-12-30 22:25:58 +0100
commit504e69fac97fc8ed228ec215911f97f3ce46e1af (patch)
tree3fdd97a8256d60911be4b709f381737336bc97ce
parentca1972c3274738c65818882b43d48c7957bada0f (diff)
Move Python code to muninplot package
This allows more easy installation into a virtualenv.
-rw-r--r--README2
-rw-r--r--muninplot/__main__.py35
-rw-r--r--muninplot/data.py (renamed from munin.py)2
-rw-r--r--muninplot/wsgi.py (renamed from web.py)19
-rw-r--r--setup.cfg2
-rw-r--r--tox.ini2
6 files changed, 44 insertions, 18 deletions
diff --git a/README b/README
index 71e5be5..0a907d6 100644
--- a/README
+++ b/README
@@ -19,7 +19,7 @@ Basic configuration snippet for deploying the munin-plot under Apache with
mod_wsgi:
WSGIDaemonProcess munin-plot threads=5 maximum-requests=100 display-name=%{GROUP} home=/PATH/TO/munin-plot
- AliasMatch ^/munin-plot/(graphs.*|data.*)$ /PATH/TO/munin-plot/web.py/$1
+ AliasMatch ^/munin-plot/(graphs.*|data.*)$ /PATH/TO/munin-plot/muninplot/wsgi.py/$1
Alias /munin-plot /PATH/TO/munin-plot/static
<Directory /PATH/TO/munin-plot>
<Files web.py>
diff --git a/muninplot/__main__.py b/muninplot/__main__.py
new file mode 100644
index 0000000..03f4a82
--- /dev/null
+++ b/muninplot/__main__.py
@@ -0,0 +1,35 @@
+# 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"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+# DEALINGS IN THE SOFTWARE.
+
+import sys
+from wsgiref.simple_server import make_server
+
+from muninplot.wsgi import application
+
+
+def devserver():
+
+ sys.stdout = sys.stderr
+ srv = make_server('0.0.0.0', 8080, application)
+ srv.serve_forever()
+
+
+if __name__ == '__main__':
+ devserver()
diff --git a/munin.py b/muninplot/data.py
index 6ad125c..a420836 100644
--- a/munin.py
+++ b/muninplot/data.py
@@ -1,5 +1,3 @@
-# Python module to get data from Munin data files
-
# Copyright (C) 2018-2019 Arthur de Jong
#
# Permission is hereby granted, free of charge, to any person obtaining a
diff --git a/web.py b/muninplot/wsgi.py
index 39547dc..606f4a0 100644
--- a/web.py
+++ b/muninplot/wsgi.py
@@ -21,23 +21,22 @@
import cgi
import json
import os
-import sys
import time
-from munin import get_info, get_resolutions, get_values
-
-
-sys.stdout = sys.stderr
+from muninplot.data import get_info, get_resolutions, get_values
def static_serve(environ, start_response):
path = environ.get('PATH_INFO', '').lstrip('/') or 'index.html'
path = os.path.normpath(os.sep + path).lstrip(os.sep)
- content_type = 'text/html'
- if path.endswith('.js'):
+ if path.endswith('.html'):
+ content_type = 'text/html'
+ elif path.endswith('.js'):
content_type = 'text/javascript'
elif path.endswith('.css'):
content_type = 'text/css'
+ else:
+ content_type = 'application/octet-stream'
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', [
@@ -119,9 +118,3 @@ def application(environ, start_response):
return get_data(environ, start_response)
else:
return static_serve(environ, start_response)
-
-
-if __name__ == '__main__':
- from wsgiref.simple_server import make_server
- srv = make_server('0.0.0.0', 8080, application)
- srv.serve_forever()
diff --git a/setup.cfg b/setup.cfg
index 869dc81..764ef81 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -24,7 +24,7 @@ classifiers =
[options]
include_package_data = true
-packages = find:
+packages = find:muninplot
[sdist]
owner=root
diff --git a/tox.ini b/tox.ini
index 42c0d53..1efa7f9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -18,7 +18,7 @@ deps = flake8
flake8-tidy-imports
flake8-tuple
pep8-naming
-commands = flake8 .
+commands = flake8 muninplot setup.py
[testenv:eslint]
skip_install = true