diff options
author | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-06-15 12:25:36 +0100 |
---|---|---|
committer | Sam Thursfield <sam.thursfield@codethink.co.uk> | 2015-06-15 12:25:36 +0100 |
commit | 8281f92eb9557d7bafa047409ed66b85fadbee31 (patch) | |
tree | badb52100269379df8dbb2d441202c6d323937f4 | |
parent | 2a41a85dbc8f53235f965ed467a825d1ed8b1d74 (diff) | |
download | morph-cache-server-8281f92eb9557d7bafa047409ed66b85fadbee31.tar.gz |
Add basics of a web frontend
Also, update for Bottle 0.13dev (was using 0.11, the only change is
order of parameters passed to app.mount().
-rwxr-xr-x | morph-cache-server | 11 | ||||
-rw-r--r-- | morphcacheserver/frontend.py | 63 | ||||
-rw-r--r-- | morphcacheserver/templates/base.tpl | 11 | ||||
-rw-r--r-- | morphcacheserver/templates/index.tpl | 11 |
4 files changed, 93 insertions, 3 deletions
diff --git a/morph-cache-server b/morph-cache-server index 32c57a5..4cbc20d 100755 --- a/morph-cache-server +++ b/morph-cache-server @@ -15,7 +15,7 @@ # with this program. If not, see <http://www.gnu.org/licenses/>. -from bottle import Bottle, request, response, run, static_file +from bottle import Bottle, request, response, run, static_file, template import cliapp from flup.server.fcgi import WSGIServer @@ -28,6 +28,7 @@ import os import urllib import urllib2 +import morphcacheserver.frontend from morphcacheserver.artifact_database import ArtifactDatabase from morphcacheserver.repocache import RepoCache @@ -402,6 +403,8 @@ class MorphCacheServer(cliapp.Application): '''Return info on all known builds.''' return {'builds': db.view_artifact_statistics()} + # This may not be the right name for this method, as its name is + # 'builds' but it takes the cache name of an artifact, not a build. @app.get('/builds/<cache_name>') def get_builds_for_artifact(cache_name): '''Return info on builds of a given artifact.''' @@ -424,10 +427,12 @@ class MorphCacheServer(cliapp.Application): api_1_0 = self.api_1_0(repo_cache, db) api_2_0 = self.api_2_0(db) + web_frontend = morphcacheserver.frontend.web_frontend(db) root = Bottle() - root.mount(api_1_0, '/1.0') - root.mount(api_2_0, '/2.0') + root.merge(web_frontend) + root.mount('/1.0', api_1_0) + root.mount('/2.0', api_2_0) if self.settings['fcgi-server']: WSGIServer(root).run() diff --git a/morphcacheserver/frontend.py b/morphcacheserver/frontend.py new file mode 100644 index 0000000..03d037b --- /dev/null +++ b/morphcacheserver/frontend.py @@ -0,0 +1,63 @@ +# Copyright (C) 2015 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program. If not, see <http://www.gnu.org/licenses/>. + + +from bottle import Bottle, template + + +def make_table(data, headings): + '''Render 'data' as a HTML table.''' + + table_template = """ + <table border="1"> + <tr> + %for header in headings: + <td>{{header}}</td> + %end + </tr> + %for row in rows: + <tr> + %for header in headings: + <td>{{row[header]}}</td> + %end + </tr> + %end + </table> + """ + return template(table_template, headings=headings, rows=data) + + +def web_frontend(db): + '''Some pretty stuff for users to interact with.''' + app = Bottle() + + @app.get('/artifacts') + def artifacts(): + '''View artifacts in the cache.''' + + content = '<p>Artifacts:</p>' + + artifacts = db.view_artifact_statistics() + content += make_table( + artifacts, ['cache_name', 'n_different_builds', 'n_builds']) + + return template('morphcacheserver/templates/base', base=content) + + @app.get('/') + def frontpage(): + '''A nice frontpage.''' + + return template('morphcacheserver/templates/index') + + return app diff --git a/morphcacheserver/templates/base.tpl b/morphcacheserver/templates/base.tpl new file mode 100644 index 0000000..79e97fe --- /dev/null +++ b/morphcacheserver/templates/base.tpl @@ -0,0 +1,11 @@ +<html> + +<head> + <title>Baserock Cache Server</title> +</head> + +<body> + {{!base}} +</body> + +</html> diff --git a/morphcacheserver/templates/index.tpl b/morphcacheserver/templates/index.tpl new file mode 100644 index 0000000..fac7790 --- /dev/null +++ b/morphcacheserver/templates/index.tpl @@ -0,0 +1,11 @@ +% rebase('morphcacheserver/templates/base.tpl') + +<p> +This is a Baserock cache server. +</p> +<p> +This web frontend is a total work in progress, don't expect too much from it. +</p> +<p> +Maybe you are interested in the <a href="/artifacts">list of artifacts</a>. +</p> |