diff -r 7dc357cbaa40 -r f36075170a4e gmyth-stream/server/0.2/lib/server.py
--- a/gmyth-stream/server/0.2/lib/server.py Thu Apr 19 22:38:46 2007 +0100
+++ b/gmyth-stream/server/0.2/lib/server.py Wed Apr 25 15:50:41 2007 +0100
@@ -78,6 +78,12 @@
def_transcoder = None
transcoders = utils.PluginSet(Transcoder)
+ menu = {
+ "Status": "/status.do",
+ "Stop": "/stop-transcoder.do",
+ "Shutdown": "/shutdown.do"
+ }
+
@classmethod
def load_plugins_transcoders(cls, directory):
cls.transcoders.load_from_directory(directory)
@@ -122,14 +128,16 @@
def _nav_items(self):
- self.wfile.write("""\
-
Play
- Status
- Stop transcoders
- Shutdown Server
-""")
+ ret = ""
+ for name, url in self.menu.items():
+ ret += utils.getHTML("menu", {"name": name, "url": url})
+
+ return ret
# _nav_items()
+ def _create_html_item(self, opt):
+ return "%s\n" % opt
+ # _create_html_item
def serve_main(self, body):
self.send_response(200)
@@ -137,62 +145,17 @@
self.send_header('Connection', 'close')
self.end_headers()
if body:
- self.wfile.write("""\
-
- GMyth-Streamer Server
-
-Welcome to GMyth-Streamer Server
-
-""")
- self._nav_items()
- self.wfile.write("""\
-
-
-
-""")
+ self.wfile.write(utils.getHTML("index", {"menu": self._nav_items()}))
# serve_main()
- def serve_play(self, body):
- self.send_response(200)
- self.send_header("Content-Type", "text/html")
- self.send_header('Connection', 'close')
- self.end_headers()
- if body:
- self.wfile.write("""\
-
- GMyth-Streamer Server
-
- Play
-
-
-""")
- self._nav_items()
- self.wfile.write("""\
-
-
-
-""")
- # serve_play()
-
-
def serve_shutdown(self, body):
self.send_response(200)
self.send_header("Content-Type", "text/html")
self.send_header('Connection', 'close')
self.end_headers()
if body:
- self.wfile.write("""\
-
- GMyth-Streamer Server Exited
-
- GMyth-Streamer is not running anymore
-
-
-""")
+ self.wfile.write(utils.getHTML("shutdown"))
self.server.server_close()
# serve_shutdown()
@@ -204,19 +167,7 @@
self.end_headers()
if body:
self.server.stop_transcoders()
- self.wfile.write("""\
-
- GMyth-Streamer Server Stopped Transcoders
-
- GMyth-Streamer stopped running transcoders
-
-""")
- self._nav_items()
- self.wfile.write("""\
-
-
-
- """)
+ self.wfile.write(utils.getHTML("stop_all", {"menu": self._nav_items()}))
# serve_stop_all_transcoders()
@@ -225,14 +176,8 @@
self.send_header("Content-Type", "text/html")
self.send_header('Connection', 'close')
self.end_headers()
+ opts = ""
if body:
- self.wfile.write("""\
-
- GMyth-Streamer Server Stopped Transcoders
-
- GMyth-Streamer stopped running transcoders:
-
- """)
transcoders = self.server.get_transcoders()
for req in requests:
@@ -251,20 +196,14 @@
except Exception, e:
self.log.info("Plugin already stopped")
- self.wfile.write("""\
- - %s: %s:%s
-""" % (t, addr[0], addr[1]))
+ opts += self._create_html_item("%s: %s:%s" % (
+ t, addr[0], addr[1]))
+
break
- self.wfile.write("""\
-
-
-""")
- self._nav_items()
- self.wfile.write("""\
-
-
-
-""")
+
+ self.wfile.write(utils.getHTML("stop_selected",
+ {"menu": self._nav_items(),
+ "opts": opts}))
# serve_stop_selected_transcoders()
@@ -284,38 +223,29 @@
self.send_header("Content-Type", "text/html")
self.send_header('Connection', 'close')
self.end_headers()
+
if body:
- self.wfile.write("""\
-
- GMyth-Streamer Server Status
-
- GMyth-Streamer Status
-""")
tl = self.server.get_transcoders()
if not tl:
- self.wfile.write("No running transcoder.
\n")
+ running = "No running transcoder.
\n"
+ stopall = ""
+ stopone = ""
else:
- self.wfile.write("Running transcoders:
\n")
- self.wfile.write("""\
-
- - [STOP ALL]
-""")
+ running = "Running transcoders:
\n"
+ stopall = self._create_html_item("[STOP ALL]" %
+ self.menu["Stop"])
+
for transcoder, request in tl:
- self.wfile.write("""\
- - %s: %s:%s [STOP]
-""" % (transcoder, request.client_address[0], request.client_address[1],
- request.client_address[0], request.client_address[1]))
+ stopone = self._create_html_item("%s: %s:%s"
+ "[STOP]" % (
+ transcoder, request.client_address[0], request.client_address[1],
+ self.menu["Stop"], request.client_address[0], request.client_address[1]) )
- self.wfile.write("""\
-
-
-""")
- self._nav_items()
- self.wfile.write("""\
-
-
-
-""")
+ self.wfile.write(utils.getHTML("status",
+ {"menu": self._nav_items(),
+ "running": running,
+ "stopall": stopall,
+ "stopone": stopone}))
# serve_status()
@@ -455,7 +385,6 @@
def serve_forever(host="0.0.0.0", port=40000):
addr = (host, port)
-
RequestHandler.protocol_version = "HTTP/1.0"
httpd = Server(addr, RequestHandler)
httpd.serve_forever()