diff options
author | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2010-12-05 00:04:16 +0000 |
---|---|---|
committer | willmcgugan <willmcgugan@67cdc799-7952-0410-af00-57a81ceafa0f> | 2010-12-05 00:04:16 +0000 |
commit | e72b070d2cf1b9dc42118d6eb48ce6c614c861e7 (patch) | |
tree | e6238eaa21181e62ec05b06e13722fe28302f3c4 /fs/wrapfs | |
parent | 800bcbc18feccd92e1f4e4b87f4f6706e96f08aa (diff) | |
download | pyfilesystem-e72b070d2cf1b9dc42118d6eb48ce6c614c861e7.tar.gz |
Added FS command line scripts
git-svn-id: http://pyfilesystem.googlecode.com/svn/trunk@537 67cdc799-7952-0410-af00-57a81ceafa0f
Diffstat (limited to 'fs/wrapfs')
-rw-r--r-- | fs/wrapfs/__init__.py | 12 | ||||
-rw-r--r-- | fs/wrapfs/debugfs.py | 19 | ||||
-rw-r--r-- | fs/wrapfs/lazyfs.py | 4 | ||||
-rw-r--r-- | fs/wrapfs/limitsizefs.py | 17 | ||||
-rw-r--r-- | fs/wrapfs/readonlyfs.py | 2 | ||||
-rw-r--r-- | fs/wrapfs/subfs.py | 14 |
6 files changed, 47 insertions, 21 deletions
diff --git a/fs/wrapfs/__init__.py b/fs/wrapfs/__init__.py index 0bb5c73..8172eec 100644 --- a/fs/wrapfs/__init__.py +++ b/fs/wrapfs/__init__.py @@ -144,6 +144,14 @@ class WrapFS(FS): return self._file_wrap(f, mode) @rewrite_errors + def setcontents(self, path, data, chunk_size=64*1024): + return self.wrapped_fs.setcontents(self._encode(path), data, chunk_size=chunk_size) + + @rewrite_errors + def createfile(self, path): + return self.wrapped_fs.createfile(self._encode(path)) + + @rewrite_errors def exists(self, path): return self.wrapped_fs.exists(self._encode(path)) @@ -156,7 +164,7 @@ class WrapFS(FS): return self.wrapped_fs.isfile(self._encode(path)) @rewrite_errors - def listdir(self, path="", **kwds): + def listdir(self, path="", **kwds): full = kwds.pop("full",False) absolute = kwds.pop("absolute",False) wildcard = kwds.pop("wildcard",None) @@ -325,6 +333,6 @@ def wrap_fs_methods(decorator, cls=None, exclude=[]): wrap_fs_methods.method_names = ["open","exists","isdir","isfile","listdir", "makedir","remove","setcontents","removedir","rename","getinfo","copy", "move","copydir","movedir","close","getxattr","setxattr","delxattr", - "listxattrs","getsyspath","createfile"] + "listxattrs","getsyspath","createfile", "hasmeta", "getmeta"] diff --git a/fs/wrapfs/debugfs.py b/fs/wrapfs/debugfs.py index 1b35eb3..03d66ee 100644 --- a/fs/wrapfs/debugfs.py +++ b/fs/wrapfs/debugfs.py @@ -45,16 +45,17 @@ logger.setLevel(logging.DEBUG) logger.addHandler(logging.StreamHandler())
class DebugFS(object):
- def __init__(self, fs, identifier=None, skip=()):
+ def __init__(self, fs, identifier=None, skip=(), verbose=True):
'''
fs - Reference to object to debug
identifier - Custom string-like object will be added
to each log line as identifier.
skip - list of method names which DebugFS should not log
- '''
+ '''
self.__wrapped_fs = fs
self.__identifier = identifier
- self.__skip = skip
+ self.__skip = skip
+ self.__verbose = verbose
super(DebugFS, self).__init__()
def __log(self, level, message):
@@ -65,8 +66,8 @@ class DebugFS(object): def __parse_param(self, value):
if isinstance(value, basestring):
- if len(value) > 20:
- value = "%s (length %d)" % (repr(value[:20]), len(value))
+ if len(value) > 60:
+ value = "%s ... (length %d)" % (repr(value[:60]), len(value))
else:
value = repr(value)
elif isinstance(value, list):
@@ -96,6 +97,7 @@ class DebugFS(object): self.__log(INFO, "%s %s%s -> %s" % (msg, str(key), args, value))
def __getattr__(self, key):
+
if key.startswith('__'):
# Internal calls, nothing interesting
return object.__getattribute__(self, key)
@@ -117,7 +119,7 @@ class DebugFS(object): def _method(*args, **kwargs):
try:
- value = attr(*args, **kwargs)
+ value = attr(*args, **kwargs)
self.__report("Call method", key, value, *args, **kwargs)
except FSError, e:
self.__log(ERROR, "Call method %s%s -> Exception %s: %s" % \
@@ -134,6 +136,7 @@ class DebugFS(object): raise e, None, tb
return value
- if key not in self.__skip:
- self.__log(DEBUG, "Asking for method %s" % key)
+ if self.__verbose:
+ if key not in self.__skip:
+ self.__log(DEBUG, "Asking for method %s" % key)
return _method
diff --git a/fs/wrapfs/lazyfs.py b/fs/wrapfs/lazyfs.py index bca6410..55a3dd5 100644 --- a/fs/wrapfs/lazyfs.py +++ b/fs/wrapfs/lazyfs.py @@ -88,8 +88,8 @@ class LazyFS(WrapFS): wrapped_fs = property(_get_wrapped_fs,_set_wrapped_fs) - def setcontents(self, path, data): - return self.wrapped_fs.setcontents(path, data) + def setcontents(self, path, data, chunk_size=64*1024): + return self.wrapped_fs.setcontents(path, data, chunk_size=chunk_size) def close(self): if not self.closed: diff --git a/fs/wrapfs/limitsizefs.py b/fs/wrapfs/limitsizefs.py index 01616c6..4c3b190 100644 --- a/fs/wrapfs/limitsizefs.py +++ b/fs/wrapfs/limitsizefs.py @@ -60,7 +60,22 @@ class LimitSizeFS(WrapFS): size = 0 self._file_sizes[path] = 0 return LimitSizeFile(self,path,f,mode,size) - + + def setcontents(self, path, data, chunk_size=64*1024): + f = None + try: + f = self.open(path, 'w') + if hasattr(data, 'read'): + chunk = data.read(chunk_size) + while chunk: + f.write(chunk) + chunk = data.read(chunk_size) + else: + f.write(data) + finally: + if f is not None: + f.close() + def _ensure_file_size(self, path, size, shrink=False): path = relpath(normpath(path)) with self._size_lock: diff --git a/fs/wrapfs/readonlyfs.py b/fs/wrapfs/readonlyfs.py index 61a1466..129bd65 100644 --- a/fs/wrapfs/readonlyfs.py +++ b/fs/wrapfs/readonlyfs.py @@ -59,3 +59,5 @@ class ReadOnlyFS(WrapFS): remove = _no_can_do removedir = _no_can_do settimes = _no_can_do + setcontents = _no_can_do + createfile = _no_can_do diff --git a/fs/wrapfs/subfs.py b/fs/wrapfs/subfs.py index 83d9da5..eddd614 100644 --- a/fs/wrapfs/subfs.py +++ b/fs/wrapfs/subfs.py @@ -38,15 +38,13 @@ class SubFS(WrapFS): def __repr__(self): return str(self) - def desc(self, path): - if self.isdir(path): - return "Sub dir of %s" % str(self.wrapped_fs) - else: - return "File in sub dir of %s" % str(self.wrapped_fs) - - def setcontents(self,path,contents): + def desc(self, path): + desc = "%s in sub dir %s of %s" % (path, self.sub_dir, str(self.wrapped_fs)) + return desc + + def setcontents(self, path, data, chunk_size=64*1024): path = self._encode(path) - return self.wrapped_fs.setcontents(path,contents) + return self.wrapped_fs.setcontents(path, data, chunk_size=chunk_size) def opendir(self, path): if not self.exists(path): |