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) 2008 Fluendo, S.L. (www.fluendo.com). 6 # All rights reserved. 7 8 # This file may be distributed and/or modified under the terms of 9 # the GNU General Public License version 2 as published by 10 # the Free Software Foundation. 11 # This file is distributed without any warranty; without even the implied 12 # warranty of merchantability or fitness for a particular purpose. 13 # See "LICENSE.GPL" in the source distribution for more information. 14 15 # Licensees having purchased or holding a valid Flumotion Advanced 16 # Streaming Server license may use this file in accordance with the 17 # Flumotion Advanced Streaming Server Commercial License Agreement. 18 # See "LICENSE.Flumotion" in the source distribution for more information. 19 20 # Headers in this file shall remain intact. 21 22 import os 23 24 from twisted.web.resource import Resource 25 from twisted.web.static import Data, File 26 27 from flumotion.common import log 28 from flumotion.common.errors import ComponentStartError 29 from flumotion.component.misc.httpserver.httpserver import HTTPFileStreamer 30 from flumotion.component.plugs.base import ComponentPlug 31 from flumotion.component.plugs.cortado.cortado_location import \ 32 getCortadoFilename 33 from flumotion.configure import configure 34 35 __version__ = "$Rev$" 36 37 42 4345 """I generate the directory used to serve a cortado applet 46 It contains:: 47 - a html file, usually called index.html. 48 - cortado.jar - cortado java applet 49 """ 5099 10052 Resource.__init__(self) 53 54 index_name = properties.get('index', 'index.html') 55 56 root = mount_point 57 if not root.endswith("/"): 58 root += "/" 59 if index_name != 'index.html': 60 root = None 61 self._mount_point_root = root 62 self._properties = properties 63 self._index_content = self._get_index_content() 64 self._index_name = index_name 65 self._cortado_filename = filename 66 self._addChildren()6769 self.putChild("cortado.jar", 70 File(self._cortado_filename, 71 'application/x-java-archive')) 72 73 self.putChild(self._index_name, 74 self._index_content) 75 self.putChild('', self._index_content)7678 filename = self._properties.get('html-template') 79 if not filename: 80 filename = os.path.join(configure.datadir, 81 'cortado-template.html') 82 return filename8385 html_template = self._get_template_filename() 86 ns = {} 87 ns['has-audio'] = _htmlbool(self._properties['has-audio']) 88 ns['has-video'] = _htmlbool(self._properties['has-video']) 89 for attribute in ['codebase', 90 'width', 91 'height', 92 'stream-url', 93 'buffer-size']: 94 ns[attribute] = self._properties[attribute] 95 96 data = open(html_template, 'r').read() 97 content = data % ns 98 return Data(content, 'text/html')102 """I am a component plug for a http-server which plugs in a 103 http resource containing a cortado java applet. 104 """ 105124 125107 """ 108 @type component: L{HTTPFileStreamer} 109 """ 110 if not isinstance(component, HTTPFileStreamer): 111 raise ComponentStartError( 112 "A CortadoPlug %s must be plugged into a " 113 " HTTPStreamer component, not a %s" % ( 114 self, component.__class__.__name__)) 115 filename = getCortadoFilename() 116 if not filename: 117 raise ComponentStartError( 118 "Could not find cortado jar file") 119 log.debug('cortado', 'Attaching to %r' % (component, )) 120 resource = CortadoDirectoryResource(component.getMountPoint(), 121 self.args['properties'], 122 filename) 123 component.setRootResource(resource)127 import sys 128 from twisted.internet import reactor 129 from twisted.python.log import startLogging 130 from twisted.web.server import Site 131 startLogging(sys.stderr) 132 133 properties = {'has-audio': True, 134 'has-video': True, 135 'codebase': '/', 136 'width': 320, 137 'height': 240, 138 'stream-url': '/stream.ogg', 139 'buffer-size': 40} 140 root = CortadoDirectoryResource('/', properties, getCortadoFilename()) 141 site = Site(root) 142 143 reactor.listenTCP(8080, site) 144 reactor.run()145 146 if __name__ == "__main__": 147 test() 148
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Jun 17 13:31:35 2011 | http://epydoc.sourceforge.net |