witten
/
luminotes
Archived
1
0
Fork 0

Now storing uploaded files in home directory / APPDATA. And made uploads always use binary mode, necessary on Windows.

Also fixed removal of log files on startup to remove them from the right location.
This commit is contained in:
Dan Helfman 2008-08-25 23:30:36 -07:00
parent 978ce6a360
commit 7a65670c45
5 changed files with 38 additions and 9 deletions

9
NEWS
View File

@ -1,7 +1,14 @@
1.4.28:
* Completed the Luminotes Desktop Windows installer.
* Improved logging, so tracebacks in production and desktop mode actually go
to a file. Also removing logs on startup to prevent endless log growth.
to a file. Also removed logs on startup to prevent endless log growth.
* Moved "files" directory into ~/.luminotes or %APPDATA%\Luminotes.
* NOTE: After upgrading to this release, you must move your Luminotes
"files" directory into ~/.luminotes/ or you will not be able to access
your uploaded files:
mkdir ~/.luminotes
chmod 700 ~/.luminotes
mv files ~/.luminotes
1.4.27: August 22, 2008
* Fixed a bug in tools/initdb.py and tools/updatedb.py that caused them to

View File

@ -1,8 +1,10 @@
import os
import re
import sys
import cgi
import time
import urllib
import os.path
import tempfile
import cherrypy
from PIL import Image
@ -56,6 +58,22 @@ current_uploads = {}
current_uploads_lock = Lock()
def make_files_dir():
if sys.platform.startswith( "win" ):
files_dir = os.path.join( os.environ.get( "APPDATA" ), "Luminotes", "files" )
else:
files_dir = os.path.join( os.environ.get( "HOME", "" ), ".luminotes", "files" )
if not os.path.exists( files_dir ):
import stat
os.makedirs( files_dir, stat.S_IXUSR | stat.S_IRUSR | stat.S_IWUSR )
return files_dir
files_dir = make_files_dir()
class Upload_file( object ):
"""
File-like object for storing file uploads.
@ -109,13 +127,18 @@ class Upload_file( object ):
@staticmethod
def make_server_filename( file_id ):
return u"files/%s" % file_id
global files_dir
return os.path.join( files_dir, u"%s" % file_id )
@staticmethod
def open_file( file_id, mode = None ):
if mode:
return file( Upload_file.make_server_filename( file_id ), mode )
return file( Upload_file.make_server_filename( file_id ) )
# force binary mode
if not mode:
mode = "b"
elif "b" not in mode:
mode = "%sb" % mode
return file( Upload_file.make_server_filename( file_id ), mode )
@staticmethod
def open_image( file_id ):
@ -142,7 +165,7 @@ class FieldStorage( cherrypy._cpcgifs.FieldStorage ):
"""
Derived from cherrypy._cpcgifs.FieldStorage, which is in turn derived from cgi.FieldStorage, which
calls make_file() to create a temporary file where file uploads are stored. By wrapping this file
object, we can track its progress as its written. Inspired by:
object, we can track its progress as it's written. Inspired by:
http://www.cherrypy.org/attachment/ticket/546/uploadfilter.py
This method relies on a file_id parameter being present in the HTTP query string.

View File

View File

@ -77,11 +77,11 @@ def main( args ):
# remove the existing log files, if any
try:
os.remove( "luminotes.log" )
os.remove( cherrypy.config.configMap[ u"global" ].get( u"server.log_access_file" ) )
except OSError:
pass
try:
os.remove( "luminotes_error.log" )
os.remove( cherrypy.config.configMap[ u"global" ].get( u"server.log_file" ) )
except OSError:
pass

View File

@ -252,7 +252,6 @@ data_files = [
( "static/images/toolbar/small", files( "static/images/toolbar/small/*.*", excludes = [ "static/images/toolbar/small/*.xcf" ] ) ),
( "static/js", files( "static/js/*.*" ) ),
( "static/js", files( "static/js/*_LICENSE" ) ),
( "files", files( "files/.empty" ) ),
]
package_data = { ".": sum( [ pair[ 1 ] for pair in data_files ], [] ) }