我的服务器上安装了多个版本的wkhtmltopdf
库。我希望能够在我即将渲染它们时以编程方式在它们之间切换,因为我们有几个开发团队并且他们使用不同版本的wkhtmltopdf
。不同的wkhtmltopdf
版本提供完全不同的渲染结果,这很奇怪。是否可以通过编程方式在它们之间切换?
答案 0 :(得分:0)
这不是一个完整的代码,但我尝试这种类型的代码可能适合你:
import os
from openerp import tools # this odoo config file master/openerp/tools/which.py
import subprocess
import logging
_logger = logging.getLogger(__name__)
def find_in_path(name):
path = os.environ.get('PATH', os.defpath).split(os.pathsep)
if tools.config.get('bin_path') and tools.config['bin_path'] != 'None':
path.append(tools.config['bin_path'])
return tools.which(name, path=os.pathsep.join(path))
def _get_wkhtmltopdf_bin():
return find_in_path('wkhtmltopdf')
wkhtmltopdf_state = 'install'
try:
process = subprocess.Popen(
[_get_wkhtmltopdf_bin(), '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
print "prrrrrrrrrrrrrrrr", process.communicate()[0]
# here write your logic
#
#
#
#
except (OSError, IOError):
_logger.info('You need Wkhtmltopdf to print a pdf version of the reports.')