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