Package flumotion :: Package component :: Package misc :: Package httpserver :: Package httpcached :: Module file_provider
[hide private]

Source Code for Module flumotion.component.misc.httpserver.httpcached.file_provider

 1  # -*- Mode: Python; test-case-name: flumotion.test.test_component_providers -*- 
 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  from twisted.internet import defer 
19   
20  from flumotion.common import log 
21  from flumotion.component.misc.httpserver import fileprovider 
22  from flumotion.component.misc.httpserver import localpath 
23  from flumotion.component.misc.httpserver.httpcached import file_reader 
24   
25   
26  BASE_PATH = "/" 
27   
28  LOG_CATEGORY = "fileprovider-httpcached" 
29   
30   
31 -class FileProviderHTTPCachedPlug(fileprovider.FileProviderPlug, log.Loggable):
32 """ 33 Implements the FileProviderPlug interface over a FileReader instance. 34 35 Needed because FileReader do not support file browsing. 36 """ 37 38 logCategory = LOG_CATEGORY 39
40 - def __init__(self, args):
42
43 - def start(self, component):
44 d = defer.Deferred() 45 d.addCallback(lambda _: self._reader.start()) 46 d.addCallback(lambda _: self) # Don't return internal references 47 d.callback(None) 48 return d
49
50 - def stop(self, component):
51 d = defer.Deferred() 52 d.addCallback(lambda _: self._reader.stop()) 53 d.addCallback(lambda _: self) # Don't return internal references 54 d.callback(None) 55 return d
56
57 - def startStatsUpdates(self, updater):
58 #FIXME: This is temporary. Should be done with plug UI. 59 # Used for the UI to know which plug is used 60 updater.update("provider-name", "fileprovider-httpcached") 61 self._reader.stats.startUpdates(updater)
62
63 - def stopStatsUpdates(self):
64 self._reader.stats.stopUpdates()
65
66 - def getRootPath(self):
67 return VirtualPath(self, BASE_PATH)
68 69
70 -class VirtualPath(localpath.LocalPath, log.Loggable):
71 72 logCategory = LOG_CATEGORY 73
74 - def __init__(self, plug, path):
75 localpath.LocalPath.__init__(self, path) 76 self.plug = plug
77
78 - def child(self, name):
79 childpath = self._getChildPath(name) 80 return VirtualPath(self.plug, childpath)
81
82 - def open(self):
83 return self.plug._reader.open(self._path)
84