# HG changeset patch # User Sylvain Thénault # Date 1269006429 -3600 # Node ID 03e083faefbf115301b7ccd2e84a343f8b6e0263 # Parent 26b2468a1e73870ce440f0f41de0c14ed3ee3e8b# Parent f32dcf3925d45ff6e0896ff9a11cfdbe1822684f backport stable diff -r 26b2468a1e73 -r 03e083faefbf utils.py --- a/utils.py Fri Mar 19 14:43:49 2010 +0100 +++ b/utils.py Fri Mar 19 14:47:09 2010 +0100 @@ -7,6 +7,7 @@ """ __docformat__ = "restructuredtext en" +import os import sys import decimal import datetime @@ -271,31 +272,34 @@ self.body.getvalue()) -def can_do_pdf_conversion(__answer=[None]): - """pdf conversion depends on - * pysixt (python package) - * fop 0.9x - """ - if __answer[0] is not None: - return __answer[0] +def _pdf_conversion_availability(): try: import pysixt except ImportError: - __answer[0] = False return False from subprocess import Popen, STDOUT - import os + if not os.path.isfile('/usr/bin/fop'): + return False try: Popen(['/usr/bin/fop', '-q'], stdout=open(os.devnull, 'w'), stderr=STDOUT) except OSError, e: - print e - __answer[0] = False + getLogger('cubicweb').info('fop not usable (%s)', e) return False - __answer[0] = True return True +def can_do_pdf_conversion(__answer_cache=[]): + """pdf conversion depends on + * pysixt (python package) + * fop 0.9x + + NOTE: actual check is done by _pdf_conversion_availability and + result is cached + """ + if not __answer_cache: # first time, not in cache + __answer_cache.append(_pdf_conversion_availability()) + return __answer_cache[0] try: # may not be there if cubicweb-web not installed diff -r 26b2468a1e73 -r 03e083faefbf web/views/basetemplates.py --- a/web/views/basetemplates.py Fri Mar 19 14:43:49 2010 +0100 +++ b/web/views/basetemplates.py Fri Mar 19 14:47:09 2010 +0100 @@ -270,7 +270,7 @@ if can_do_pdf_conversion(): try: - from xml.etree.cElementTree import ElementTree + from xml.etree.cElementTree import ElementTree except ImportError: #python2.4 from elementtree import ElementTree from subprocess import Popen as sub