diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2016-02-14 16:07:53 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2016-02-14 16:52:00 +0100 |
commit | 07d71c14e51e3333d2823bb0ea28b38af9c22949 (patch) | |
tree | 3d6898b5b76e546fb8356106bd28cc7120d9bffd | |
parent | 4875d6229f6d782e0767fa63811f8274cb292199 (diff) | |
download | fuse-httpfs-07d71c14e51e3333d2823bb0ea28b38af9c22949.tar.gz fuse-httpfs-07d71c14e51e3333d2823bb0ea28b38af9c22949.zip |
Use named logger
-rwxr-xr-x | fuse-httpfs | 14 | ||||
-rw-r--r-- | httpfs/__init__.py | 40 |
2 files changed, 29 insertions, 25 deletions
diff --git a/fuse-httpfs b/fuse-httpfs index e6a8c24..aa68cf6 100755 --- a/fuse-httpfs +++ b/fuse-httpfs @@ -3,7 +3,7 @@ import sys import fuse import logging import argparse -from httpfs import Config, Httpfs +import httpfs FORMAT = "%(threadName)s %(asctime)-15s %(levelname)s:%(name)s " + \ "%(filename)s:%(lineno)s %(message)s" @@ -28,15 +28,17 @@ p.add_argument("--system-ca", default="/etc/ssl/certs/ca-certificates.crt", args = vars(p.parse_args(sys.argv[1:])) -Config.timeout = args.pop("timeout") -Config.mountpoint = args.pop("mountpoint") -Config.verify = args.pop("ssl") -Config.system_ca = args.pop("system_ca") +httpfs.Config.timeout = args.pop("timeout") +httpfs.Config.mountpoint = args.pop("mountpoint") +httpfs.Config.verify = args.pop("ssl") +httpfs.Config.system_ca = args.pop("system_ca") kwargs = {} if not args.pop("no_foreground"): kwargs["foreground"] = True if args.pop("debug"): kwargs["debug"] = True + print(httpfs.__name__) + logging.getLogger(httpfs.__name__).setLevel(logging.DEBUG) kwargs.update(args) -fuse = fuse.FUSE(Httpfs(), Config.mountpoint, **kwargs) +fuse = fuse.FUSE(httpfs.Httpfs(), httpfs.Config.mountpoint, **kwargs) diff --git a/httpfs/__init__.py b/httpfs/__init__.py index 9a2d2c9..1b4ede3 100644 --- a/httpfs/__init__.py +++ b/httpfs/__init__.py @@ -13,6 +13,8 @@ import fuse import requests +logger = logging.getLogger(__name__) + class Config: mountpoint = None timeout = None @@ -41,7 +43,7 @@ class Path: if type(pathElement) == bytes: pathElement = pathElement.decode('utf-8') p = clazz(parent, unquote(pathElement)) - logging.info("created {} '{}' referencing {}".format( + logger.info("created {} '{}' referencing {}".format( clazz.__name__, p.name, p.buildUrl())) return p @@ -56,7 +58,7 @@ class File(Path): def init(self): url = self.buildUrl() - logging.info("File url={} name={}".format(url, self.name)) + logger.info("File url={} name={}".format(url, self.name)) r = self.getSession().head(url, timeout=Config.timeout, allow_redirects=True) r.close() @@ -72,7 +74,7 @@ class File(Path): self.size = int(r.headers['content-length']) self.lastModified = time.mktime(parsedate(r.headers['last-modified'])) - logging.info("File initialized url={} name={}".format(url, self.name)) + logger.info("File initialized url={} name={}".format(url, self.name)) self.initialized = True def get(self, size, offset): @@ -81,15 +83,15 @@ class File(Path): url = self.buildUrl() bytesRange = '{}-{}'.format(offset, min(self.size, offset + size - 1)) headers = {'range': 'bytes=' + bytesRange} - logging.info("File.get url={} range={}".format(url, bytesRange)) + logger.info("File.get url={} range={}".format(url, bytesRange)) r = self.getSession().get(url, headers=headers, timeout=Config.timeout) r.close() if r.status_code == 200 or r.status_code == 206: d = r.content - logging.info("Received {} bytes".format(len(d))) + logger.info("Received {} bytes".format(len(d))) if len(d) > size: errormsg = "size {} > than expected {}".format(len(d), size) - logging.error(errormsg) + logger.error(errormsg) raise fuse.FuseOSError(EIO) return d else: @@ -114,11 +116,11 @@ class Directory(Path): def init(self): url = self.buildUrl() + "/" - logging.info("Directory url={} name={}".format(url, self.name)) + logger.info("Directory url={} name={}".format(url, self.name)) r = self.getSession().get(url, stream=True, timeout=Config.timeout) if r.status_code >= 400 and r.status_code <= 499: self.mode = 0o000 - logging.info("Directory is 4xx {}".format(url)) + logger.info("Directory is 4xx {}".format(url)) r.close() self.initialized = True return @@ -138,7 +140,7 @@ class Directory(Path): self.entries.update(parser.entries) r.close() - logging.info("Diretory loaded {}".format(url)) + logger.info("Diretory loaded {}".format(url)) self.initialized = True def getAttr(self): @@ -162,7 +164,7 @@ class Server(Directory): elif Config.verify == "system": self.session.verify = Config.system_ca elif Config.verify == "none": - logging.warning("SSL Verification disabled!") + logger.warning("SSL Verification disabled!") self.session.verify = False else: raise SystemExit("Invalid value for ssl verification") @@ -236,23 +238,23 @@ class Httpfs(fuse.LoggingMixIn, fuse.Operations): for machine in netrc.netrc().hosts.keys(): yield (machine, Server(parent, machine)) except IOError as e: - logging.warning("No .netrc file found, no default machines") + logger.warning("No .netrc file found, no default machines") def getattr(self, path, fh=None): - logging.debug("getattr path={}".format(path)) + logger.debug("getattr path={}".format(path)) try: entry = self._getPath(path) if entry: return entry.getAttr() except Exception as e: - logging.exception("Error in getattr(%s)", path) + logger.exception("Error in getattr(%s)", path) raise fuse.FuseOSError(EHOSTUNREACH) raise fuse.FuseOSError(ENOENT) def _getPath(self, path): """ map path to self.root tree a path is build like /<schema>/<server hostname>/<http-path>""" - logging.debug("getPath path={}".format(path)) + logger.debug("getPath path={}".format(path)) if path == "/": return self.root @@ -261,7 +263,7 @@ class Httpfs(fuse.LoggingMixIn, fuse.Operations): schema, *p = path[1:].split("/") if schema not in self.root.entries: - logging.debug("schema %s not in root.entries", schema) + logger.debug("schema %s not in root.entries", schema) return None prevEntry = self.root.entries[schema] if p == []: @@ -293,18 +295,18 @@ class Httpfs(fuse.LoggingMixIn, fuse.Operations): r = d.getSession().head(url, timeout=Config.timeout, allow_redirects=True) if r.status_code == 200: - logging.info("Create directory for path: {} " + logger.info("Create directory for path: {} " "at: {}".format(path, url)) prevEntry.entries[lastElement] = d else: - logging.info("Path not found ({}): {} for {}".format( + logger.info("Path not found ({}): {} for {}".format( r.status_code, path, url)) return None return prevEntry.entries[lastElement] def readdir(self, path, fh): try: - logging.debug("readdir path=%s", path) + logger.debug("readdir path=%s", path) entry = self._getPath(path) if not entry: raise fuse.FuseOSError(EBADF) @@ -317,7 +319,7 @@ class Httpfs(fuse.LoggingMixIn, fuse.Operations): (it.name, it.getAttr(), 0) for it in entry.entries.values() ] except Exception as e: - logging.exception("Error in readdir(%s)", path) + logger.exception("Error in readdir(%s)", path) raise fuse.FuseOSError(EIO) def read(self, path, size, offset, fh): |