projects
/
zzz-floof.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
the beginnings of user-art relations. You can add relations, and it makes sure they...
[zzz-floof.git]
/
floof
/
lib
/
file_storage.py
diff --git
a/floof/lib/file_storage.py
b/floof/lib/file_storage.py
index
5595e88
..
90561d0
100644
(file)
--- a/
floof/lib/file_storage.py
+++ b/
floof/lib/file_storage.py
@@
-3,6
+3,8
@@
import os, shutil, tempfile, hashlib
chunk_size = 1024*1024 # TODO: is this a good chunk size?
chunk_size = 1024*1024 # TODO: is this a good chunk size?
+from pylons import config
+
"""
Notes:
# Here's one way to move stuff...
"""
Notes:
# Here's one way to move stuff...
@@
-16,17
+18,23
@@
from mimetypes import guess_type
guess_type(temp.filename)[0]
"""
guess_type(temp.filename)[0]
"""
+def get_path(space, hash):
+ return "/" + os.path.join( space, hash[:2], hash[2:] )
+
+
+def save_file(space, temp):
+
+ dest_root = os.path.join( config['app_conf']['static_root'], space )
-def save_file(dest_root, temp):
# we don't know where we're going to save this stuff yet,
# so I guess we'll write it to another tempfile. One we know the path of.
# we don't know where we're going to save this stuff yet,
# so I guess we'll write it to another tempfile. One we know the path of.
- # I'm assuming the tempfile we get from pylons is set to delete itself
+ # I'm assuming the tempfile we get from pylons is set to delete itself
# when it closes, and has no visible path. Maybe I'm wrong?
intermediate_file_descriptor, intermediate_path = tempfile.mkstemp()
# when it closes, and has no visible path. Maybe I'm wrong?
intermediate_file_descriptor, intermediate_path = tempfile.mkstemp()
-
+
# that function gives me an integer file descriptor for some reason.
intermediate_file = os.fdopen(intermediate_file_descriptor, "wb")
# that function gives me an integer file descriptor for some reason.
intermediate_file = os.fdopen(intermediate_file_descriptor, "wb")
-
+
sha1 = hashlib.sha1()
while 1:
data = temp.file.read(chunk_size)
sha1 = hashlib.sha1()
while 1:
data = temp.file.read(chunk_size)
@@
-44,7
+52,7
@@
def save_file(dest_root, temp):
dest_path = os.path.join( dest_dir, hash[2:] )
makedirs(dest_dir)
dest_path = os.path.join( dest_dir, hash[2:] )
makedirs(dest_dir)
-
os.renam
e(intermediate_path, dest_path)
+
shutil.mov
e(intermediate_path, dest_path)
return hash
return hash
@@
-55,4
+63,4
@@
def makedirs(dir):
os.makedirs(dir)
except OSError:
pass
os.makedirs(dir)
except OSError:
pass
-
\ No newline at end of file
+