diff options
author | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2010-12-12 00:23:08 +0000 |
---|---|---|
committer | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2010-12-12 00:23:08 +0000 |
commit | 019606859f92428fb3936b4ff73331044c281655 (patch) | |
tree | 61b2acdea8192e330d19cbc7cbd804e4a36480a3 | |
parent | ae7768bf6756a21bdfc4748018efeb024adc938d (diff) | |
download | pyfilesystem-019606859f92428fb3936b4ff73331044c281655.tar.gz |
Command fixes
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@548 67cdc799-7952-0410-af00-57a81ceafa0f
-rw-r--r-- | fs/base.py | 2 | ||||
-rw-r--r-- | fs/commands/fscp.py | 2 | ||||
-rw-r--r-- | fs/commands/fsmkdir.py | 5 | ||||
-rw-r--r-- | fs/commands/fsmv.py | 2 | ||||
-rw-r--r-- | fs/commands/fsrm.py | 2 | ||||
-rw-r--r-- | fs/commands/fsserve.py | 7 | ||||
-rw-r--r-- | fs/commands/fstree.py | 2 | ||||
-rw-r--r-- | fs/commands/runner.py | 6 | ||||
-rw-r--r-- | fs/opener.py | 56 | ||||
-rw-r--r-- | fs/osfs/__init__.py | 2 | ||||
-rw-r--r-- | fs/rpcfs.py | 17 | ||||
-rw-r--r-- | fs/utils.py | 15 | ||||
-rw-r--r-- | fs/wrapfs/__init__.py | 7 | ||||
-rw-r--r-- | fs/wrapfs/subfs.py | 6 |
14 files changed, 65 insertions, 66 deletions
@@ -649,6 +649,8 @@ class FS(object): :rtype: An FS object """ + if path in ('', '/'): + return self from fs.wrapfs.subfs import SubFS if not self.exists(path): raise ResourceNotFoundError(path) diff --git a/fs/commands/fscp.py b/fs/commands/fscp.py index 1e30bc3..05ddd71 100644 --- a/fs/commands/fscp.py +++ b/fs/commands/fscp.py @@ -124,7 +124,7 @@ Copy SOURCE to DESTINATION""" self.total_files = len(copy_fs_paths) self.done_files = 0 - file_queue = queue.Queue() + file_queue = queue.Queue() threads = [FileOpThread(self.get_action(), 'T%i' % i, dst_fs, diff --git a/fs/commands/fsmkdir.py b/fs/commands/fsmkdir.py index d5a5729..32c6bd3 100644 --- a/fs/commands/fsmkdir.py +++ b/fs/commands/fsmkdir.py @@ -13,8 +13,9 @@ Make a directory""" def do_run(self, options, args): - for fs_url in args: - fs, path = self.open_fs(fs_url, create=True) + for fs_url in args: + fs, path = self.open_fs(fs_url, create=True) + print fs, path def run(): return FSMkdir().run() diff --git a/fs/commands/fsmv.py b/fs/commands/fsmv.py index 06b1828..a03b339 100644 --- a/fs/commands/fsmv.py +++ b/fs/commands/fsmv.py @@ -2,7 +2,7 @@ from fs.utils import movefile, contains_files from fs.commands import fscp import sys -class FSMove(fscp.FSCopy): +class FSMove(fscp.FScp): usage = """fsmv [OPTION]... [SOURCE] [DESTINATION] Move files from SOURCE to DESTINATION""" diff --git a/fs/commands/fsrm.py b/fs/commands/fsrm.py index 833555d..5e2bd09 100644 --- a/fs/commands/fsrm.py +++ b/fs/commands/fsrm.py @@ -25,7 +25,7 @@ Remove a file or directory at PATH""" interactive = options.interactive verbose = options.verbose - for fs, path, is_dir in self.get_resources(args): + for fs, path, is_dir in self.get_resources(args): if interactive: if is_dir: msg = "remove directory '%s'?" % path diff --git a/fs/commands/fsserve.py b/fs/commands/fsserve.py index 10b4b9f..c1a0c2d 100644 --- a/fs/commands/fsserve.py +++ b/fs/commands/fsserve.py @@ -29,6 +29,13 @@ Serves the contents of PATH with one of a number of methods""" fs_url = './' fs, path = self.open_fs(fs_url) + + if fs.isdir(path): + fs = fs.opendir(path) + path = '/' + + if options.verbose: + print "Serving \"%s\" in %s" % (path, fs) port = options.port diff --git a/fs/commands/fstree.py b/fs/commands/fstree.py index 9ef440c..166612c 100644 --- a/fs/commands/fstree.py +++ b/fs/commands/fstree.py @@ -13,7 +13,7 @@ Recursively display the contents of PATH in an ascii tree""" def get_optparse(self): optparse = super(FSTree, self).get_optparse() - optparse.add_option('-L', '--level', dest='depth', type="int", default=5, + optparse.add_option('-l', '--level', dest='depth', type="int", default=5, help="Descend only LEVEL directories deep", metavar="LEVEL") optparse.add_option('-a', '--all', dest='all', action='store_true', default=False, help="do not hide dot files") diff --git a/fs/commands/runner.py b/fs/commands/runner.py index 8a27b1a..f57cded 100644 --- a/fs/commands/runner.py +++ b/fs/commands/runner.py @@ -221,13 +221,11 @@ class Command(object): except KeyboardInterrupt: if self.is_terminal(): self.output("\n") - return 0 - #except ValueError: - # pass + return 0 except SystemExit: return 0 except Exception, e: - self.error(self.wrap_error('Internal Error - %s\n' % unicode(e))) + self.error(self.wrap_error('Error - %s\n' % unicode(e))) return 1 diff --git a/fs/opener.py b/fs/opener.py index 0111834..9a78ecd 100644 --- a/fs/opener.py +++ b/fs/opener.py @@ -79,7 +79,7 @@ class OpenerRegistry(object): for name in opener.names: self.registry[name] = index - def parse(self, fs_url, default_fs_name=None, writeable=False, create=False): + def parse(self, fs_url, default_fs_name=None, open_dir=True, writeable=False, create=False): orig_url = fs_url match = self.split_segments(fs_url) @@ -110,27 +110,27 @@ class OpenerRegistry(object): if fs_url is None: raise OpenerError("Unable to parse '%s'" % orig_url) - #wildcard = None - #if iswildcard(fs_url): - # fs_url, wildcard = pathsplit(fs_url) fs, fs_path = opener.get_fs(self, fs_name, fs_name_params, fs_url, writeable, create) - pathname, resourcename = pathsplit(fs_path or '') - if pathname: - fs = fs.opendir(pathname) - fs_path = resourcename - if fs_path and iswildcard(fs_path): - return fs, fs_path - + pathname, resourcename = pathsplit(fs_path or '') + if pathname: + fs = fs.opendir(pathname) + return fs, resourcename + + #pathname, resourcename = pathsplit(fs_path or '') + #if pathname and resourcename: + # fs = fs.opendir(pathname) + # fs_path = resourcename + fs_path = join(fs_path, path) - - pathname, resourcename = pathsplit(fs_path or '') - if pathname: + + pathname, resourcename = pathsplit(fs_path or '') + if pathname and resourcename: fs = fs.opendir(pathname) fs_path = resourcename - + return fs, fs_path def parse_credentials(self, url): @@ -180,17 +180,12 @@ class OSFSOpener(Opener): from fs.osfs import OSFS path = _expand_syspath(fs_path) - if create: - from fs.osfs import _os_makedirs - _os_makedirs(fs_path) - if os.path.isdir(path): - osfs = OSFS(path) - filepath = None - else: - path, filepath = pathsplit(path) - osfs = OSFS(path, create=create) - return osfs, filepath - + if create and not os.path.exists(path): + from fs.osfs import _os_makedirs + _os_makedirs(path) + dirname, resourcename = pathsplit(fs_path) + osfs = OSFS(dirname) + return osfs, resourcename class ZipOpener(Opener): names = ['zip', 'zip64'] @@ -210,8 +205,7 @@ class ZipOpener(Opener): else: open_mode = 'rb' - zip_file = zip_fs.open(zip_path, mode=open_mode) - + zip_file = zip_fs.open(zip_path, mode=open_mode) username, password, fs_path = registry.parse_credentials(fs_path) @@ -251,7 +245,7 @@ class RPCOpener(Opener): if create and path: rpcfs.makedir(path, recursive=True, allow_recreate=True) - + return rpcfs, path or None @@ -387,7 +381,9 @@ opener = OpenerRegistry([OSFSOpener, def main(): - fs, path = opener.parse('zip:zip://~/zips.zip!t.zip!') + #fs, path = opener.parse('zip:zip://~/zips.zip!t.zip!') + fs, path = opener.parse('rpc://127.0.0.1/a/*.JPG') + print fs, path if __name__ == "__main__": diff --git a/fs/osfs/__init__.py b/fs/osfs/__init__.py index 779f96a..6622e04 100644 --- a/fs/osfs/__init__.py +++ b/fs/osfs/__init__.py @@ -230,7 +230,7 @@ class OSFS(OSFSXAttrMixin, OSFSWatchMixin, FS): @convert_os_errors def remove(self, path): sys_path = self.getsyspath(path) - try: + try: os.remove(sys_path) except OSError, e: if e.errno == errno.EACCES and sys.platform == "win32": diff --git a/fs/rpcfs.py b/fs/rpcfs.py index cbd7500..5eb6082 100644 --- a/fs/rpcfs.py +++ b/fs/rpcfs.py @@ -27,21 +27,18 @@ def re_raise_faults(func): #import traceback #traceback.print_exc() # Make sure it's in a form we can handle - bits = f.faultString.split(" ") + bits = f.faultString.split(" ") if bits[0] not in ["<type","<class"]: raise f # Find the class/type object bits = " ".join(bits[1:]).split(">:") - cls = bits[0] - msg = ">:".join(bits[1:]) - while cls[0] in ["'",'"']: - cls = cls[1:] - while cls[-1] in ["'",'"']: - cls = cls[:-1] + cls = bits[0] + msg = ">:".join(bits[1:]) + cls = cls.strip('\'') cls = _object_by_name(cls) # Re-raise using the remainder of the fault code as message - if cls: - raise cls(msg) + if cls: + raise cls(msg=msg) raise f except socket.error, e: raise RemoteConnectionError(str(e), details=e) @@ -210,7 +207,7 @@ class RPCFS(FS): path = self.encode_path(path) return self.proxy.isfile(path) - def listdir(self, path="./", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False): + def listdir(self, path="./", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False): path = self.encode_path(path) entries = self.proxy.listdir(path,wildcard,full,absolute,dirs_only,files_only) return [self.decode_path(e) for e in entries] diff --git a/fs/utils.py b/fs/utils.py index f55babb..af47c35 100644 --- a/fs/utils.py +++ b/fs/utils.py @@ -56,10 +56,7 @@ def copyfile(src_fs, src_path, dst_fs, dst_path, overwrite=True, chunk_size=64*1 src = None try: # Chunk copy - if src_fs.getsize(src_path) < chunk_size: - src = src_fs.getcontents(src_path) - else: - src = src_fs.open(src_path, 'rb') + src = src_fs.open(src_path, 'rb') dst_fs.setcontents(dst_path, src, chunk_size=chunk_size) finally: if src is not None and hasattr(src, 'close'): @@ -92,19 +89,15 @@ def movefile(src_fs, src_path, dst_fs, dst_path, overwrite=True, chunk_size=64*1 FS._shutil_movefile(src_syspath, dst_syspath) return - src = None try: # Chunk copy - if src_fs.getsize(src_path) < chunk_size: - src = src_fs.getcontents(src_path) - else: - src = src_fs.open(src_path, 'rb') - dst_fs.setcontents(dst_path, src, chunk_size=chunk_size) - src_fs.remove(src_path) + src = src_fs.open(src_path, 'rb') + dst_fs.setcontents(dst_path, src, chunk_size=chunk_size) finally: if src is not None and hasattr(src, 'close'): src.close() + src_fs.remove(src_path) def movedir(fs1, fs2, overwrite=False, ignore_errors=False, chunk_size=64*1024): """Moves contents of a directory from one filesystem to another. diff --git a/fs/wrapfs/__init__.py b/fs/wrapfs/__init__.py index 8172eec..760a601 100644 --- a/fs/wrapfs/__init__.py +++ b/fs/wrapfs/__init__.py @@ -164,7 +164,12 @@ class WrapFS(FS): return self.wrapped_fs.isfile(self._encode(path)) @rewrite_errors - def listdir(self, path="", **kwds): + def listdir(self, path="", wildcard=None, full=False, absolute=False, dirs_only=False, files_only=False): + kwds = dict(wildcard=wildcard, + full=full, + absolute=absolute, + dirs_only=dirs_only, + files_only=files_only) full = kwds.pop("full",False) absolute = kwds.pop("absolute",False) wildcard = kwds.pop("wildcard",None) diff --git a/fs/wrapfs/subfs.py b/fs/wrapfs/subfs.py index eddd614..314b108 100644 --- a/fs/wrapfs/subfs.py +++ b/fs/wrapfs/subfs.py @@ -30,16 +30,16 @@ class SubFS(WrapFS): return abspath(normpath(path))[len(self.sub_dir):] def __str__(self): - return "<SubFS: %s in %s>" % (self.sub_dir, self.wrapped_fs) + return "%s/%s" % (self.wrapped_fs, self.sub_dir.lstrip('/')) def __unicode__(self): - return u"<SubFS: %s in %s>" % (self.sub_dir, self.wrapped_fs) + return u"%s/%s" % (self.wrapped_fs, self.sub_dir.lstrip('/')) def __repr__(self): return str(self) def desc(self, path): - desc = "%s in sub dir %s of %s" % (path, self.sub_dir, str(self.wrapped_fs)) + desc = "%s!%s" % (str(self), path) return desc def setcontents(self, path, data, chunk_size=64*1024): |