Trees | Indices | Help |
---|
|
1 # -*- Mode: Python -*- 2 # vi:si:et:sw=4:sts=4:ts=4 3 4 # Flumotion - a streaming media server 5 # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 6 # Copyright (C) 2010,2011 Flumotion Services, S.A. 7 # All rights reserved. 8 # 9 # This file may be distributed and/or modified under the terms of 10 # the GNU Lesser General Public License version 2.1 as published by 11 # the Free Software Foundation. 12 # This file is distributed without any warranty; without even the implied 13 # warranty of merchantability or fitness for a particular purpose. 14 # See "LICENSE.LGPL" in the source distribution for more information. 15 # 16 # Headers in this file shall remain intact. 17 18 import os 19 20 from twisted.web.resource import Resource 21 from twisted.web.static import Data, File 22 23 from flumotion.common import log 24 from flumotion.common.errors import ComponentStartError 25 from flumotion.component.misc.httpserver.httpserver import HTTPFileStreamer 26 from flumotion.component.plugs.base import ComponentPlug 27 from flumotion.component.plugs.cortado.cortado_location import \ 28 getCortadoFilename 29 from flumotion.configure import configure 30 31 __version__ = "$Rev$" 32 33 38 3941 """I generate the directory used to serve a cortado applet 42 It contains:: 43 - a html file, usually called index.html. 44 - cortado.jar - cortado java applet 45 """ 4695 9648 Resource.__init__(self) 49 50 index_name = properties.get('index', 'index.html') 51 52 root = mount_point 53 if not root.endswith("/"): 54 root += "/" 55 if index_name != 'index.html': 56 root = None 57 self._mount_point_root = root 58 self._properties = properties 59 self._index_content = self._get_index_content() 60 self._index_name = index_name 61 self._cortado_filename = filename 62 self._addChildren()6365 self.putChild("cortado.jar", 66 File(self._cortado_filename, 67 'application/x-java-archive')) 68 69 self.putChild(self._index_name, 70 self._index_content) 71 self.putChild('', self._index_content)7274 filename = self._properties.get('html-template') 75 if not filename: 76 filename = os.path.join(configure.datadir, 77 'cortado-template.html') 78 return filename7981 html_template = self._get_template_filename() 82 ns = {} 83 ns['has-audio'] = _htmlbool(self._properties['has-audio']) 84 ns['has-video'] = _htmlbool(self._properties['has-video']) 85 for attribute in ['codebase', 86 'width', 87 'height', 88 'stream-url', 89 'buffer-size']: 90 ns[attribute] = self._properties[attribute] 91 92 data = open(html_template, 'r').read() 93 content = data % ns 94 return Data(content, 'text/html')98 """I am a component plug for a http-server which plugs in a 99 http resource containing a cortado java applet. 100 """ 101120 121103 """ 104 @type component: L{HTTPFileStreamer} 105 """ 106 if not isinstance(component, HTTPFileStreamer): 107 raise ComponentStartError( 108 "A CortadoPlug %s must be plugged into a " 109 " HTTPStreamer component, not a %s" % ( 110 self, component.__class__.__name__)) 111 filename = getCortadoFilename() 112 if not filename: 113 raise ComponentStartError( 114 "Could not find cortado jar file") 115 log.debug('cortado', 'Attaching to %r' % (component, )) 116 resource = CortadoDirectoryResource(component.getMountPoint(), 117 self.args['properties'], 118 filename) 119 component.setRootResource(resource)123 import sys 124 from twisted.internet import reactor 125 from twisted.python.log import startLogging 126 from twisted.web.server import Site 127 startLogging(sys.stderr) 128 129 properties = {'has-audio': True, 130 'has-video': True, 131 'codebase': '/', 132 'width': 320, 133 'height': 240, 134 'stream-url': '/stream.ogg', 135 'buffer-size': 40} 136 root = CortadoDirectoryResource('/', properties, getCortadoFilename()) 137 site = Site(root) 138 139 reactor.listenTCP(8080, site) 140 reactor.run()141 142 if __name__ == "__main__": 143 test() 144
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Tue Aug 13 06:17:17 2013 | http://epydoc.sourceforge.net |