[IMP] openerp.report: _logger with fully qualified module name.

bzr revid: vmt@openerp.com-20120124125512-2bjh1xpzcgvz1nrp
This commit is contained in:
Vo Minh Thu 2012-01-24 13:55:12 +01:00
parent f22f2fc770
commit 15a4d4e19e
5 changed files with 28 additions and 23 deletions

View File

@ -29,7 +29,8 @@ try:
from PIL import Image
except ImportError:
import logging
logging.warning('Python Imaging not installed, you can use only .JPG pictures !')
_logger = logging.getLogger(__name__)
_logger.warning('Python Imaging not installed, you can use only .JPG pictures !')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -40,6 +40,8 @@ Due to an awful configuration that ships with reportlab at many Linux
and Ubuntu distros, we have to override the search path, too.
"""
_logger = logging.getLogger(__name__)
CustomTTFonts = [ ('Helvetica',"DejaVu Sans", "DejaVuSans.ttf", 'normal'),
('Helvetica',"DejaVu Sans Bold", "DejaVuSans-Bold.ttf", 'bold'),
('Helvetica',"DejaVu Sans Oblique", "DejaVuSans-Oblique.ttf", 'italic'),
@ -97,7 +99,6 @@ def FindCustomFonts():
meanwhile, the server must be restarted eventually.
"""
dirpath = []
log = logging.getLogger('report.fonts')
global __foundFonts
__foundFonts = {}
searchpath = []
@ -127,7 +128,7 @@ def FindCustomFonts():
for d in dirpath:
abs_filename = os.path.join(d, filename)
if os.path.exists(abs_filename):
log.debug("Found font %s at %s", filename, abs_filename)
_logger.debug("Found font %s at %s", filename, abs_filename)
__foundFonts[filename] = abs_filename
break

View File

