Commit 147a2b67 by rfkelly0

allow uniform use of logging throughout the module

parent 7ca85974
...@@ -45,3 +45,16 @@ import os ...@@ -45,3 +45,16 @@ import os
SEEK_CUR = os.SEEK_CUR SEEK_CUR = os.SEEK_CUR
SEEK_END = os.SEEK_END SEEK_END = os.SEEK_END
SEEK_SET = os.SEEK_SET SEEK_SET = os.SEEK_SET
# Allow clean use of logging throughout the lib
import logging as _logging
class _NullHandler(_logging.Handler):
def emit(self,record):
pass
_logging.getLogger("fs").addHandler(_NullHandler())
def getLogger(name):
"""Get a logger object for use within the pyfilesystem library."""
assert name.startswith("fs.")
return _logging.getLogger(name)
...@@ -94,4 +94,4 @@ def run(): ...@@ -94,4 +94,4 @@ def run():
return FSServe().run() return FSServe().run()
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(run()) sys.exit(run())
\ No newline at end of file
...@@ -31,6 +31,7 @@ import cookielib ...@@ -31,6 +31,7 @@ import cookielib
import fnmatch import fnmatch
import xml.dom.pulldom import xml.dom.pulldom
import fs
from fs.base import * from fs.base import *
from fs.path import * from fs.path import *
from fs.errors import * from fs.errors import *
...@@ -40,8 +41,7 @@ from fs.contrib.davfs.util import * ...@@ -40,8 +41,7 @@ from fs.contrib.davfs.util import *
from fs.contrib.davfs import xmlobj from fs.contrib.davfs import xmlobj
from fs.contrib.davfs.xmlobj import * from fs.contrib.davfs.xmlobj import *
import logging logger = fs.getLogger("fs.contrib.davfs")
logger = logging.getLogger("fs.contrib.davfs")
import errno import errno
_RETRYABLE_ERRORS = [errno.EADDRINUSE] _RETRYABLE_ERRORS = [errno.EADDRINUSE]
...@@ -236,7 +236,7 @@ class DAVFS(FS): ...@@ -236,7 +236,7 @@ class DAVFS(FS):
except KeyError: except KeyError:
msg = "unsupported protocol: '%s'" % (url.scheme,) msg = "unsupported protocol: '%s'" % (url.scheme,)
raise RemoteConnectionError(msg=msg) raise RemoteConnectionError(msg=msg)
#logger.debug("DAVFS >REQ %s %s/%s",method,url.hostname,url.path) logger.debug("DAVFS >REQ %s %s/%s",method,url.hostname,url.path)
con = ConClass(url.hostname,url.port,timeout=self.timeout) con = ConClass(url.hostname,url.port,timeout=self.timeout)
self._add_connection(con) self._add_connection(con)
try: try:
...@@ -257,11 +257,11 @@ class DAVFS(FS): ...@@ -257,11 +257,11 @@ class DAVFS(FS):
resp = con.getresponse() resp = con.getresponse()
self._cookiejar.extract_cookies(FakeResp(resp),FakeReq(con,url.scheme,url.path)) self._cookiejar.extract_cookies(FakeResp(resp),FakeReq(con,url.scheme,url.path))
except Exception, e: except Exception, e:
#logger.exception("DAVFS <ERR %s %s/%s",method,url.hostname,url.path) logger.exception("DAVFS <ERR %s %s/%s",method,url.hostname,url.path)
self._del_connection(con) self._del_connection(con)
raise raise
else: else:
#logger.debug("DAVFS <RESP %s %s %s/%s",resp.status,method,url.hostname,url.path) logger.debug("DAVFS <RESP %s %s %s/%s",resp.status,method,url.hostname,url.path)
old_close = resp.close old_close = resp.close
def new_close(): def new_close():
old_close() old_close()
......
...@@ -54,6 +54,7 @@ import stat as statinfo ...@@ -54,6 +54,7 @@ import stat as statinfo
import logging import logging
from logging import DEBUG, INFO, ERROR, CRITICAL from logging import DEBUG, INFO, ERROR, CRITICAL
import fs
import fs.errors as errors import fs.errors as errors
from fs.path import abspath, relpath, normpath, dirname, pathjoin from fs.path import abspath, relpath, normpath, dirname, pathjoin
from fs import FS, NullFile, _thread_synchronize_default, SEEK_END from fs import FS, NullFile, _thread_synchronize_default, SEEK_END
...@@ -63,7 +64,7 @@ from fs.base import fnmatch, NoDefaultMeta ...@@ -63,7 +64,7 @@ from fs.base import fnmatch, NoDefaultMeta
from util import TahoeUtil from util import TahoeUtil
from connection import Connection from connection import Connection
logger = logging.getLogger('fs.tahoefs') logger = fs.getLogger('fs.tahoefs')
def _fix_path(func): def _fix_path(func):
"""Method decorator for automatically normalising paths.""" """Method decorator for automatically normalising paths."""
......
...@@ -83,6 +83,10 @@ else: ...@@ -83,6 +83,10 @@ else:
from ctypes.wintypes import LPCWSTR, WCHAR from ctypes.wintypes import LPCWSTR, WCHAR
kernel32 = ctypes.windll.kernel32 kernel32 = ctypes.windll.kernel32
import logging
logger = logging.getLogger("fs.expose.dokan")
# Options controlling the behaiour of the Dokan filesystem # Options controlling the behaiour of the Dokan filesystem
DOKAN_OPTION_DEBUG = 1 DOKAN_OPTION_DEBUG = 1
DOKAN_OPTION_STDERR = 2 DOKAN_OPTION_STDERR = 2
...@@ -139,6 +143,7 @@ FILETIME_UNIX_EPOCH = 116444736000000000 ...@@ -139,6 +143,7 @@ FILETIME_UNIX_EPOCH = 116444736000000000
def _debug(*args): def _debug(*args):
#print >>sys.stderr, args; sys.stderr.flush() #print >>sys.stderr, args; sys.stderr.flush()
#logger.debug(map(str,args))
pass pass
......
...@@ -54,7 +54,10 @@ class DirMount(object): ...@@ -54,7 +54,10 @@ class DirMount(object):
self.fs = fs self.fs = fs
def __str__(self): def __str__(self):
return "Mount point: %s"%self.path return "Mount point: <%s,%s>" % (self.path,self.fs,)
__repr__ = __str__
def __unicode__(self):
return unicode(str(self))
class FileMount(object): class FileMount(object):
...@@ -83,7 +86,7 @@ class MountFS(FS): ...@@ -83,7 +86,7 @@ class MountFS(FS):
self.mount_tree = PathMap() self.mount_tree = PathMap()
def __str__(self): def __str__(self):
return "<MountFS>" return "<%s [%s]>" % (self.__class__.__name__,self.mount_tree.items(),)
__repr__ = __str__ __repr__ = __str__
......
...@@ -496,6 +496,9 @@ class PathMap(object): ...@@ -496,6 +496,9 @@ class PathMap(object):
for subk in self.iterkeys(k,subm): for subk in self.iterkeys(k,subm):
yield subk yield subk
def __iter__(self):
return self.iterkeys()
def keys(self,root="/"): def keys(self,root="/"):
return list(self.iterkeys(root)) return list(self.iterkeys(root))
...@@ -558,6 +561,7 @@ class PathMap(object): ...@@ -558,6 +561,7 @@ class PathMap(object):
def names(self,root="/"): def names(self,root="/"):
return list(self.iternames(root)) return list(self.iternames(root))
_wild_chars = frozenset('*?[]!{}') _wild_chars = frozenset('*?[]!{}')
def iswildcard(path): def iswildcard(path):
"""Check if a path ends with a wildcard """Check if a path ends with a wildcard
......
...@@ -39,9 +39,6 @@ from fs.local_functools import wraps ...@@ -39,9 +39,6 @@ from fs.local_functools import wraps
from fs.filelike import StringIO, SpooledTemporaryFile, FileWrapper from fs.filelike import StringIO, SpooledTemporaryFile, FileWrapper
from fs import SEEK_SET, SEEK_CUR, SEEK_END from fs import SEEK_SET, SEEK_CUR, SEEK_END
import logging
logger = logging.getLogger("fs.remote")
_SENTINAL = object() _SENTINAL = object()
...@@ -595,9 +592,7 @@ class CacheFSMixin(WrapFS): ...@@ -595,9 +592,7 @@ class CacheFSMixin(WrapFS):
if not ci.has_full_info: if not ci.has_full_info:
raise KeyError raise KeyError
info = ci.info info = ci.info
logger.debug("GOT INFO FROM CACHE: %r",path)
except KeyError: except KeyError:
logger.debug("INFO WASN'T IN CACHE: %r",path)
info = super(CacheFSMixin,self).getinfo(path) info = super(CacheFSMixin,self).getinfo(path)
self.__set_cached_info(path,CachedInfo(info)) self.__set_cached_info(path,CachedInfo(info))
return info return info
......
...@@ -466,6 +466,7 @@ def wrap_fs_methods(decorator, cls=None, exclude=[]): ...@@ -466,6 +466,7 @@ def wrap_fs_methods(decorator, cls=None, exclude=[]):
wrap_fs_methods.method_names = ["open","exists","isdir","isfile","listdir", wrap_fs_methods.method_names = ["open","exists","isdir","isfile","listdir",
"makedir","remove","setcontents","removedir","rename","getinfo","copy", "makedir","remove","setcontents","removedir","rename","getinfo","copy",
"move","copydir","movedir","close","getxattr","setxattr","delxattr", "move","copydir","movedir","close","getxattr","setxattr","delxattr",
"listxattrs","getsyspath","createfile", "hasmeta", "getmeta"] "listxattrs","getsyspath","createfile", "hasmeta", "getmeta","listdirinfo",
"ilistdir","ilistdirinfo"]
...@@ -38,9 +38,10 @@ import logging ...@@ -38,9 +38,10 @@ import logging
from logging import DEBUG, INFO, ERROR, CRITICAL from logging import DEBUG, INFO, ERROR, CRITICAL
import sys import sys
import fs
from fs.errors import FSError from fs.errors import FSError
logger = logging.getLogger('fs.debugfs') logger = fs.getLogger('fs.debugfs')
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler()) logger.addHandler(logging.StreamHandler())
......
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