# HG changeset patch # User morphbr # Date 1177340814 -3600 # Node ID a1783dab9ba6cda42de25470b307764e23c9269f # Parent 170e18a7ca71771683b87d2f550da3934003e30d [svn r591] - Updated GMyth-Streamer core diff -r 170e18a7ca71 -r a1783dab9ba6 gmyth-stream/server/0.2/lib/server.py --- a/gmyth-stream/server/0.2/lib/server.py Fri Apr 20 21:48:57 2007 +0100 +++ b/gmyth-stream/server/0.2/lib/server.py Mon Apr 23 16:06:54 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.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

    -
    - :// - -
    - - - -""") - # 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.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:

    - - - - -""") + + 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("""\ - - - - -""") + 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() diff -r 170e18a7ca71 -r a1783dab9ba6 gmyth-stream/server/0.2/lib/utils.py --- a/gmyth-stream/server/0.2/lib/utils.py Fri Apr 20 21:48:57 2007 +0100 +++ b/gmyth-stream/server/0.2/lib/utils.py Mon Apr 23 16:06:54 2007 +0100 @@ -15,10 +15,10 @@ log = logging.getLogger("gms.utils") -__all__ = ("which", "load_plugins", "PluginSet") +__all__ = ("which", "load_plugins", "PluginSet", "getHTML") def which(app): - """function to implement which(1) unix command""" + """Function to implement which(1) unix command""" pl = os.environ["PATH"].split(os.pathsep) for p in pl: path = os.path.join(p, app) @@ -121,6 +121,7 @@ def load_plugins(directory, basetype): + """Function to load plugins from a given directory""" tn = basetype.__name__ log.debug("Loading plugins from %s, type=%s" % (directory, tn)) @@ -146,3 +147,15 @@ return plugins # load_plugins() + +def getHTML(html_file, params={}): + """This function parses a file 'html_file.html' with the given + parameters and returns a formated web-page""" + try: + filename = os.path.join(sys.path[0], "html", html_file + ".html") + html = open(filename).read() % params + return html + except Exception, e: + return "HTML format error. Wrong keys: %s" % e + +# getHTML diff -r 170e18a7ca71 -r a1783dab9ba6 gmyth-stream/server/0.2/plugins/transcoders/mencoder.py --- a/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Fri Apr 20 21:48:57 2007 +0100 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Mon Apr 23 16:06:54 2007 +0100 @@ -9,6 +9,7 @@ __all__ = ("TranscoderMencoder",) class TranscoderMencoder(server.Transcoder): + """Transcoder class that implements a transcoder using Mencoder""" mencoder_path = utils.which("mencoder") name = "mencoder" priority = -1