# HG changeset patch
# User morphbr
# Date 1180563278 -3600
# Node ID f5f7abc760aad1262ef699031fbaa710335f0696
# Parent c397a899490f0e04c313e4c60c23c395e0e0014f
[svn r729] * GMyth-Streamer
- More bug fixes ;-)
- Coding style fixes
- Inserted request_handler file
diff -r c397a899490f -r f5f7abc760aa gmyth-stream/server/0.3/gms.py
--- a/gmyth-stream/server/0.3/gms.py Wed May 30 19:53:13 2007 +0100
+++ b/gmyth-stream/server/0.3/gms.py Wed May 30 23:14:38 2007 +0100
@@ -21,6 +21,9 @@
"\t%(message)s"),
datefmt="%Y-%m-%d %H:%M:%S")
+if not os.path.exists(".transcoded"):
+ os.mkdir(".transcoded")
+
pd = os.path.join("plugins", "transcoders")
load_plugins_transcoders(pd)
serve_forever()
diff -r c397a899490f -r f5f7abc760aa gmyth-stream/server/0.3/lib/file_handler.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gmyth-stream/server/0.3/lib/file_handler.py Wed May 30 23:14:38 2007 +0100
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+
+__author__ = "Artur Duque de Souza"
+__author_email__ = "artur.souza@indt.org.br"
+__license__ = "GPL"
+__version__ = "0.1"
+
+import os
+import pickle
+import lib.utils as utils
+
+from stat import *
+
+__all__ = ("FileList", "list_media_files")
+
+
+class TranscodedFile(object):
+ """This class creates and reads information about transcoded files."""
+ opts = {}
+
+ def __init__(self, filename, args):
+ print filename
+ if filename == "" or not os.path.exists(filename):
+ self.opts = args.copy()
+ self.opts["original"] = self.opts.pop("input", "").split("://")[1]
+ self.opts["original_mtime"] = os.stat(
+ self.opts["original"])[ST_MTIME]
+
+ name = os.path.splitext(os.path.basename(self.opts["outfile"]))[0]
+ output = open(".transcoded/%s.dat" % name, "wb")
+ # dumps data using the highest protocol
+ pickle.dump(self.opts, output, -1)
+ output.close()
+ else:
+ name = os.path.splitext(os.path.basename(filename))[0]
+ pkl_file = open(".transcoded/%s.dat" % name, "rb")
+ self.opts = pickle.load(pkl_file)
+ # __init__()
+
+# TranscodedFile
+
+
+class FileList(list):
+ """Class to hold file's list - reimplements str and repr."""
+ def __str__(self):
+ ret = ""
+ if len(self) > 0:
+ for item in self:
+ ret = ret + " %s" % item
+ return ret
+ # __str__()
+
+ def __repr__(self):
+ return self.__str__()
+ # __repr__()
+
+# FileList
+
+def list_media_files(directory, file_list):
+ """Show all the media files with extension defined in the var 'ext'
+ that are in the directory, appending each one to 'file_list'."""
+ ext = ['mpg', 'avi', 'mp4', 'nuv', 'mpeg', 'mov']
+ for root, dirs, files in os.walk(directory):
+ for name in files:
+ if os.path.splitext(name)[1].strip(".") in ext:
+ media = os.path.join(root,name)
+ if media not in file_list:
+ file_list.append(os.path.join(root,name))
+
+ return True
+# list_media_files()
diff -r c397a899490f -r f5f7abc760aa gmyth-stream/server/0.3/lib/request_handler.py
--- a/gmyth-stream/server/0.3/lib/request_handler.py Wed May 30 19:53:13 2007 +0100
+++ b/gmyth-stream/server/0.3/lib/request_handler.py Wed May 30 23:14:38 2007 +0100
@@ -3,20 +3,22 @@
__author__ = "Gustavo Sverzut Barbieri / Artur Duque de Souza"
__author_email__ = "barbieri@gmail.com / artur.souza@indt.org.br"
__license__ = "GPL"
-__version__ = "0.4"
+__version__ = "0.3"
import os
+import cgi
+import socket
+import logging
+import urlparse
import threading
import SocketServer
import BaseHTTPServer
-import socket
-import urlparse
-import cgi
+
import lib.utils as utils
-import logging
+import lib.file_handler as files
+import lib.transcoder as transcoder
from log import Log
-import lib.transcoder as transcoder
__all__ = ("RequestHandler")
@@ -48,35 +50,32 @@
def do_dispatch(self, body):
self.url = self.path
-
pieces = urlparse.urlparse(self.path)
self.path = pieces[2]
self.query = cgi.parse_qs(pieces[4])
- if self.path == "/":
- self.serve_main(body)
- elif self.path == "/shutdown.do":
- self.serve_shutdown(body)
- elif self.path == "/stop-transcoder.do":
- self.serve_stop_transcoder(body)
- elif self.path == "/status.do":
- self.serve_status(body)
- elif self.path == "/version.do":
- self.serve_version(body)
- elif self.path == "/new_id.do":
- self.serve_new_id(body)
- elif self.path == "/get_log.do":
- self.serve_get_log(body)
- elif self.path == "/get_all_log.do":
- self.serve_get_all_log(body)
- elif self.path == "/stream.do":
- self.serve_stream(body)
- else:
+ url = {
+ "/": self.serve_main,
+ "/shutdown.do": self.serve_shutdown,
+ "/stop-transcoder.do": self.serve_stop_transcoder,
+ "/status.do": self.serve_status,
+ "/version.do": self.serve_version,
+ "/new_id.do": self.serve_new_id,
+ "/get_log.do": self.serve_get_log,
+ "/get_all_log.do": self.serve_get_all_log,
+ "/stream.do": self.serve_stream,
+ "/list.do": self.serve_list,
+ }
+
+ try:
+ url[self.path](body)
+ except KeyError, e:
action = self.query.get("action", None)
if action and "stream.do" in action:
self.serve_stream(body)
else:
self.send_error(404, "File not found")
+
# do_dispatch()
@@ -94,10 +93,10 @@
ret = ""
for name, url in self.menu.items():
ret += utils.getHTML("menu", {"name": name, "url": url})
-
return ret
# _nav_items()
+
def serve_main(self, body):
self.send_response(200)
self.send_header("Content-Type", "text/html")
@@ -107,6 +106,7 @@
self.wfile.write(utils.getHTML("index", {"menu": self._nav_items()}))
# serve_main()
+
def serve_version(self, body):
self.send_response(200)
self.send_header("Content-Type", "text/html")
@@ -114,6 +114,7 @@
self.end_headers()
if body:
self.wfile.write("Version: %s" % __version__)
+ # serve_version
def serve_shutdown(self, body):
@@ -127,6 +128,24 @@
# serve_shutdown()
+ def serve_list(self, body):
+ self.send_response(200)
+ self.send_header("Content-Type", "text/html")
+ self.send_header('Connection', 'close')
+ self.end_headers()
+ directories = self.query.get("directory", None)
+ if body and directories:
+ file_list = []
+ for directory in directories[0].split(";"):
+ files.list_media_files(directory, file_list)
+
+ output = files.FileList(map(lambda x, y: x+y, file_list,
+ ["
"]*len(file_list)))
+ self.wfile.write(utils.getHTML("file_list", {"file_list": output}))
+
+ # serve_list()
+
+
def serve_stop_all_transcoders(self, body):
self.send_response(200)
self.send_header("Content-Type", "text/html")
@@ -134,7 +153,8 @@
self.end_headers()
if body:
self.server.stop_transcoders()
- self.wfile.write(utils.getHTML("stop_all", {"menu": self._nav_items()}))
+ self.wfile.write(utils.getHTML("stop_all",
+ {"menu": self._nav_items()}))
# serve_stop_all_transcoders()
@@ -186,11 +206,16 @@
if body:
tl = self.server.get_transcoders()
- if not tl:
+ if not tl and not self.query.get("tid", None):
running = "
No running transcoder.
\n" stopall = "" stopone = "" + elif self.query.get("tid", None) and not tl: + tid = int(self.query.get("tid")[0]) + stat = self.transcoders_log.get_status(tid) + self.wfile.write("Running: %s" % stat) + elif self.query.get("tid", None): req_tid = int(self.query.get("tid")[0]) for transcoder, request in tl: @@ -261,7 +286,7 @@ if self.query.get("tid", None): tid = int(self.query.get("tid")[0]) stat = self.transcoders_log.get_status(tid) - self.wfile.write("%s" % stat) + self.wfile.write("Status: %s" % stat) else: stat = self.transcoders_log.get_status() for rtid, status in stat.iteritems(): diff -r c397a899490f -r f5f7abc760aa gmyth-stream/server/0.3/lib/utils.py --- a/gmyth-stream/server/0.3/lib/utils.py Wed May 30 19:53:13 2007 +0100 +++ b/gmyth-stream/server/0.3/lib/utils.py Wed May 30 23:14:38 2007 +0100 @@ -15,7 +15,8 @@ log = logging.getLogger("gms.utils") -__all__ = ("which", "load_plugins", "PluginSet", "getHTML") +__all__ = ("which", "load_plugins", "PluginSet", "getHTML", + "progress_bar", "create_tid", "list_media_files") def which(app): """Function to implement which(1) unix command""" @@ -165,7 +166,7 @@ return "