# HG changeset patch # User Jeff Hammel # Date 1311088138 25200 # Node ID f1142bcce77a738a6a81c89ac4dd8c2d4717c6cd # Parent 4da97e040145ee3d62d19800a29c0388603f14a9 add ability to log uploads diff -r 4da97e040145 -r f1142bcce77a setup.py --- a/setup.py Sat Jul 16 17:46:04 2011 -0700 +++ b/setup.py Tue Jul 19 08:08:58 2011 -0700 @@ -3,7 +3,7 @@ version = "0.2.6" -setup(name='uploader', +setup(name='UploadView', version=version, description="a file uploader app", long_description="", diff -r 4da97e040145 -r f1142bcce77a uploader/dispatcher.py --- a/uploader/dispatcher.py Sat Jul 16 17:46:04 2011 -0700 +++ b/uploader/dispatcher.py Tue Jul 19 08:08:58 2011 -0700 @@ -1,5 +1,5 @@ """ -request dispatcher +request dispatcher for uploader """ import os @@ -14,7 +14,8 @@ 'query_string': None, 'subpath': False, 'display_contents': False, - 'app': None} + 'app': None, + 'log_file': None} def __init__(self, **kw): diff -r 4da97e040145 -r f1142bcce77a uploader/handlers.py --- a/uploader/handlers.py Sat Jul 16 17:46:04 2011 -0700 +++ b/uploader/handlers.py Tue Jul 19 08:08:58 2011 -0700 @@ -1,4 +1,5 @@ import os +import sys from urlparse import urlparse from webob import Response, exc @@ -45,6 +46,10 @@ form += '
Currently uploaded:
  • ' + '
  • '.join(contents) + '
' else: form += '
No files in upload directory
' + log_file = self.app.log_file + if log_file and os.path.exists(log_file): + log_contents = file(log_file).read() + form += '
Upload log:
%s
' % log_contents form += '' return Response(content_type='text/html', body=form) @@ -77,6 +82,13 @@ # write the file + redirect _path = os.path.join(self.app.directory, _path) self.write(fin, _path) + if self.app.log_file: + try: + f = file(self.app.log_file, 'a') + print >> f, fin.filename + f.close() + except Exception, e: + print >> sys.stderr, e return self.redirect(self.link('/?uploaded=' + fin.filename)) def path(directory, request):