CHM handler: bundle pychm for Python3

This commit is contained in:
Jean-Francois Dockes
2018-06-01 14:52:12 +02:00
parent dae381f49b
commit 29e63aeda1
18 changed files with 7135 additions and 8 deletions
+18 -5
View File
@@ -1,12 +1,9 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
"""Extract Html files from a Microsoft Compiled Html Help file (.chm)
Needs at least python 2.2 for HTMLParser (chmlib needs 2.2 too)"""
from __future__ import print_function
# Note: this is not converted to Py3, libchm does not have a
# Py3 wrapper at this point (2018-03)
rclchm_html_mtype = "text/html"
import sys
@@ -18,16 +15,32 @@ if PY3:
from urllib.parse import unquote as urllib_unquote
from urllib.parse import urlparse as urlparse_urlparse
from html.parser import HTMLParser
chmpackname = 'pychm3.egg'
else:
from urlparse import urlparse as urlparse_urlparse
from urllib import unquote as urllib_unquote
from HTMLParser import HTMLParser
chmpackname = 'pychm2.egg'
import subprocess
import rclconfig
import rclexecm
# pychm has no official port to Python3, hence no package in the
# standard place. Recoll bundles a python3 port which we install out
# of the standard python places. Look for it:
# sys.path[0] is for MSW, where we install the egg in the filters
# directory? TBD for now
try:
# First try the system version if any
from chm import chm,chmlib
except:
for d in ('sys.path[0]', '/usr/lib/recoll', '/usr/local/lib/recoll'):
p = os.path.join(d, chmpackname)
if os.path.exists(p):
sys.path.append(p)
break
try:
from chm import chm,chmlib
except: