add common execPythonScript method to rclexecm
This commit is contained in:
parent
32ebd65ba8
commit
d3de1f0d6f
@ -32,6 +32,7 @@ import cmdtalk
|
|||||||
|
|
||||||
PY3 = (sys.version > '3')
|
PY3 = (sys.version > '3')
|
||||||
_mswindows = (sys.platform == "win32")
|
_mswindows = (sys.platform == "win32")
|
||||||
|
_execdir = os.path.dirname(sys.argv[0])
|
||||||
|
|
||||||
# Convert to bytes if not already such.
|
# Convert to bytes if not already such.
|
||||||
def makebytes(data):
|
def makebytes(data):
|
||||||
@ -47,7 +48,7 @@ def subprocfile(fn):
|
|||||||
# to convert.
|
# to convert.
|
||||||
# On Unix all list elements get converted to bytes in the C
|
# On Unix all list elements get converted to bytes in the C
|
||||||
# _posixsubprocess module, nothing to do.
|
# _posixsubprocess module, nothing to do.
|
||||||
if PY3 and _mswindows:
|
if PY3 and _mswindows and type(fn) != type(''):
|
||||||
return fn.decode('UTF-8')
|
return fn.decode('UTF-8')
|
||||||
else:
|
else:
|
||||||
return fn
|
return fn
|
||||||
@ -239,6 +240,15 @@ def which(program):
|
|||||||
return candidate
|
return candidate
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
# Execute Python script. cmd is a list with the script name as first elt.
|
||||||
|
def execPythonScript(icmd):
|
||||||
|
import subprocess
|
||||||
|
cmd = list(icmd)
|
||||||
|
if _mswindows:
|
||||||
|
if not os.path.isabs(cmd[0]):
|
||||||
|
cmd[0] = os.path.join(_execdir, cmd[0])
|
||||||
|
cmd = [sys.executable] + cmd
|
||||||
|
return subprocess.check_output(cmd)
|
||||||
|
|
||||||
# Temp dir helper
|
# Temp dir helper
|
||||||
class SafeTmpDir:
|
class SafeTmpDir:
|
||||||
|
|||||||
@ -36,7 +36,6 @@ from hwp5.transforms import BaseTransform
|
|||||||
from hwp5.xmlmodel import Hwp5File as xml_Hwp5File
|
from hwp5.xmlmodel import Hwp5File as xml_Hwp5File
|
||||||
from hwp5.utils import cached_property
|
from hwp5.utils import cached_property
|
||||||
|
|
||||||
|
|
||||||
# Associate HTML meta names and hwp summaryinfo values
|
# Associate HTML meta names and hwp summaryinfo values
|
||||||
def metafields(summaryinfo):
|
def metafields(summaryinfo):
|
||||||
yield(('Description', summaryinfo.subject + " " +
|
yield(('Description', summaryinfo.subject + " " +
|
||||||
@ -49,8 +48,7 @@ def metafields(summaryinfo):
|
|||||||
# Extractor class. We use hwp summaryinfo to extract metadata and code
|
# Extractor class. We use hwp summaryinfo to extract metadata and code
|
||||||
# extracted from hwp.hwp5txt.py to extract the text.
|
# extracted from hwp.hwp5txt.py to extract the text.
|
||||||
class HWP5Dump(RclBaseHandler):
|
class HWP5Dump(RclBaseHandler):
|
||||||
def __init__(self, em, td):
|
def __init__(self, em):
|
||||||
self.execdir = td
|
|
||||||
super(HWP5Dump, self).__init__(em)
|
super(HWP5Dump, self).__init__(em)
|
||||||
|
|
||||||
def html_text(self, fn):
|
def html_text(self, fn):
|
||||||
@ -83,13 +81,9 @@ class HWP5Dump(RclBaseHandler):
|
|||||||
# the hwp5 module (no subproc). But this apparently mishandled
|
# the hwp5 module (no subproc). But this apparently mishandled
|
||||||
# tables. Switched to executing hwp5html instead. See 1st git
|
# tables. Switched to executing hwp5html instead. See 1st git
|
||||||
# version for the old approach.
|
# version for the old approach.
|
||||||
cmd = [sys.executable, os.path.join(self.execdir, "hwp5html"),
|
return rclexecm.execPythonScript(["hwp5html", "--html", fn])
|
||||||
"--html", fn]
|
|
||||||
html = subprocess.check_output(cmd)
|
|
||||||
return html
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
execdir = os.path.dirname(sys.argv[0])
|
|
||||||
proto = rclexecm.RclExecM()
|
proto = rclexecm.RclExecM()
|
||||||
extract = HWP5Dump(proto, execdir)
|
extract = HWP5Dump(proto)
|
||||||
rclexecm.main(proto, extract)
|
rclexecm.main(proto, extract)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user