mirror of https://github.com/tLDP/python-tldp
use arg_ checking functions; add build_precheck
rename platform_check to build_precheck refer to arg_ checking functions from utils ensure that just before each build we validate executables avoid FD leakage by using with ... context for outf (stdout)
This commit is contained in:
parent
11834a17cc
commit
1475cf7890
|
@ -5,18 +5,19 @@ from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from ..utils import logger, which, execute
|
from tldp.utils import logger, which, execute
|
||||||
from .common import BaseDoctype, SignatureChecker
|
from tldp.utils import arg_isexecutable, isexecutable
|
||||||
|
from tldp.doctypes.common import BaseDoctype, SignatureChecker
|
||||||
|
|
||||||
|
|
||||||
def config_fragment(p):
|
def config_fragment(p):
|
||||||
p.add_argument('--linuxdoc-sgml2html', type=str,
|
p.add_argument('--linuxdoc-sgml2html', type=arg_isexecutable,
|
||||||
default=which('sgml2html'),
|
default=which('sgml2html'),
|
||||||
help='full path to sgml2html [%(default)s]')
|
help='full path to sgml2html [%(default)s]')
|
||||||
p.add_argument('--linuxdoc-html2text', type=str,
|
p.add_argument('--linuxdoc-html2text', type=arg_isexecutable,
|
||||||
default=which('html2text'),
|
default=which('html2text'),
|
||||||
help='full path to html2text [%(default)s]')
|
help='full path to html2text [%(default)s]')
|
||||||
p.add_argument('--linuxdoc-htmldoc', type=str,
|
p.add_argument('--linuxdoc-htmldoc', type=arg_isexecutable,
|
||||||
default=which('htmldoc'),
|
default=which('htmldoc'),
|
||||||
help='full path to htmldoc [%(default)s]')
|
help='full path to htmldoc [%(default)s]')
|
||||||
|
|
||||||
|
@ -25,16 +26,21 @@ class Linuxdoc(BaseDoctype, SignatureChecker):
|
||||||
formatname = 'Linuxdoc'
|
formatname = 'Linuxdoc'
|
||||||
extensions = ['.sgml']
|
extensions = ['.sgml']
|
||||||
signatures = ['<!doctype linuxdoc system', ]
|
signatures = ['<!doctype linuxdoc system', ]
|
||||||
tools = ['sgml2html', 'html2text', 'htmldoc']
|
|
||||||
|
|
||||||
def platform_check(self):
|
required = {'linuxdoc_sgml2html': isexecutable,
|
||||||
for tool in self.tools:
|
'linuxdoc_html2text': isexecutable,
|
||||||
assert hasattr(self.platform, tool)
|
'linuxdoc_htmldoc': isexecutable,
|
||||||
assert isexecutable(getattr(self.platform, tool))
|
}
|
||||||
|
|
||||||
|
def build_precheck(self):
|
||||||
|
for tool, validator in self.required.items():
|
||||||
|
thing = getattr(self.config, tool, None)
|
||||||
|
assert thing is not None
|
||||||
|
assert validator(thing)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def create_txt(self):
|
def create_txt(self):
|
||||||
exe = self.platform.html2text
|
exe = self.config.linuxdoc_html2text
|
||||||
inf = self.output.name_htmls
|
inf = self.output.name_htmls
|
||||||
assert os.path.exists(inf)
|
assert os.path.exists(inf)
|
||||||
outf = self.output.name_txt
|
outf = self.output.name_txt
|
||||||
|
@ -42,15 +48,15 @@ class Linuxdoc(BaseDoctype, SignatureChecker):
|
||||||
logdir = self.output.logdir
|
logdir = self.output.logdir
|
||||||
cmd = [exe, '-style', 'pretty', '-nobs', inf]
|
cmd = [exe, '-style', 'pretty', '-nobs', inf]
|
||||||
logger.debug("%s creating TXT %s.", stem, outf)
|
logger.debug("%s creating TXT %s.", stem, outf)
|
||||||
stdout = open(outf, 'wx')
|
with open(outf, 'wx') as stdout:
|
||||||
result = execute(cmd, logdir=logdir, stdout=stdout)
|
result = execute(cmd, logdir=logdir, stdout=stdout)
|
||||||
if result != 0:
|
if result != 0:
|
||||||
return False
|
return False
|
||||||
logger.info("%s created TXT %s.", stem, outf)
|
logger.info("%s created TXT %s.", stem, outf)
|
||||||
return os.path.isfile(outf)
|
return os.path.isfile(outf)
|
||||||
|
|
||||||
def create_pdf(self):
|
def create_pdf(self):
|
||||||
exe = self.platform.htmldoc
|
exe = self.config.linuxdoc_htmldoc
|
||||||
inf = self.output.name_htmls
|
inf = self.output.name_htmls
|
||||||
assert os.path.exists(inf)
|
assert os.path.exists(inf)
|
||||||
outf = self.output.name_pdf
|
outf = self.output.name_pdf
|
||||||
|
@ -66,7 +72,7 @@ class Linuxdoc(BaseDoctype, SignatureChecker):
|
||||||
return os.path.isfile(outf)
|
return os.path.isfile(outf)
|
||||||
|
|
||||||
def create_html(self):
|
def create_html(self):
|
||||||
exe = self.platform.sgml2html
|
exe = self.config.linuxdoc_sgml2html
|
||||||
inf = self.source.filename
|
inf = self.source.filename
|
||||||
assert os.path.exists(inf)
|
assert os.path.exists(inf)
|
||||||
outf = self.output.name_html
|
outf = self.output.name_html
|
||||||
|
@ -86,7 +92,7 @@ class Linuxdoc(BaseDoctype, SignatureChecker):
|
||||||
return os.path.isfile(outf)
|
return os.path.isfile(outf)
|
||||||
|
|
||||||
def create_htmls(self):
|
def create_htmls(self):
|
||||||
exe = self.platform.sgml2html
|
exe = self.config.linuxdoc_sgml2html
|
||||||
inf = self.source.filename
|
inf = self.source.filename
|
||||||
assert os.path.exists(inf)
|
assert os.path.exists(inf)
|
||||||
outf = self.output.name_htmls
|
outf = self.output.name_htmls
|
||||||
|
|
Loading…
Reference in New Issue