@ -39,13 +39,14 @@ from openerp.tools.misc import file_open
from reportlab.pdfbase import pdfmetrics
from reportlab.lib.pagesizes import A4, letter
try:
from cStringIO import StringIO
_hush_pyflakes = [ StringIO ]
except ImportError:
from StringIO import StringIO
_logger = logging.getLogger(__name__)
encoding = 'utf-8'
def _open_image(filename, path=None):
@ -328,7 +329,6 @@ class _rml_canvas(object):
self.images = images
self.path = path
self.title = title
self._logger = logging.getLogger('report.rml.canvas')
if self.title:
self.canvas.setTitle(self.title)
@ -452,7 +452,7 @@ class _rml_canvas(object):
if not nfile:
if node.get('name'):
image_data = self.images[node.get('name')]
self._logger.debug("Image %s used", node.get('name'))
_logger.debug("Image %s used", node.get('name'))
s = StringIO(image_data)
else:
newtext = node.text
@ -466,7 +466,7 @@ class _rml_canvas(object):
if image_data:
s = StringIO(image_data)
else:
self._logger.debug("No image data!")
_logger.debug("No image data!")
return False
else:
if nfile in self.images:
@ -479,16 +479,16 @@ class _rml_canvas(object):
if up and up.scheme:
# RFC: do we really want to open external URLs?
# Are we safe from cross-site scripting or attacks?
self._logger.debug("Retrieve image from %s", nfile)
_logger.debug("Retrieve image from %s", nfile)
u = urllib.urlopen(str(nfile))
s = StringIO(u.read())
else:
self._logger.debug("Open image file %s ", nfile)
_logger.debug("Open image file %s ", nfile)
s = _open_image(nfile, path=self.path)
try:
img = ImageReader(s)
(sx,sy) = img.getSize()
self._logger.debug("Image is %dx%d", sx, sy)
_logger.debug("Image is %dx%d", sx, sy)
args = { 'x': 0.0, 'y': 0.0 }
for tag in ('width','height','x','y'):
if node.get(tag):
@ -540,7 +540,7 @@ class _rml_canvas(object):
try:
pdfmetrics.getFont(fontname)
except Exception:
logging.getLogger('report.fonts').debug('Could not locate font %s, substituting default: %s',
_logger.debug('Could not locate font %s, substituting default: %s',
fontname,
self.canvas._fontname)
fontname = self.canvas._fontname
@ -613,7 +613,6 @@ class _rml_flowable(object):
self.images = images
self.path = path
self.title = title
self._logger = logging.getLogger('report.rml.flowable')
def _textual(self, node):
rc1 = utils._process_text(self, node.text or '')
@ -753,7 +752,7 @@ class _rml_flowable(object):
from reportlab.graphics.barcode import createBarcodeDrawing
except ImportError:
self._logger.warning("Cannot use barcode renderers:", exc_info=True)
_logger.warning("Cannot use barcode renderers:", exc_info=True)
return None
args = utils.attr_get(node, [], {'ratio':'float','xdim':'unit','height':'unit','checksum':'int','quiet':'int','width':'unit','stop':'bool','bearers':'int','barWidth':'float','barHeight':'float'})
codes = {
@ -801,10 +800,10 @@ class _rml_flowable(object):
if not node.get('file'):
if node.get('name'):
if node.get('name') in self.doc.images:
self._logger.debug("Image %s read ", node.get('name'))
_logger.debug("Image %s read ", node.get('name'))
image_data = self.doc.images[node.get('name')].read()
else:
self._logger.warning("Image %s not defined", node.get('name'))
_logger.warning("Image %s not defined", node.get('name'))
return False
else:
import base64
@ -813,11 +812,11 @@ class _rml_flowable(object):
newtext = utils._process_text(self, node.text or '')
image_data = base64.decodestring(newtext)
if not image_data:
self._logger.debug("No inline image data")
_logger.debug("No inline image data")
return False
image = StringIO(image_data)
else:
self._logger.debug("Image get from file %s", node.get('file'))
_logger.debug("Image get from file %s", node.get('file'))
image = _open_image(node.get('file'), path=self.doc.path)
return platypus.Image(image, mask=(250,255,250,255,250,255), **(utils.attr_get(node, ['width','height'])))
elif node.tag=='spacer':
@ -980,7 +979,7 @@ def parseNode(rml, localcontext=None, fout=None, images=None, path='.', title=No
# means there is no custom fonts mapping in this system.
pass
except Exception:
logging.getLogger('report').warning('Cannot set font mapping', exc_info=True)
_logger.warning('Cannot set font mapping', exc_info=True)
pass
fp = StringIO()
r.render(fp)

View File

@ -47,6 +47,8 @@ import openerp.tools as tools
from openerp.tools.safe_eval import safe_eval as eval
from openerp.tools.misc import ustr
_logger = logging.getLogger(__name__)
_regex = re.compile('\[\[(.+?)\]\]')
def str2xml(s):
@ -68,7 +70,7 @@ def _child_get(node, self=None, tagname=None):
except GeneratorExit:
continue
except Exception, e:
logging.getLogger('report').warning('rml_except: "%s"',n.get('rml_except',''), exc_info=True)
_logger.warning('rml_except: "%s"', n.get('rml_except',''), exc_info=True)
continue
if n.get('rml_tag'):
try:
@ -80,7 +82,7 @@ def _child_get(node, self=None, tagname=None):
except GeneratorExit:
yield n
except Exception, e:
logging.getLogger('report').warning('rml_tag: "%s"',n.get('rml_tag',''), exc_info=True)
_logger.warning('rml_tag: "%s"', n.get('rml_tag',''), exc_info=True)
yield n
else:
yield n
@ -91,7 +93,7 @@ def _child_get(node, self=None, tagname=None):
except GeneratorExit:
continue
except Exception, e:
logging.getLogger('report').warning('rml_except: "%s"',n.get('rml_except',''), exc_info=True)
_logger.warning('rml_except: "%s"', n.get('rml_except',''), exc_info=True)
continue
if self and self.localcontext and n.get('rml_tag'):
try:
@ -104,7 +106,7 @@ def _child_get(node, self=None, tagname=None):
except GeneratorExit:
pass
except Exception, e:
logging.getLogger('report').warning('rml_tag: "%s"',n.get('rml_tag',''), exc_info=True)
_logger.warning('rml_tag: "%s"', n.get('rml_tag',''), exc_info=True)
pass
if (tagname is None) or (n.tag==tagname):
yield n

View File

@ -37,6 +37,8 @@ from openerp.osv.fields import float as float_class, function as function_class
from openerp.osv.orm import browse_record
from openerp.tools.translate import _
_logger = logging.getLogger(__name__)
DT_FORMAT = '%Y-%m-%d'
DHM_FORMAT = '%Y-%m-%d %H:%M:%S'
HM_FORMAT = '%H:%M:%S'
@ -483,7 +485,7 @@ class report_sxw(report_rml, preprocess.report):
)
except Exception:
#TODO: should probably raise a proper osv_except instead, shouldn't we? see LP bug #325632
logging.getLogger('report').error('Could not create saved report attachment', exc_info=True)
_logger.error('Could not create saved report attachment', exc_info=True)
results.append(result)
if results:
if results[0][1]=='pdf':