Commit c638a2e9 by willmcgugan

Opener fixes

parent 929c9603
...@@ -9,6 +9,7 @@ from fs.base import FS ...@@ -9,6 +9,7 @@ from fs.base import FS
from fs.path import normpath from fs.path import normpath
from fs.errors import ResourceNotFoundError, UnsupportedError from fs.errors import ResourceNotFoundError, UnsupportedError
from urllib2 import urlopen, URLError from urllib2 import urlopen, URLError
from fs.filelike import FileWrapper
class HTTPFS(FS): class HTTPFS(FS):
...@@ -20,6 +21,9 @@ class HTTPFS(FS): ...@@ -20,6 +21,9 @@ class HTTPFS(FS):
""" """
_meta = {'read_only':True,
'network':True,}
def __init__(self, url): def __init__(self, url):
""" """
...@@ -46,7 +50,7 @@ class HTTPFS(FS): ...@@ -46,7 +50,7 @@ class HTTPFS(FS):
except OSError, e: except OSError, e:
raise ResourceNotFoundError(path, details=e) raise ResourceNotFoundError(path, details=e)
return f return FileWrapper(f)
def exists(self, path): def exists(self, path):
return self.isfile(path) return self.isfile(path)
......
...@@ -62,11 +62,10 @@ you can always access them directly. ...@@ -62,11 +62,10 @@ you can always access them directly.
""" """
from fs.base import FS, FSError, synchronize from fs.base import FS, synchronize
from fs.path import * from fs.path import *
from fs.errors import * from fs.errors import *
from fs import _thread_synchronize_default from fs import _thread_synchronize_default
from fs.errors import ResourceNotFoundError
class MultiFS(FS): class MultiFS(FS):
...@@ -234,7 +233,7 @@ class MultiFS(FS): ...@@ -234,7 +233,7 @@ class MultiFS(FS):
for fs in self: for fs in self:
try: try:
paths += fs.listdir(path, *args, **kwargs) paths += fs.listdir(path, *args, **kwargs)
except FSError, e: except FSError:
pass pass
return list(set(paths)) return list(set(paths))
...@@ -254,16 +253,14 @@ class MultiFS(FS): ...@@ -254,16 +253,14 @@ class MultiFS(FS):
@synchronize @synchronize
def rename(self, src, dst): def rename(self, src, dst):
if self.writefs is None: if self.writefs is None:
raise OperationFailedError('rename', path=path, msg="No writeable FS set") raise OperationFailedError('rename', path=src, msg="No writeable FS set")
self.writefs.rename(src, dst) self.writefs.rename(src, dst)
raise ResourceNotFoundError(path)
@synchronize @synchronize
def settimes(self, path, accessed_time=None, modified_time=None): def settimes(self, path, accessed_time=None, modified_time=None):
if self.writefs is None: if self.writefs is None:
raise OperationFailedError('settimes', path=path, msg="No writeable FS set") raise OperationFailedError('settimes', path=path, msg="No writeable FS set")
self.writefs.settimes(path, accessed_time, modified_time) self.writefs.settimes(path, accessed_time, modified_time)
raise ResourceNotFoundError(path)
@synchronize @synchronize
def getinfo(self, path): def getinfo(self, path):
......
...@@ -231,6 +231,7 @@ class OpenerRegistry(object): ...@@ -231,6 +231,7 @@ class OpenerRegistry(object):
fs_path = join(fs_path, path) fs_path = join(fs_path, path)
if create_dir and fs_path: if create_dir and fs_path:
if not fs.getmeta('read_only', False):
fs.makedir(fs_path, allow_recreate=True) fs.makedir(fs_path, allow_recreate=True)
pathname, resourcename = pathsplit(fs_path or '') pathname, resourcename = pathsplit(fs_path or '')
...@@ -659,7 +660,7 @@ example: ...@@ -659,7 +660,7 @@ example:
def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create_dir): def get_fs(cls, registry, fs_name, fs_name_params, fs_path, writeable, create_dir):
from fs.httpfs import HTTPFS from fs.httpfs import HTTPFS
if '/' in fs_path: if '/' in fs_path:
dirname, resourcename = fs_path.rsplit('/') dirname, resourcename = fs_path.rsplit('/', 1)
else: else:
dirname = fs_path dirname = fs_path
resourcename = '' resourcename = ''
...@@ -796,7 +797,7 @@ example: ...@@ -796,7 +797,7 @@ example:
mount_fs = MountFS() mount_fs = MountFS()
for mount_point, mount_path in cfg.items(section): for mount_point, mount_path in cfg.items(section):
mount_fs.mount(mount_point, registry.opendir(mount_path)) mount_fs.mount(mount_point, registry.opendir(mount_path, create_dir=create_dir))
return mount_fs, '' return mount_fs, ''
...@@ -832,7 +833,7 @@ example: ...@@ -832,7 +833,7 @@ example:
multi_fs = MultiFS() multi_fs = MultiFS()
for name, fs_url in cfg.items(section): for name, fs_url in cfg.items(section):
multi_fs.addfs(name, registry.opendir(fs_url)) multi_fs.addfs(name, registry.opendir(fs_url, create_dir=create_dir))
return multi_fs, '' return multi_fs, ''
......
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