# HG changeset patch # User Jeff Hammel # Date 1330562319 28800 # Node ID 1eb5e82605a59334ae321012bb1e7db984ed7d71 # Parent c6e459be8534ab51a926253e9675ca13d9951e3c * flush out README * other minor fixes diff -r c6e459be8534 -r 1eb5e82605a5 INSTALL.py --- a/INSTALL.py Wed Feb 29 16:15:31 2012 -0800 +++ b/INSTALL.py Wed Feb 29 16:38:39 2012 -0800 @@ -55,7 +55,7 @@ # find the clone filename = REPO.rstrip('/') - filename = REPO.split('/')[-1] + filename = filename.split('/')[-1] clone = os.path.join(src, filename) assert os.path.exists(clone), "Clone directory not found in %s" % src diff -r c6e459be8534 -r 1eb5e82605a5 README.txt --- a/README.txt Wed Feb 29 16:15:31 2012 -0800 +++ b/README.txt Wed Feb 29 16:38:39 2012 -0800 @@ -3,9 +3,58 @@ a simple static fileserver and directory index server in python (WSGI app) +About +----- + +Often for testing you will want a static fileserver and directory +index as part of your WSGI stack. In addition, you may have +requirements to run such as part of a production WSGI +stack. FileServer fits these needs. + +Motivation +---------- + +I needed a directory index server a la Apache to test a PyPI clone I +was using. After surveying what was out there, there didn't seem +anything out there that was easily consumable for my purposes. So I +wrote one only depending on +`webob `_ . + +Contents +-------- + +``from fileserver import *`` should give you access to all of the +usable components of fileserver: + + * ``file_response``: return a webob response object appropriate to a + file name + * ``FileApp``: WSGI app that wraps ``file_response`` + * ``Directory Server``: serves a directory tree and generated indices + * ``main``: command line entry point + +``FileApp`` and ``file_response`` are heavily borrowed from +http://docs.webob.org/en/latest/file-example.html though the example +there is more complete. I will work on making this more thorough +going forward. + +In addition there is a command line script, ``serve``, which may be +used to serve a directory with the +`wsgiref `_ server. + +Other Projects +-------------- + +While I didn't find them suitable for my use, there are other +standalone static fileservers available for python: + + * `Cling `_ + + * `Paste `_ ``StaticURLParser`` + + * `SimpleHTTPServer `_ + ---- Jeff Hammel http://k0s.org/hg/FileServer - diff -r c6e459be8534 -r 1eb5e82605a5 fileserver/web.py --- a/fileserver/web.py Wed Feb 29 16:15:31 2012 -0800 +++ b/fileserver/web.py Wed Feb 29 16:38:39 2012 -0800 @@ -14,7 +14,7 @@ from webob import Request, Response, exc from wsgiref.simple_server import make_server -__all__ = ['get_mimetype', 'file_response', 'FileApp', 'DirectoryServer'] +__all__ = ['get_mimetype', 'file_response', 'FileApp', 'DirectoryServer', 'main'] def get_mimetype(filename): type, encoding = mimetypes.guess_type(filename) @@ -22,6 +22,7 @@ return type or 'application/octet-stream' def file_response(filename): + """return a webob response object appropriate to a file name""" res = Response(content_type=get_mimetype(filename)) res.body = open(filename, 'rb').read() return res diff -r c6e459be8534 -r 1eb5e82605a5 setup.py --- a/setup.py Wed Feb 29 16:15:31 2012 -0800 +++ b/setup.py Wed Feb 29 16:38:39 2012 -0800 @@ -4,7 +4,7 @@ import os -version = "0.1" +version = "0.2" dependencies = ['webob'] # allow use of setuptools/distribute or distutils @@ -13,8 +13,7 @@ from setuptools import setup kw['entry_points'] = """ [console_scripts] - FileServer = FileServer.main:main - FileServer-template = FileServer.template:main + FileServer = FileServer.web:main """ kw['install_requires'] = dependencies except ImportError: