From ca6fada2564ce40efd2d660755bf7c2f1c7cf006 Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Fri, 26 Nov 2010 12:33:44 +0200 Subject: [PATCH 1/2] convert.py: use the get_object_reference() API for ir.model.data Note that the "return False" would have never worked, since the _get_id() would have raised an exception for missing records. bzr revid: p_christ@hol.gr-20101126103344-ugr20dnti4gezdoe --- bin/tools/convert.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/bin/tools/convert.py b/bin/tools/convert.py index 1d050a832a4..3190335f4c2 100644 --- a/bin/tools/convert.py +++ b/bin/tools/convert.py @@ -830,11 +830,7 @@ form: module.record_id""" % (xml_id,) mod = self.module if '.' in id_str: mod,id_str = id_str.split('.') - result = model_data_obj._get_id(cr, self.uid, mod, id_str) - res = model_data_obj.read(cr, self.uid, [result], ['model', 'res_id']) - if res and res[0] and res[0]['res_id']: - return res[0]['model'], int(res[0]['res_id']) - return False + return model_data_obj.get_object_reference(cr, self.uid, mod, id_str) def parse(self, de): if not de.tag in ['terp', 'openerp']: From 7c55e521a3b6aa0e45599c67158cf392e57173ea Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Fri, 26 Nov 2010 12:34:59 +0200 Subject: [PATCH 2/2] customfonts: search path for fonts, override the broken of reportlab Several Linux distros still ship with a broken reportlab config, which looks at "c:\winnt\fonts" for fonts! Since they have not fixed that for months, we have to do their job and have a custom search path of: - paths from the config file (ttfonts.search_path key) - sensible defaults for distros, considering os.name and os.uname - default reportlab path (opt-out with ttfonts.use_default_path=False) The result is that we will have more chance of locating TTF fonts and use them (as now required) in the PDF reports. bzr revid: p_christ@hol.gr-20101126103459-5wv7crw3i3b56adr --- bin/report/render/rml2pdf/customfonts.py | 44 +++++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/bin/report/render/rml2pdf/customfonts.py b/bin/report/render/rml2pdf/customfonts.py index e4f15aa8d8b..5fbfe3b4e12 100644 --- a/bin/report/render/rml2pdf/customfonts.py +++ b/bin/report/render/rml2pdf/customfonts.py @@ -3,6 +3,7 @@ # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2009 P. Christeas, Tiny SPRL (). +# Copyright (C) 2010 OpenERP SA. (http://www.openerp.com) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -20,6 +21,8 @@ ############################################################################## from reportlab import rl_config +from tools import config +import glob import os import logging @@ -28,6 +31,9 @@ the reportlab engine. This file could be customized per distro (although most Linux/Unix ones) should have the same filenames, only need the code below). + +Due to an awful configuration that ships with reportlab at many Linux +and Ubuntu distros, we have to override the search path, too. """ CustomTTFonts = [ ('Helvetica',"DejaVu Sans", "DejaVuSans.ttf", 'normal'), @@ -51,6 +57,16 @@ CustomTTFonts = [ ('Helvetica',"DejaVu Sans", "DejaVuSans.ttf", 'normal'), ('Courier',"FreeMono Oblique", "FreeMonoOblique.ttf", 'italic'), ('Courier',"FreeMono BoldOblique", "FreeMonoBoldOblique.ttf", 'bolditalic'),] + +TTFSearchPath_Linux = ( + '/usr/share/fonts/truetype', # SuSE + '/usr/share/fonts/dejavu', '/usr/share/fonts/liberation', # Fedora, RHEL + '/usr/share/fonts/truetype/*', # Ubuntu, + '/usr/share/fonts/TTF/*', # at Mandriva/Mageia + ) + + +# ----- The code below is less distro-specific, please avoid editing! ------- __foundFonts = [] def FindCustomFonts(): @@ -64,10 +80,28 @@ def FindCustomFonts(): dirpath = [] log = logging.getLogger('report.fonts') global __foundFonts - for dirname in rl_config.TTFSearchPath: - abp = os.path.abspath(dirname) - if os.path.isdir(abp): - dirpath.append(abp) + searchpath = [] + + if config.get_misc('ttfonts', 'search_path', False): + searchpath += map(str.strip, config.get_misc('ttfonts', 'search_path').split(',')) + + if os.name == 'nt': + pass # TODO + elif os.uname()[0] == 'Linux': + searchpath += TTFSearchPath_Linux + else: + pass # TODO for MacOSX, Unix etc. + + if config.get_misc('ttfonts', 'use_default_path', True): + # Append the original search path of reportlab (at the end) + searchpath += rl_config.TTFSearchPath + + for dirglob in searchpath: + dirglob = os.path.expanduser(dirglob) + for dirname in glob.iglob(dirglob): + abp = os.path.abspath(dirname) + if os.path.isdir(abp): + dirpath.append(abp) for k, (name, font, fname, mode) in enumerate(CustomTTFonts): if fname in __foundFonts: @@ -77,7 +111,7 @@ def FindCustomFonts(): log.debug("Found font %s in %s as %s", fname, d, name) __foundFonts.append(fname) break - + # print "Found fonts:", __foundFonts