Merge lp:~isoschiz/endroid/httpindex into lp:endroid

Proposed by Martin Morrison
Status: Merged
Approved by: Martin Morrison
Approved revision: 117
Merged at revision: 44
Proposed branch: lp:~isoschiz/endroid/httpindex
Merge into: lp:endroid
Diff against target: 125 lines (+39/-6)
2 files modified
debian/endroid.install (+1/-0)
src/endroid/plugins/httpinterface.py (+38/-6)
To merge this branch: bzr merge lp:~isoschiz/endroid/httpindex
Reviewer Review Type Date Requested Status
Martin Morrison Approve
ChrisD Pending
Review via email: mp+180391@code.launchpad.net

This proposal supersedes a proposal from 2013-08-15.

Commit message

Add an HTTP front page with links to any plugins with registered pages.

Description of the change

Add an HTTP front page with links to any plugins with registered pages.

To post a comment you must log in.
Revision history for this message
ChrisD (gingerchris) wrote : Posted in a previous version of this proposal

looks good

review: Approve
Revision history for this message
Martin Morrison (isoschiz) wrote : Posted in a previous version of this proposal

The prerequisite lp:~isoschiz/endroid/globalplugins has not yet been merged into lp:endroid.

Revision history for this message
Martin Morrison (isoschiz) wrote : Posted in a previous version of this proposal

Attempt to merge into lp:endroid failed due to conflicts:

text conflict in src/endroid/plugins/httpinterface.py

Revision history for this message
Martin Morrison (isoschiz) wrote :

Reviewing by proxy following resolution of merge conflicts.

review: Approve
Revision history for this message
Martin Morrison (isoschiz) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/endroid.install'
2--- debian/endroid.install 2013-08-15 13:46:28 +0000
3+++ debian/endroid.install 2013-08-15 18:11:14 +0000
4@@ -8,3 +8,4 @@
5 bin/endroid_tee usr/bin/
6 lib/wokkel-0.7.1-py2.7.egg usr/lib/endroid/dependencies
7 var/endroid.db var/lib/endroid/db
8+doc/EnDroid.png usr/share/endroid/media/
9
10=== added file 'doc/EnDroid.png'
11Binary files doc/EnDroid.png 1970-01-01 00:00:00 +0000 and doc/EnDroid.png 2013-08-15 18:11:14 +0000 differ
12=== modified file 'src/endroid/plugins/httpinterface.py'
13--- src/endroid/plugins/httpinterface.py 2013-08-15 18:01:37 +0000
14+++ src/endroid/plugins/httpinterface.py 2013-08-15 18:11:14 +0000
15@@ -5,14 +5,17 @@
16
17 import collections
18 import re
19+import logging
20
21 from endroid.pluginmanager import Plugin
22 from twisted.internet import reactor
23 from twisted.web.resource import Resource
24 from twisted.web.server import Site
25+from twisted.web.static import File
26
27 DEFAULT_HTTP_PORT = 8880
28 DEFAULT_HTTP_INTERFACE = '127.0.0.1'
29+DEFAULT_MEDIA_DIR = "/usr/share/endroid/media/"
30
31 NOT_FOUND_TEMPLATE = """
32 <html>
33@@ -24,6 +27,18 @@
34 </html>
35 """
36
37+INDEX_TEMPLATE = """
38+<html>
39+ <head><title>EnDroid</title></head>
40+ <body bgcolor="white">
41+ <h1>EnDroid HTTP interface</h1>
42+ <img style='float: right;' src='_media/EnDroid.png'>
43+ <ul>
44+{}
45+ </ul>
46+ </body>
47+</html>"""
48+
49 class HandlerNotFoundError(Exception):
50 pass
51
52@@ -31,12 +46,18 @@
53 """
54 Only registered resource. Route requests to callbacks.
55 """
56- isLeaf = True
57
58 def __init__(self, interface):
59+ Resource.__init__(self)
60 self.interface = interface
61+
62+ def getChild(self, name, request):
63+ if name == "_media":
64+ return self.interface._media
65+ else:
66+ return self
67
68- def render(self, request):
69+ def _render(self, request):
70 try:
71 callback = self.interface.lookup_handler(request.path)
72 except HandlerNotFoundError as e:
73@@ -46,8 +67,8 @@
74
75 return page
76
77- render_GET = render
78- render_POST = render
79+ render_GET = _render
80+ render_POST = _render
81
82
83 class HTTPInterfaceSingleton(object):
84@@ -59,6 +80,11 @@
85 def __init__(self):
86 self.registrations = collections.defaultdict(list)
87
88+ def _index(self, request):
89+ return INDEX_TEMPLATE.format("\n".join("<li><a href='{0}/'>{0}</a></li>"
90+ .format(name)
91+ for name in self.registrations))
92+
93 def lookup_handler(self, path):
94 """"
95 Search for a callback function registered to handle the given path.
96@@ -71,6 +97,8 @@
97 path = path[1:]
98
99 spl = path.split('/', 1)
100+ if len(spl) != 2 and not spl[0]:
101+ return self._index
102 if len(spl) != 2:
103 raise HandlerNotFoundError("Path only has one component")
104 plugin_name, sub_path = spl
105@@ -115,8 +143,11 @@
106 def register_resource(self, plugin, resource):
107 self.root.putChild(plugin.name, resource)
108
109- def endroid_init(self, port, interface):
110+ def endroid_init(self, port, interface, media_dir):
111 self.root = IndexPage(self)
112+ logging.info("Publishing static files from {}".format(media_dir))
113+ self._media = File(media_dir)
114+ self.root.putChild("_media", self._media)
115 factory = Site(self.root)
116 reactor.listenTCP(port, factory, interface=interface)
117
118@@ -167,5 +198,6 @@
119 if not HTTPInterface.enInited:
120 port = self.vars.get("port", DEFAULT_HTTP_PORT)
121 interface = self.vars.get("interface", DEFAULT_HTTP_INTERFACE)
122- HTTPInterface.object.endroid_init(port, interface)
123+ media_dir = self.vars.get("media_dir", DEFAULT_MEDIA_DIR)
124+ HTTPInterface.object.endroid_init(port, interface, media_dir)
125 HTTPInterface.enInited = True

Subscribers

People subscribed via source and target branches