Commit 829def4b by Piotr Mitros

s3fs/untested implementation

parent 484258bb
...@@ -11,6 +11,9 @@ if settings.DJFS['type'] == 'osfs': ...@@ -11,6 +11,9 @@ if settings.DJFS['type'] == 'osfs':
from fs.osfs import OSFS from fs.osfs import OSFS
elif settings.DJFS['type'] == 'sf3s': elif settings.DJFS['type'] == 'sf3s':
from fs.s3fs import S3FS from fs.s3fs import S3FS
from boto.s3.connection import S3Connection
from boto.s3.key import Key
s3conn = S3Connection()
else: else:
raise AttributeError("Bad filesystem") raise AttributeError("Bad filesystem")
...@@ -61,7 +64,7 @@ def get_osfs(namespace): ...@@ -61,7 +64,7 @@ def get_osfs(namespace):
if not os.path.exists(full_path): if not os.path.exists(full_path):
os.makedirs(full_path) os.makedirs(full_path)
osfs = OSFS(full_path) osfs = OSFS(full_path)
osfs = patch_fs(osfs, namespace, lambda self, filename:os.path.join(settings.DJFS['url_root'], namespace, filename)) osfs = patch_fs(osfs, namespace, lambda self, filename, timeout=0:os.path.join(settings.DJFS['url_root'], namespace, filename))
return osfs return osfs
def get_s3fs(namespace): def get_s3fs(namespace):
...@@ -69,5 +72,15 @@ def get_s3fs(namespace): ...@@ -69,5 +72,15 @@ def get_s3fs(namespace):
if 'prefix' in settings.DJFS: if 'prefix' in settings.DJFS:
fullpath = os.path.join(settings.DJFS['prefix'], fullpath) fullpath = os.path.join(settings.DJFS['prefix'], fullpath)
s3fs = S3FS(settings.DJFS['bucket'], fullpath) s3fs = S3FS(settings.DJFS['bucket'], fullpath)
def get_s3_url(self, filename, timeout=60):
global s3conn
try:
return s3conn.generate_s3_url(timeout, 'GET', bucket = settings.DJFS['bucket'], key = filename)
except: # If connection has timed out
s3conn = S3Connection()
return s3conn.generate_s3_url(timeout, 'GET', bucket = settings.DJFS['bucket'], key = filename)
s3fs = patchfs(fs, namespace, get_s3_url)
return s3fs return s3fs
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment