From cfd0ae1f9084cbd1bf989d9eb75150c37d1b4b52 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 2 Mar 2010 10:43:49 +0100 Subject: [PATCH] [fix] document: remove hacky reimplementation of netsvc, replace netsvc calls with logging calls bzr revid: xmo@tinyerp.com-20100302094349-jdzhmtn23rdfqi83 --- addons/document/content_index.py | 42 ++++++++++---------------------- 1 file changed, 13 insertions(+), 29 deletions(-) diff --git a/addons/document/content_index.py b/addons/document/content_index.py index 17928b43873..9fc0023e833 100644 --- a/addons/document/content_index.py +++ b/addons/document/content_index.py @@ -18,28 +18,10 @@ # along with this program. If not, see . # ############################################################################## +import logging import os import tempfile -# A quick hack: if netsvc is not there, emulate it. Thus, work offline, too -try: - import netsvc - def log(lvl,msg): - netsvc.Logger().notifyChannel("index",lvl,msg) -except: - class netsvc: - LOG_NOTSET = 'notset' - LOG_DEBUG_RPC = 'debug_rpc' - LOG_DEBUG = 'debug' - LOG_INFO = 'info' - LOG_WARNING = 'warn' - LOG_ERROR = 'error' - LOG_CRITICAL = 'critical' - - def log(lvl,msg): - print msg - - class NhException(Exception): pass @@ -129,7 +111,8 @@ def mime_match(mime, mdict): return (None, None) -class contentIndex() : +class contentIndex(): + __logger = logging.getLogger('addons.document.content_index') def __init__(self): self.mimes = {} self.exts = {} @@ -145,7 +128,7 @@ class contentIndex() : f = True if f: - log(netsvc.LOG_DEBUG, "Register content indexer: %r" % obj) + self.__logger.debug('Register content indexer: %s', obj) if not f: raise Exception("Your indexer should at least suport a mimetype or extension") @@ -179,30 +162,31 @@ class contentIndex() : result = fp.read() fp.close() mime2 = result.strip() - log(netsvc.LOG_DEBUG,"File gave us: %s" % mime2) + self.__logger.debug('File gave us: %s', mime2) # Note that the temporary file still exists now. mime,fobj = mime_match(mime2, self.mimes) if not mime: mime = mime2 - except Exception, e: - log(netsvc.LOG_WARNING,"Cannot determine mime type: %s" % str(e)) + except Exception: + self.__logger.exception('Cannot determine mime type') try: if fobj: res = (mime, fobj.indexContent(content,filename,fname or realfname) ) else: - log(netsvc.LOG_DEBUG,"Have no object, return (%s, None)" % mime) + self.__logger.debug("Have no object, return (%s, None)", mime) res = (mime, None ) - except Exception, e: - log(netsvc.LOG_WARNING,"Could not index file, %s" % e) + except Exception: + self.__logger.exception("Could not index file %s (%s)", + filename, fname or realfname) res = None # If we created a tmp file, unlink it now if not realfname and fname: try: os.unlink(fname) - except Exception, e: - log(netsvc.LOG_WARNING,"Could not unlink %s, %s" %(fname, e)) + except Exception: + self.__logger.exception("Could not unlink %s", fname) return res