1.1 --- a/gmyth-stream/server/0.2/lib/server.py Fri Apr 20 21:48:57 2007 +0100
1.2 +++ b/gmyth-stream/server/0.2/lib/server.py Mon Apr 23 16:06:54 2007 +0100
1.3 @@ -78,6 +78,12 @@
1.4 def_transcoder = None
1.5 transcoders = utils.PluginSet(Transcoder)
1.6
1.7 + menu = {
1.8 + "Status": "/status.do",
1.9 + "Stop": "/stop-transcoder.do",
1.10 + "Shutdown": "/shutdown.do"
1.11 + }
1.12 +
1.13 @classmethod
1.14 def load_plugins_transcoders(cls, directory):
1.15 cls.transcoders.load_from_directory(directory)
1.16 @@ -122,14 +128,16 @@
1.17
1.18
1.19 def _nav_items(self):
1.20 - self.wfile.write("""\
1.21 - <li><a href="/play.do">Play</a></li>
1.22 - <li><a href="/status.do">Status</a></li>
1.23 - <li><a href="/stop-transcoder.do">Stop transcoders</a></li>
1.24 - <li><a href="/shutdown.do">Shutdown Server</a></li>
1.25 -""")
1.26 + ret = ""
1.27 + for name, url in self.menu.items():
1.28 + ret += utils.getHTML("menu", {"name": name, "url": url})
1.29 +
1.30 + return ret
1.31 # _nav_items()
1.32
1.33 + def _create_html_item(self, opt):
1.34 + return "<li>%s</li>\n" % opt
1.35 + # _create_html_item
1.36
1.37 def serve_main(self, body):
1.38 self.send_response(200)
1.39 @@ -137,62 +145,17 @@
1.40 self.send_header('Connection', 'close')
1.41 self.end_headers()
1.42 if body:
1.43 - self.wfile.write("""\
1.44 -<html>
1.45 - <head><title>GMyth-Streamer Server</title></head>
1.46 - <body>
1.47 -<h1>Welcome to GMyth-Streamer Server</h1>
1.48 -<ul>
1.49 -""")
1.50 - self._nav_items()
1.51 - self.wfile.write("""\
1.52 -</ul>
1.53 - </body>
1.54 -</html>
1.55 -""")
1.56 + self.wfile.write(utils.getHTML("index", {"menu": self._nav_items()}))
1.57 # serve_main()
1.58
1.59
1.60 - def serve_play(self, body):
1.61 - self.send_response(200)
1.62 - self.send_header("Content-Type", "text/html")
1.63 - self.send_header('Connection', 'close')
1.64 - self.end_headers()
1.65 - if body:
1.66 - self.wfile.write("""\
1.67 -<html>
1.68 - <head><title>GMyth-Streamer Server</title></head>
1.69 - <body>
1.70 - <h1>Play</h1>
1.71 - <form action="/stream.do" method="GET">
1.72 - <input type="text" name="type" value="file" />://<input type="text" name="location" value=""/>
1.73 - <input type="submit" />
1.74 - </form>
1.75 - <ul>
1.76 -""")
1.77 - self._nav_items()
1.78 - self.wfile.write("""\
1.79 - </ul>
1.80 - </body>
1.81 -</html>
1.82 -""")
1.83 - # serve_play()
1.84 -
1.85 -
1.86 def serve_shutdown(self, body):
1.87 self.send_response(200)
1.88 self.send_header("Content-Type", "text/html")
1.89 self.send_header('Connection', 'close')
1.90 self.end_headers()
1.91 if body:
1.92 - self.wfile.write("""\
1.93 -<html>
1.94 - <head><title>GMyth-Streamer Server Exited</title></head>
1.95 - <body>
1.96 - <h1>GMyth-Streamer is not running anymore</h1>
1.97 - </body>
1.98 -</html>
1.99 -""")
1.100 + self.wfile.write(utils.getHTML("shutdown"))
1.101 self.server.server_close()
1.102 # serve_shutdown()
1.103
1.104 @@ -204,19 +167,7 @@
1.105 self.end_headers()
1.106 if body:
1.107 self.server.stop_transcoders()
1.108 - self.wfile.write("""\
1.109 -<html>
1.110 - <head><title>GMyth-Streamer Server Stopped Transcoders</title></head>
1.111 - <body>
1.112 - <h1>GMyth-Streamer stopped running transcoders</h1>
1.113 - <ul>
1.114 -""")
1.115 - self._nav_items()
1.116 - self.wfile.write("""\
1.117 - </ul>
1.118 - </body>
1.119 -</html>
1.120 - """)
1.121 + self.wfile.write(utils.getHTML("stop_all", {"menu": self._nav_items()}))
1.122 # serve_stop_all_transcoders()
1.123
1.124
1.125 @@ -225,14 +176,8 @@
1.126 self.send_header("Content-Type", "text/html")
1.127 self.send_header('Connection', 'close')
1.128 self.end_headers()
1.129 + opts = ""
1.130 if body:
1.131 - self.wfile.write("""\
1.132 -<html>
1.133 - <head><title>GMyth-Streamer Server Stopped Transcoders</title></head>
1.134 - <body>
1.135 - <h1>GMyth-Streamer stopped running transcoders:</h1>
1.136 - <ul>
1.137 - """)
1.138 transcoders = self.server.get_transcoders()
1.139
1.140 for req in requests:
1.141 @@ -251,20 +196,14 @@
1.142 except Exception, e:
1.143 self.log.info("Plugin already stopped")
1.144
1.145 - self.wfile.write("""\
1.146 - <li>%s: %s:%s</li>
1.147 -""" % (t, addr[0], addr[1]))
1.148 + opts += self._create_html_item("%s: %s:%s" % (
1.149 + t, addr[0], addr[1]))
1.150 +
1.151 break
1.152 - self.wfile.write("""\
1.153 - </ul>
1.154 - <ul>
1.155 -""")
1.156 - self._nav_items()
1.157 - self.wfile.write("""\
1.158 - </ul>
1.159 - </body>
1.160 -</html>
1.161 -""")
1.162 +
1.163 + self.wfile.write(utils.getHTML("stop_selected",
1.164 + {"menu": self._nav_items(),
1.165 + "opts": opts}))
1.166 # serve_stop_selected_transcoders()
1.167
1.168
1.169 @@ -284,38 +223,29 @@
1.170 self.send_header("Content-Type", "text/html")
1.171 self.send_header('Connection', 'close')
1.172 self.end_headers()
1.173 +
1.174 if body:
1.175 - self.wfile.write("""\
1.176 -<html>
1.177 - <head><title>GMyth-Streamer Server Status</title></head>
1.178 - <body>
1.179 - <h1>GMyth-Streamer Status</h1>
1.180 -""")
1.181 tl = self.server.get_transcoders()
1.182 if not tl:
1.183 - self.wfile.write("<p>No running transcoder.</p>\n")
1.184 + running = "<p>No running transcoder.</p>\n"
1.185 + stopall = ""
1.186 + stopone = ""
1.187 else:
1.188 - self.wfile.write("<p>Running transcoders:</p>\n")
1.189 - self.wfile.write("""\
1.190 - <ul>
1.191 - <li><a href="/stop-transcoder.do?request=all">[STOP ALL]</a></li>
1.192 -""")
1.193 + running = "<p>Running transcoders:</p>\n"
1.194 + stopall = self._create_html_item("<a href='%s?request=all'>[STOP ALL]</a>" %
1.195 + self.menu["Stop"])
1.196 +
1.197 for transcoder, request in tl:
1.198 - self.wfile.write("""\
1.199 - <li>%s: %s:%s <a href="/stop-transcoder.do?request=%s:%s">[STOP]</a></li>
1.200 -""" % (transcoder, request.client_address[0], request.client_address[1],
1.201 - request.client_address[0], request.client_address[1]))
1.202 + stopone = self._create_html_item("%s: %s:%s<a href='%s?request=%s:%s'>"
1.203 + "[STOP]</a>" % (
1.204 + transcoder, request.client_address[0], request.client_address[1],
1.205 + self.menu["Stop"], request.client_address[0], request.client_address[1]) )
1.206
1.207 - self.wfile.write("""\
1.208 - </ul>
1.209 - <ul>
1.210 -""")
1.211 - self._nav_items()
1.212 - self.wfile.write("""\
1.213 - </ul>
1.214 - </body>
1.215 -</html>
1.216 -""")
1.217 + self.wfile.write(utils.getHTML("status",
1.218 + {"menu": self._nav_items(),
1.219 + "running": running,
1.220 + "stopall": stopall,
1.221 + "stopone": stopone}))
1.222 # serve_status()
1.223
1.224
1.225 @@ -455,7 +385,6 @@
1.226
1.227 def serve_forever(host="0.0.0.0", port=40000):
1.228 addr = (host, port)
1.229 -
1.230 RequestHandler.protocol_version = "HTTP/1.0"
1.231 httpd = Server(addr, RequestHandler)
1.232 httpd.serve_forever()
2.1 --- a/gmyth-stream/server/0.2/lib/utils.py Fri Apr 20 21:48:57 2007 +0100
2.2 +++ b/gmyth-stream/server/0.2/lib/utils.py Mon Apr 23 16:06:54 2007 +0100
2.3 @@ -15,10 +15,10 @@
2.4
2.5 log = logging.getLogger("gms.utils")
2.6
2.7 -__all__ = ("which", "load_plugins", "PluginSet")
2.8 +__all__ = ("which", "load_plugins", "PluginSet", "getHTML")
2.9
2.10 def which(app):
2.11 - """function to implement which(1) unix command"""
2.12 + """Function to implement which(1) unix command"""
2.13 pl = os.environ["PATH"].split(os.pathsep)
2.14 for p in pl:
2.15 path = os.path.join(p, app)
2.16 @@ -121,6 +121,7 @@
2.17
2.18
2.19 def load_plugins(directory, basetype):
2.20 + """Function to load plugins from a given directory"""
2.21 tn = basetype.__name__
2.22 log.debug("Loading plugins from %s, type=%s" % (directory, tn))
2.23
2.24 @@ -146,3 +147,15 @@
2.25
2.26 return plugins
2.27 # load_plugins()
2.28 +
2.29 +def getHTML(html_file, params={}):
2.30 + """This function parses a file 'html_file.html' with the given
2.31 + parameters and returns a formated web-page"""
2.32 + try:
2.33 + filename = os.path.join(sys.path[0], "html", html_file + ".html")
2.34 + html = open(filename).read() % params
2.35 + return html
2.36 + except Exception, e:
2.37 + return "HTML format error. Wrong keys: %s" % e
2.38 +
2.39 +# getHTML
3.1 --- a/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Fri Apr 20 21:48:57 2007 +0100
3.2 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Mon Apr 23 16:06:54 2007 +0100
3.3 @@ -9,6 +9,7 @@
3.4 __all__ = ("TranscoderMencoder",)
3.5
3.6 class TranscoderMencoder(server.Transcoder):
3.7 + """Transcoder class that implements a transcoder using Mencoder"""
3.8 mencoder_path = utils.which("mencoder")
3.9 name = "mencoder"
3.10 priority = -1