From d4e43188b922d38fd012278f40eb84e94422b9be Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Sat, 8 Jul 2006 11:16:18 -0800 Subject: [PATCH] add support for interactive debugging via manhole.telnet... add some modules and provide functions to add to the namespace... drop the media server since we now serve all of our content though content.. [git-p4: depot-paths = "//depot/": change = 838] --- debug.py | 35 +++++++++++++++++++++++++++++++++++ pymediaserv | 28 +++++++++------------------- 2 files changed, 44 insertions(+), 19 deletions(-) create mode 100644 debug.py diff --git a/debug.py b/debug.py new file mode 100644 index 0000000..bf71002 --- /dev/null +++ b/debug.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +from twisted.internet import reactor + +__all__ = [ 'appendnamespace', 'insertnamespace', ] + +appendnamespace = lambda k, v: [] +insertnamespace = lambda k, v: None + +def doDebugging(opt): + if not opt: + return + + from twisted.manhole import telnet + + class Debug(telnet.Shell): + def welcomeMessage(self): + data = [ '', 'PyMedS Debugging Console', '', '' ] + return '\r\n'.join(data) + + sf = telnet.ShellFactory() + sf.protocol = Debug + reactor.listenTCP(56283, sf) + + global insertnamespace, appendnamespace + + def insertnamespace(k, v): + assert isinstance(k, basestring) + sf.namespace[k] = v + + def appendnamespace(k, v): + try: + sf.namespace[k].append(v) + except KeyError: + sf.namespace[k] = [ v ] diff --git a/pymediaserv b/pymediaserv index 580512f..55a2b94 100755 --- a/pymediaserv +++ b/pymediaserv @@ -13,6 +13,12 @@ import dvd import shoutcast import ZipStorage # w/ tarfile support, it will gobble up empty files! +import debug # my debugging module +debug.doDebugging(True) # open up debugging port +debug.insertnamespace('dvd', dvd) +debug.insertnamespace('shoutcast', shoutcast) +debug.insertnamespace('ZipStorage', ZipStorage) + from DIDLLite import TextItem, AudioItem, VideoItem, ImageItem, Resource, StorageFolder from FSStorage import FSDirectory import os @@ -44,6 +50,7 @@ log.startLogging(sys.stdout) from SSDP import SSDPServer, SSDP_PORT, SSDP_ADDR s = SSDPServer() +debug.insertnamespace('s', s) port = reactor.listenMulticast(SSDP_PORT, s) port.joinGroup(SSDP_ADDR) @@ -73,8 +80,10 @@ class RootDevice(static.Data): static.Data.__init__(self, d, 'text/xml') root = WebServer() +debug.insertnamespace('root', root) content = resource.Resource() cds = ContentDirectoryServer('My Media Server', klass = FSDirectory, path = 'media', urlbase = os.path.join(urlbase, 'content'), webbase = content) # This sets up the root to be the media dir so we don't have to enumerate the directory +debug.insertnamespace('cds', cds) root.putChild('ContentDirectory', cds) cds = cds.control root.putChild('ConnectionManager', ConnectionManagerServer()) @@ -82,25 +91,6 @@ root.putChild('root-device.xml', RootDevice()) root.putChild('content', content) -# Area of server to serve media files from - -from MediaServer import MediaServer - -medianode = static.File('media') -medianode.contentTypes.update( { - '.wmv': 'video/x-ms-wmv', - #'.ts': 'video/mp2t', - '.ts': 'video/mpeg', # we may want this instead of mp2t - '.m2t': 'video/mpeg', - #'.mp4': 'video/mp4', - '.mp4': 'video/mpeg', - '.dat': 'video/mpeg', # VCD tracks - '.ogm': 'application/ogg', - '.vob': 'video/mpeg', - #'.m4a': 'audio/mp4', # D-Link can't seem to play AAC files. -}) -root.putChild('media', medianode) - site = server.Site(root) reactor.listenTCP(listenPort, site)