diff uploader/handlers.py @ 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
line wrap: on
line diff
--- 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):