first working example of Linuxdoc processor

This commit is contained in:
Martin A. Brown 2016-02-15 14:04:09 -08:00
parent 73305ca97f
commit 61f2538927
1 changed files with 57 additions and 36 deletions

View File

@ -4,55 +4,76 @@ from __future__ import absolute_import, division, print_function
import os import os
from ..utils import logger from ..utils import logger, execute
from .common import SignatureChecker from .common import BaseDoctype, SignatureChecker
class Linuxdoc(SignatureChecker): class Linuxdoc(BaseDoctype, SignatureChecker):
formatname = 'Linuxdoc' formatname = 'Linuxdoc'
extensions = ['.sgml'] extensions = ['.sgml']
signatures = ['<!doctype linuxdoc system', ] signatures = ['<!doctype linuxdoc system', ]
tools = ['sgml2html', 'html2text', 'htmldoc'] tools = ['sgml2html', 'html2text', 'htmldoc']
def __init__(self, *args, **kwargs): # def __init__(self, *args, **kwargs):
self.source = kwargs.get('source') # self.source = kwargs.get('source')
self.output = kwargs.get('output') # self.output = kwargs.get('output')
super(Linuxdoc, self).__init__() # self.platform = kwargs.get('platform')
# super(Linuxdoc, self).__init__()
def platform_check(self):
for tool in self.tools:
assert hasattr(self.platform, tool)
def create_txt(self): def create_txt(self):
cmd = [self.html2text, '-style', 'pretty', '-nobs', logger.info("%s creating TXT.", self.source.stem)
self.output.htmls_name] cmd = [self.platform.html2text, '-style', 'pretty', '-nobs',
stdout = self.output.txt_name self.output.name_htmls]
stdout = open(self.output.name_txt, 'wx')
def create_pdf(self): result = execute(cmd, logdir=self.logdir, stdout=stdout)
logger.info("Creating PDF for %s", self.source.stem) if result == 0:
cmd = [self.htmldoc, '--size', 'universal', '-t', 'pdf', return os.path.isfile(self.output.name_txt)
'--firstpage', 'p1', '--outfile', self.output.pdf_name, else:
self.output.htmls_name]
def create_html(self):
logger.info("Creating chunked HTML for %s", self.source.stem)
cmd = [self.sgml2html, self.source.filename]
try:
# -- execute cmd
pass
except OSError:
return False return False
success = False def create_pdf(self):
try: logger.info("%s creating PDF.", self.source.stem)
opwd = os.getcwd() cmd = [self.platform.htmldoc, '--size', 'universal', '-t', 'pdf',
os.chdir(self.output.dirname) '--firstpage', 'p1', '--outfile', self.output.name_pdf,
os.symlink(os.path.basename(self.output.html_name), 'index.html') self.output.name_htmls]
os.chdir(opwd) result = execute(cmd, logdir=self.logdir)
success = True if result == 0:
except OSError: return os.path.isfile(self.output.name_pdf)
pass else:
return success return False
def create_html(self):
stem = self.source.stem
logger.info("%s creating chunked HTML.", stem)
cmd = [self.platform.sgml2html, self.source.filename]
result = execute(cmd, logdir=self.logdir)
if result == 0: # -- only symlink, if HTML generated successfully
target = os.path.basename(self.output.name_html)
logger.debug("%s creating index.html symlink to %s.", stem, target)
try:
os.symlink(target, 'index.html')
except OSError:
logger.debug("%s failed in creating index.html symlink.", stem)
return os.path.isfile(self.output.name_html)
def create_htmls(self): def create_htmls(self):
cmd = [self.sgml2html, '--split=0', self.source.filename] stem = self.source.stem
os.rename(self.output.html_name, self.output.htmls_name) logger.info("%s creating single-file HTML.", stem)
cmd = [self.platform.sgml2html, '--split=0', self.source.filename]
result = execute(cmd, logdir=self.logdir)
logger.debug("%s result %r.", stem, result)
if result == 0: # -- only rename, if HTML generated successfully
target = os.path.basename(self.output.name_htmls)
logger.debug("%s renaming HTML single file to %s.", stem, target)
try:
os.rename(self.output.name_html, self.output.name_htmls)
except OSError:
logger.debug("%s failed renaming HTML single file to %s.", stem, target)
return os.path.isfile(self.output.name_htmls)
# #
# -- end of file # -- end of file