changeset 20:f1142bcce77a

add ability to log uploads
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 19 Jul 2011 08:08:58 -0700
parents 4da97e040145
children 183224756ded
files setup.py uploader/dispatcher.py uploader/handlers.py
diffstat 3 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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="",
--- 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):
 
--- 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 += '<div><i>Currently uploaded:<ul><li>' + '</li><li>'.join(contents) + '</li></ul></i></div>'
             else:
                 form += '<div><i>No files in upload directory</i></div>'
+            log_file = self.app.log_file
+            if log_file and os.path.exists(log_file):
+                log_contents = file(log_file).read()
+                form += '<div>Upload log:<pre>%s</pre></div>' % log_contents
         form += '</body></html>'
         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):