public
Last active

Serves static files from multiple local directories at a single external url

  • Download Gist
StaticFileScanner.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# Serves static files from multiple local directories at a single external url
# usage demo: https://gist.github.com/aausch/7348230
#
# Copyright 2013, Alex Ausch
# Free to use under attribution license: http://creativecommons.org/licenses/by/2.0/ca/
 
from twisted.web.resource import Resource
from twisted.web.static import File
 
class StaticFileScanner(Resource):
dirs = []
def __init__(self, *dirs):
if (len(dirs) < 1):
self.dirs = [File()]
else:
self.dirs = [File(d) for d in dirs]
Resource.__init__(self)
def getChild(self, *args):
for d in self.dirs:
if d.getChild(*args) != d.childNotFound:
return d.getChild(*args)
return self.dirs[0].childNotFound

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.