mirror of https://github.com/tLDP/python-tldp
improving readability and simplicity
This commit is contained in:
parent
f9aa61fa32
commit
cc6caec3a4
|
@ -23,32 +23,45 @@ class Linuxdoc(BaseDoctype, SignatureChecker):
|
||||||
def platform_check(self):
|
def platform_check(self):
|
||||||
for tool in self.tools:
|
for tool in self.tools:
|
||||||
assert hasattr(self.platform, tool)
|
assert hasattr(self.platform, tool)
|
||||||
|
return True
|
||||||
|
|
||||||
def create_txt(self):
|
def create_txt(self):
|
||||||
logger.info("%s creating TXT.", self.source.stem)
|
exe = self.platform.html2text
|
||||||
cmd = [self.platform.html2text, '-style', 'pretty', '-nobs',
|
inf = self.output.name_htmls
|
||||||
self.output.name_htmls]
|
assert os.path.exists(inf)
|
||||||
stdout = open(self.output.name_txt, 'wx')
|
outf = self.output.name_txt
|
||||||
|
stem = self.source.stem
|
||||||
|
cmd = [exe, '-style', 'pretty', '-nobs', inf]
|
||||||
|
logger.debug("%s creating TXT %s.", stem, outf)
|
||||||
|
stdout = open(outf, 'wx')
|
||||||
result = execute(cmd, logdir=self.logdir, stdout=stdout)
|
result = execute(cmd, logdir=self.logdir, stdout=stdout)
|
||||||
if result == 0:
|
if result == 0:
|
||||||
return os.path.isfile(self.output.name_txt)
|
logger.info("%s created TXT %s.", stem, outf)
|
||||||
else:
|
return os.path.isfile(outf)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def create_pdf(self):
|
def create_pdf(self):
|
||||||
logger.info("%s creating PDF.", self.source.stem)
|
exe = self.platform.htmldoc
|
||||||
cmd = [self.platform.htmldoc, '--size', 'universal', '-t', 'pdf',
|
inf = self.output.name_htmls
|
||||||
'--firstpage', 'p1', '--outfile', self.output.name_pdf,
|
assert os.path.exists(inf)
|
||||||
self.output.name_htmls]
|
outf = self.output.name_pdf
|
||||||
|
stem = self.source.stem
|
||||||
|
logger.info("%s creating PDF %s.", stem, outf)
|
||||||
|
cmd = [exe, '--size', 'universal', '-t', 'pdf', '--firstpage', 'p1',
|
||||||
|
'--outfile', outf, inf]
|
||||||
result = execute(cmd, logdir=self.logdir)
|
result = execute(cmd, logdir=self.logdir)
|
||||||
if result == 0:
|
if result == 0:
|
||||||
return os.path.isfile(self.output.name_pdf)
|
logger.info("%s created PDF %s.", stem, outf)
|
||||||
else:
|
return os.path.isfile(outf)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def create_html(self):
|
def create_html(self):
|
||||||
|
exe = self.platform.sgml2html
|
||||||
|
inf = self.source.filename
|
||||||
|
assert os.path.exists(inf)
|
||||||
|
outf = self.output.name_html
|
||||||
stem = self.source.stem
|
stem = self.source.stem
|
||||||
logger.info("%s creating chunked HTML.", stem)
|
logger.info("%s creating chunked HTML %s, etc.", stem, outf)
|
||||||
cmd = [self.platform.sgml2html, self.source.filename]
|
cmd = [self.platform.sgml2html, self.source.filename]
|
||||||
result = execute(cmd, logdir=self.logdir)
|
result = execute(cmd, logdir=self.logdir)
|
||||||
if result == 0: # -- only symlink, if HTML generated successfully
|
if result == 0: # -- only symlink, if HTML generated successfully
|
||||||
|
@ -58,22 +71,26 @@ class Linuxdoc(BaseDoctype, SignatureChecker):
|
||||||
os.symlink(target, 'index.html')
|
os.symlink(target, 'index.html')
|
||||||
except OSError:
|
except OSError:
|
||||||
logger.debug("%s failed in creating index.html symlink.", stem)
|
logger.debug("%s failed in creating index.html symlink.", stem)
|
||||||
return os.path.isfile(self.output.name_html)
|
return os.path.isfile(outf)
|
||||||
|
|
||||||
def create_htmls(self):
|
def create_htmls(self):
|
||||||
|
exe = self.platform.sgml2html
|
||||||
|
inf = self.source.filename
|
||||||
|
assert os.path.exists(inf)
|
||||||
|
outf = self.output.name_htmls
|
||||||
stem = self.source.stem
|
stem = self.source.stem
|
||||||
logger.info("%s creating single-file HTML.", stem)
|
logger.info("%s creating single-file HTML %s, etc.", stem, outf)
|
||||||
cmd = [self.platform.sgml2html, '--split=0', self.source.filename]
|
cmd = [exe, '--split=0', inf]
|
||||||
result = execute(cmd, logdir=self.logdir)
|
result = execute(cmd, logdir=self.logdir)
|
||||||
logger.debug("%s result %r.", stem, result)
|
|
||||||
if result == 0: # -- only rename, if HTML generated successfully
|
if result == 0: # -- only rename, if HTML generated successfully
|
||||||
|
source = os.path.basename(self.output.name_html)
|
||||||
target = os.path.basename(self.output.name_htmls)
|
target = os.path.basename(self.output.name_htmls)
|
||||||
logger.debug("%s renaming HTML single file to %s.", stem, target)
|
logger.debug("%s renaming HTML single file to %s.", stem, target)
|
||||||
try:
|
try:
|
||||||
os.rename(self.output.name_html, self.output.name_htmls)
|
os.rename(source, target)
|
||||||
except OSError:
|
except OSError:
|
||||||
logger.debug("%s failed renaming HTML single file to %s.", stem, target)
|
logger.debug("%s failed renaming HTML single file to %s.", stem, target)
|
||||||
return os.path.isfile(self.output.name_htmls)
|
return os.path.isfile(outf)
|
||||||
|
|
||||||
#
|
#
|
||||||
# -- end of file
|
# -- end of file
|
||||||
|
|
Loading…
Reference in New Issue