2016-02-11 03:22:23 +00:00
|
|
|
#! /usr/bin/python
|
2016-02-18 21:25:02 +00:00
|
|
|
# -*- coding: utf8 -*-
|
2016-04-29 15:02:02 +00:00
|
|
|
#
|
|
|
|
# Copyright (c) 2016 Linux Documentation Project
|
2016-02-11 03:22:23 +00:00
|
|
|
|
2016-02-11 19:29:23 +00:00
|
|
|
from __future__ import absolute_import, division, print_function
|
2016-03-15 05:18:09 +00:00
|
|
|
from __future__ import unicode_literals
|
2016-02-11 17:15:50 +00:00
|
|
|
|
2016-02-25 19:37:14 +00:00
|
|
|
import logging
|
2016-02-11 17:15:50 +00:00
|
|
|
|
2016-02-26 09:02:16 +00:00
|
|
|
from tldp.utils import which
|
2016-02-23 19:05:28 +00:00
|
|
|
from tldp.utils import arg_isexecutable, isexecutable
|
2016-02-26 09:02:16 +00:00
|
|
|
from tldp.doctypes.common import BaseDoctype, SignatureChecker, depends
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
2016-02-11 03:22:23 +00:00
|
|
|
|
|
|
|
|
2016-02-15 22:04:09 +00:00
|
|
|
class Linuxdoc(BaseDoctype, SignatureChecker):
|
2016-02-12 20:49:50 +00:00
|
|
|
formatname = 'Linuxdoc'
|
2016-02-11 03:22:23 +00:00
|
|
|
extensions = ['.sgml']
|
|
|
|
signatures = ['<!doctype linuxdoc system', ]
|
|
|
|
|
2016-02-23 19:05:28 +00:00
|
|
|
required = {'linuxdoc_sgml2html': isexecutable,
|
2016-03-13 16:41:55 +00:00
|
|
|
'linuxdoc_sgmlcheck': isexecutable,
|
2016-02-23 19:05:28 +00:00
|
|
|
'linuxdoc_html2text': isexecutable,
|
|
|
|
'linuxdoc_htmldoc': isexecutable,
|
|
|
|
}
|
|
|
|
|
2016-03-13 16:41:55 +00:00
|
|
|
def validate_source(self, **kwargs):
|
|
|
|
s = '"{config.linuxdoc_sgmlcheck}" "{source.filename}"'
|
|
|
|
return self.shellscript(s, **kwargs)
|
|
|
|
|
|
|
|
@depends(validate_source)
|
2016-03-10 02:08:56 +00:00
|
|
|
def make_htmls(self, **kwargs):
|
2016-02-26 09:02:16 +00:00
|
|
|
'''create a single page HTML output (with incorrect name)'''
|
|
|
|
s = '"{config.linuxdoc_sgml2html}" --split=0 "{source.filename}"'
|
2016-03-10 02:08:56 +00:00
|
|
|
return self.shellscript(s, **kwargs)
|
2016-02-26 09:02:16 +00:00
|
|
|
|
2016-03-06 01:08:33 +00:00
|
|
|
@depends(make_htmls)
|
2016-03-10 02:08:56 +00:00
|
|
|
def make_name_htmls(self, **kwargs):
|
2016-02-26 09:02:16 +00:00
|
|
|
'''correct the single page HTML output name'''
|
|
|
|
s = 'mv -v --no-clobber -- "{output.name_html}" "{output.name_htmls}"'
|
2016-03-10 02:08:56 +00:00
|
|
|
return self.shellscript(s, **kwargs)
|
2016-02-26 09:02:16 +00:00
|
|
|
|
2016-03-06 01:08:33 +00:00
|
|
|
@depends(make_name_htmls)
|
2016-03-10 02:08:56 +00:00
|
|
|
def make_name_txt(self, **kwargs):
|
2016-02-26 09:02:16 +00:00
|
|
|
'''create text output (from single-page HTML)'''
|
|
|
|
s = '''"{config.linuxdoc_html2text}" > "{output.name_txt}" \\
|
|
|
|
-style pretty \\
|
|
|
|
-nobs \\
|
|
|
|
"{output.name_htmls}"'''
|
2016-03-10 02:08:56 +00:00
|
|
|
return self.shellscript(s, **kwargs)
|
2016-02-26 09:02:16 +00:00
|
|
|
|
2016-03-06 01:08:33 +00:00
|
|
|
@depends(make_name_htmls)
|
2016-03-10 02:08:56 +00:00
|
|
|
def make_name_pdf(self, **kwargs):
|
2016-02-26 09:02:16 +00:00
|
|
|
s = '''"{config.linuxdoc_htmldoc}" \\
|
|
|
|
--size universal \\
|
|
|
|
--firstpage p1 \\
|
2016-02-27 06:18:02 +00:00
|
|
|
--format pdf \\
|
2016-03-16 23:12:25 +00:00
|
|
|
--footer c.1 \\
|
2016-02-26 09:02:16 +00:00
|
|
|
--outfile "{output.name_pdf}" \\
|
|
|
|
"{output.name_htmls}"'''
|
2016-03-10 02:08:56 +00:00
|
|
|
return self.shellscript(s, **kwargs)
|
2016-02-26 09:02:16 +00:00
|
|
|
|
2016-03-06 01:08:33 +00:00
|
|
|
@depends(make_name_htmls)
|
2016-03-10 02:08:56 +00:00
|
|
|
def make_name_html(self, **kwargs):
|
2016-03-13 16:41:55 +00:00
|
|
|
'''create chunked output'''
|
2016-02-26 09:02:16 +00:00
|
|
|
s = '"{config.linuxdoc_sgml2html}" "{source.filename}"'
|
2016-03-10 02:08:56 +00:00
|
|
|
return self.shellscript(s, **kwargs)
|
2016-02-26 09:02:16 +00:00
|
|
|
|
2016-03-06 01:08:33 +00:00
|
|
|
@depends(make_name_html)
|
2016-03-10 02:08:56 +00:00
|
|
|
def make_name_indexhtml(self, **kwargs):
|
2016-02-26 09:02:16 +00:00
|
|
|
'''create final index.html symlink'''
|
|
|
|
s = 'ln -svr -- "{output.name_html}" "{output.name_indexhtml}"'
|
2016-03-10 02:08:56 +00:00
|
|
|
return self.shellscript(s, **kwargs)
|
2016-02-11 03:22:23 +00:00
|
|
|
|
2016-02-27 17:45:32 +00:00
|
|
|
@classmethod
|
|
|
|
def argparse(cls, p):
|
|
|
|
descrip = 'executables and data files for %s' % (cls.formatname,)
|
|
|
|
g = p.add_argument_group(title=cls.__name__, description=descrip)
|
2016-03-13 16:41:55 +00:00
|
|
|
g.add_argument('--linuxdoc-sgmlcheck', type=arg_isexecutable,
|
|
|
|
default=which('sgmlcheck'),
|
|
|
|
help='full path to sgmlcheck [%(default)s]')
|
2016-02-27 17:45:32 +00:00
|
|
|
g.add_argument('--linuxdoc-sgml2html', type=arg_isexecutable,
|
2016-02-25 18:35:46 +00:00
|
|
|
default=which('sgml2html'),
|
|
|
|
help='full path to sgml2html [%(default)s]')
|
2016-02-27 17:45:32 +00:00
|
|
|
g.add_argument('--linuxdoc-html2text', type=arg_isexecutable,
|
2016-02-25 18:35:46 +00:00
|
|
|
default=which('html2text'),
|
|
|
|
help='full path to html2text [%(default)s]')
|
2016-02-27 17:45:32 +00:00
|
|
|
g.add_argument('--linuxdoc-htmldoc', type=arg_isexecutable,
|
2016-02-25 18:35:46 +00:00
|
|
|
default=which('htmldoc'),
|
|
|
|
help='full path to htmldoc [%(default)s]')
|
|
|
|
|
2016-02-11 03:22:23 +00:00
|
|
|
#
|
|
|
|
# -- end of file
|