[FIX] tools: find_in_path: config is not ready at import time

commit f76d4525a was not actually working: extra keys from
config files are not yet into the config options dict at
import time. The fix is to move the logic inside the method,
like in `find_pg_tool` just below.

Also fix the use of `find_in_path` in report.py: the subprocess
may also raise AttributeError exception, so instead of listing
all the possible ones just re-raise the IOError shallowed by
`find_in_path` when the result is None.

Fixes #3809 #3811
This commit is contained in:
Simon Lejeune 2014-11-23 15:01:52 +01:00
parent 4617f665b9
commit 467968b79a
2 changed files with 9 additions and 7 deletions

View File

@ -49,7 +49,10 @@ from pyPdf import PdfFileWriter, PdfFileReader
_logger = logging.getLogger(__name__)
def _get_wkhtmltopdf_bin():
return find_in_path('wkhtmltopdf')
wkhtmltopdf_bin = find_in_path('wkhtmltopdf')
if wkhtmltopdf_bin is None:
raise IOError
return wkhtmltopdf_bin
#--------------------------------------------------------------------------
@ -60,7 +63,7 @@ try:
process = subprocess.Popen(
[_get_wkhtmltopdf_bin(), '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
except (OSError, IOError, ValueError):
except (OSError, IOError):
_logger.info('You need Wkhtmltopdf to print a pdf version of the reports.')
else:
_logger.info('Will use the Wkhtmltopdf binary at %s' % _get_wkhtmltopdf_bin())

View File

@ -65,13 +65,12 @@ _logger = logging.getLogger(__name__)
# We include the *Base ones just in case, currently they seem to be subclasses of the _* ones.
SKIPPED_ELEMENT_TYPES = (etree._Comment, etree._ProcessingInstruction, etree.CommentBase, etree.PIBase)
DEFAULT_PATH = os.environ.get('PATH', os.defpath).split(os.pathsep)
if config.get('bin_path'):
DEFAULT_PATH.append(config['bin_path'])
def find_in_path(name):
path = os.environ.get('PATH', os.defpath).split(os.pathsep)
if config.get('bin_path') and config['bin_path'] != 'None':
path.append(config['bin_path'])
try:
return which(name, path=os.pathsep.join(DEFAULT_PATH))
return which(name, path=os.pathsep.join(path))
except IOError:
return None