use newer, simpler topo-sort for dependency tracking

This commit is contained in:
Martin A. Brown 2016-03-05 17:08:33 -08:00
parent 4c01ae4af7
commit 760cd392f4
5 changed files with 53 additions and 69 deletions

View File

@ -5,7 +5,6 @@ from __future__ import absolute_import, division, print_function
import os
import logging
import networkx as nx
from tldp.utils import which
from tldp.utils import arg_isexecutable, isexecutable
@ -25,13 +24,11 @@ class Asciidoc(BaseDoctype):
'asciidoc_a2x': isexecutable,
}
graph = nx.DiGraph()
def chdir_output(self):
os.chdir(self.output.dirname)
return True
@depends(graph, chdir_output)
@depends(chdir_output)
def copy_static_resources(self):
source = list()
for d in ('images', 'resources'):
@ -46,7 +43,7 @@ class Asciidoc(BaseDoctype):
s = 'rsync --archive --verbose %s ./' % (' '.join(source))
return self.shellscript(s)
@depends(graph, chdir_output)
@depends(chdir_output)
def make_name_pdf(self):
s = '''"{config.asciidoc_a2x}" \\
--verbose \\
@ -55,12 +52,12 @@ class Asciidoc(BaseDoctype):
"{source.filename}"'''
return self.shellscript(s)
@depends(graph, chdir_output)
@depends(chdir_output)
def make_name_txt(self):
s = 'cp --verbose --target-directory . -- "{source.filename}"'
return self.shellscript(s)
@depends(graph, chdir_output)
@depends(chdir_output)
def make_name_htmls(self):
s = '''"{config.asciidoc_a2x}" \\
--verbose \\
@ -69,7 +66,7 @@ class Asciidoc(BaseDoctype):
"{source.filename}"'''
return self.shellscript(s)
@depends(graph, chdir_output)
@depends(chdir_output)
def make_chunked_html(self):
s = '''"{config.asciidoc_a2x}" \\
--verbose \\
@ -78,12 +75,12 @@ class Asciidoc(BaseDoctype):
"{source.filename}"'''
return self.shellscript(s)
@depends(graph, make_chunked_html)
@depends(make_chunked_html)
def move_chunked_html(self):
s = 'mv --no-clobber -v -- "{output.stem}.chunked" html'
return self.shellscript(s)
@depends(graph, move_chunked_html)
@depends(move_chunked_html)
def make_name_html(self):
s = 'ln -sv --relative -- html/index.html {output.name_indexhtml}'
return self.shellscript(s)

View File

@ -5,7 +5,6 @@ from __future__ import absolute_import, division, print_function
import os
import logging
import networkx as nx
from tldp.utils import which, firstfoundfile
from tldp.utils import arg_isexecutable, isexecutable
@ -52,13 +51,11 @@ class Docbook4XML(BaseDoctype, SignatureChecker):
'docbook4xml_xslprint': isreadablefile,
}
graph = nx.DiGraph()
def chdir_output(self):
os.chdir(self.output.dirname)
return True
@depends(graph, chdir_output)
@depends(chdir_output)
def make_validated_source(self):
s = '''"{config.docbook4xml_xmllint}" > "{output.validsource}" \\
--nonet \\
@ -68,7 +65,7 @@ class Docbook4XML(BaseDoctype, SignatureChecker):
"{source.filename}"'''
return self.shellscript(s)
@depends(graph, make_validated_source)
@depends(make_validated_source)
def copy_static_resources(self):
source = list()
for d in ('images', 'resources'):
@ -83,7 +80,7 @@ class Docbook4XML(BaseDoctype, SignatureChecker):
s = 'rsync --archive --verbose %s ./' % (' '.join(source))
return self.shellscript(s)
@depends(graph, copy_static_resources)
@depends(copy_static_resources)
def make_name_htmls(self):
'''create a single page HTML output'''
s = '''"{config.docbook4xml_xsltproc}" > "{output.name_htmls}" \\
@ -94,7 +91,7 @@ class Docbook4XML(BaseDoctype, SignatureChecker):
"{output.validsource}"'''
return self.shellscript(s)
@depends(graph, make_name_htmls)
@depends(make_name_htmls)
def make_name_txt(self):
'''create text output'''
s = '''"{config.docbook4xml_html2text}" > "{output.name_txt}" \\
@ -103,7 +100,7 @@ class Docbook4XML(BaseDoctype, SignatureChecker):
"{output.name_htmls}"'''
return self.shellscript(s)
@depends(graph, copy_static_resources)
@depends(copy_static_resources)
def make_fo(self):
'''generate the Formatting Objects intermediate output'''
s = '''"{config.docbook4xml_xsltproc}" > "{output.name_fo}" \\
@ -113,7 +110,7 @@ class Docbook4XML(BaseDoctype, SignatureChecker):
return self.shellscript(s)
# -- this is conditionally built--see logic in make_name_pdf() below
# @depends(graph, make_fo)
# @depends(make_fo)
def make_pdf_with_fop(self):
'''use FOP to create a PDF'''
s = '''"{config.docbook4xml_fop}" \\
@ -122,7 +119,7 @@ class Docbook4XML(BaseDoctype, SignatureChecker):
return self.shellscript(s)
# -- this is conditionally built--see logic in make_name_pdf() below
# @depends(graph, chdir_output)
# @depends(chdir_output)
def make_pdf_with_dblatex(self):
'''use dblatex (fallback) to create a PDF'''
s = '''"{config.docbook4xml_dblatex}" \\
@ -132,7 +129,7 @@ class Docbook4XML(BaseDoctype, SignatureChecker):
"{output.validsource}"'''
return self.shellscript(s)
@depends(graph, make_fo)
@depends(make_fo)
def make_name_pdf(self):
stem = self.source.stem
classname = self.__class__.__name__
@ -146,7 +143,7 @@ class Docbook4XML(BaseDoctype, SignatureChecker):
stem, classname, 'make_pdf_with_dblatex')
return self.make_pdf_with_dblatex()
@depends(graph, make_name_htmls)
@depends(make_name_htmls)
def make_html(self):
'''create chunked HTML output'''
s = '''"{config.docbook4xml_xsltproc}" \\
@ -157,19 +154,19 @@ class Docbook4XML(BaseDoctype, SignatureChecker):
"{output.validsource}"'''
return self.shellscript(s)
@depends(graph, make_html)
@depends(make_html)
def make_name_html(self):
'''rename DocBook XSL's index.html to LDP standard STEM.html'''
s = 'mv -v --no-clobber -- "{output.name_indexhtml}" "{output.name_html}"'
return self.shellscript(s)
@depends(graph, make_name_html)
@depends(make_name_html)
def make_name_indexhtml(self):
'''create final index.html symlink'''
s = 'ln -svr -- "{output.name_html}" "{output.name_indexhtml}"'
return self.shellscript(s)
@depends(graph, make_name_html)
@depends(make_name_html)
def remove_validated_source(self):
'''create final index.html symlink'''
s = 'rm --verbose -- "{output.validsource}"'

View File

@ -6,8 +6,6 @@ from __future__ import absolute_import, division, print_function
import os
import logging
import networkx as nx
from tldp.utils import which, firstfoundfile
from tldp.utils import arg_isexecutable, isexecutable
from tldp.utils import arg_isreadablefile, isreadablefile
@ -65,13 +63,11 @@ class Docbook5XML(BaseDoctype, SignatureChecker):
'docbook5xml_xslsingle': isreadablefile,
}
graph = nx.DiGraph()
def chdir_output(self):
os.chdir(self.output.dirname)
return True
@depends(graph, chdir_output)
@depends(chdir_output)
def make_xincluded_source(self):
s = '''"{config.docbook5xml_xmllint}" > "{output.validsource}" \\
--nonet \\
@ -80,7 +76,7 @@ class Docbook5XML(BaseDoctype, SignatureChecker):
"{source.filename}"'''
return self.shellscript(s)
@depends(graph, make_xincluded_source)
@depends(make_xincluded_source)
def validate_source(self):
'''consider lxml.etree and other validators'''
s = '''"{config.docbook5xml_jing}" \\
@ -88,7 +84,7 @@ class Docbook5XML(BaseDoctype, SignatureChecker):
"{output.validsource}"'''
return self.shellscript(s)
@depends(graph, make_xincluded_source)
@depends(make_xincluded_source)
def copy_static_resources(self):
source = list()
for d in ('images', 'resources'):
@ -103,7 +99,7 @@ class Docbook5XML(BaseDoctype, SignatureChecker):
s = 'rsync --archive --verbose %s ./' % (' '.join(source))
return self.shellscript(s)
@depends(graph, copy_static_resources)
@depends(copy_static_resources)
def make_name_htmls(self):
'''create a single page HTML output'''
s = '''"{config.docbook5xml_xsltproc}" > "{output.name_htmls}" \\
@ -114,7 +110,7 @@ class Docbook5XML(BaseDoctype, SignatureChecker):
"{output.validsource}"'''
return self.shellscript(s)
@depends(graph, make_name_htmls)
@depends(make_name_htmls)
def make_name_txt(self):
'''create text output'''
s = '''"{config.docbook5xml_html2text}" > "{output.name_txt}" \\
@ -123,7 +119,7 @@ class Docbook5XML(BaseDoctype, SignatureChecker):
"{output.name_htmls}"'''
return self.shellscript(s)
@depends(graph, copy_static_resources)
@depends(copy_static_resources)
def make_fo(self):
'''generate the Formatting Objects intermediate output'''
s = '''"{config.docbook5xml_xsltproc}" > "{output.name_fo}" \\
@ -133,7 +129,7 @@ class Docbook5XML(BaseDoctype, SignatureChecker):
return self.shellscript(s)
# -- this is conditionally built--see logic in make_name_pdf() below
# @depends(graph, make_fo)
# @depends(make_fo)
def make_pdf_with_fop(self):
'''use FOP to create a PDF'''
s = '''"{config.docbook5xml_fop}" \\
@ -142,7 +138,7 @@ class Docbook5XML(BaseDoctype, SignatureChecker):
return self.shellscript(s)
# -- this is conditionally built--see logic in make_name_pdf() below
# @depends(graph, chdir_output)
# @depends(chdir_output)
def make_pdf_with_dblatex(self):
'''use dblatex (fallback) to create a PDF'''
s = '''"{config.docbook5xml_dblatex}" \\
@ -152,7 +148,7 @@ class Docbook5XML(BaseDoctype, SignatureChecker):
"{output.validsource}"'''
return self.shellscript(s)
@depends(graph, make_fo)
@depends(make_fo)
def make_name_pdf(self):
stem = self.source.stem
classname = self.__class__.__name__
@ -166,7 +162,7 @@ class Docbook5XML(BaseDoctype, SignatureChecker):
stem, classname, 'make_pdf_with_dblatex')
return self.make_pdf_with_dblatex()
@depends(graph, make_name_htmls)
@depends(make_name_htmls)
def make_html(self):
'''create chunked HTML output'''
s = '''"{config.docbook5xml_xsltproc}" \\
@ -177,19 +173,19 @@ class Docbook5XML(BaseDoctype, SignatureChecker):
"{output.validsource}"'''
return self.shellscript(s)
@depends(graph, make_html)
@depends(make_html)
def make_name_html(self):
'''rename DocBook XSL's index.html to LDP standard STEM.html'''
s = 'mv -v --no-clobber -- "{output.name_indexhtml}" "{output.name_html}"'
return self.shellscript(s)
@depends(graph, make_name_html)
@depends(make_name_html)
def make_name_indexhtml(self):
'''create final index.html symlink'''
s = 'ln -svr -- "{output.name_html}" "{output.name_indexhtml}"'
return self.shellscript(s)
@depends(graph, make_name_indexhtml, make_name_pdf)
@depends(make_name_indexhtml, make_name_pdf)
def remove_xincluded_source(self):
'''remove the xincluded source file'''
s = 'rm --verbose -- "{output.validsource}"'

View File

@ -5,7 +5,6 @@ from __future__ import absolute_import, division, print_function
import os
import logging
import networkx as nx
from tldp.utils import which, firstfoundfile
from tldp.utils import arg_isexecutable, isexecutable
@ -48,13 +47,11 @@ class DocbookSGML(BaseDoctype, SignatureChecker):
'docbooksgml_docbookdsl': isreadablefile,
}
graph = nx.DiGraph()
def chdir_output(self):
os.chdir(self.output.dirname)
return True
@depends(graph, chdir_output)
@depends(chdir_output)
def copy_static_resources(self):
source = list()
for d in ('images', 'resources'):
@ -69,7 +66,7 @@ class DocbookSGML(BaseDoctype, SignatureChecker):
s = 'rsync --archive --verbose %s ./' % (' '.join(source))
return self.shellscript(s)
@depends(graph, copy_static_resources)
@depends(copy_static_resources)
def make_blank_indexsgml(self):
indexsgml = os.path.join(self.source.dirname, 'index.sgml')
self.indexsgml = os.path.isfile(indexsgml)
@ -82,7 +79,7 @@ class DocbookSGML(BaseDoctype, SignatureChecker):
"index.sgml"'''
return self.shellscript(s)
@depends(graph, make_blank_indexsgml)
@depends(make_blank_indexsgml)
def move_blank_indexsgml_into_source(self):
'''move a blank index.sgml file into the source tree'''
if self.indexsgml:
@ -93,7 +90,7 @@ class DocbookSGML(BaseDoctype, SignatureChecker):
-- "index.sgml" "{source.dirname}/index.sgml"'''
return self.shellscript(s)
@depends(graph, move_blank_indexsgml_into_source)
@depends(move_blank_indexsgml_into_source)
def make_data_indexsgml(self):
'''collect document's index entries into a data file (HTML.index)'''
if self.indexsgml:
@ -105,7 +102,7 @@ class DocbookSGML(BaseDoctype, SignatureChecker):
"{source.filename}"'''
return self.shellscript(s)
@depends(graph, make_data_indexsgml)
@depends(make_data_indexsgml)
def make_indexsgml(self):
'''generate the final document index file (index.sgml)'''
if self.indexsgml:
@ -119,7 +116,7 @@ class DocbookSGML(BaseDoctype, SignatureChecker):
"{source.filename}"'''
return self.shellscript(s)
@depends(graph, make_indexsgml)
@depends(make_indexsgml)
def move_indexsgml_into_source(self):
'''move the generated index.sgml file into the source tree'''
if self.indexsgml:
@ -136,7 +133,7 @@ class DocbookSGML(BaseDoctype, SignatureChecker):
return True
return False
@depends(graph, move_indexsgml_into_source)
@depends(move_indexsgml_into_source)
def cleaned_indexsgml(self):
'''clean the junk from the output dir after building the index.sgml'''
# -- be super cautious before removing a bunch of files
@ -148,7 +145,7 @@ class DocbookSGML(BaseDoctype, SignatureChecker):
s = '''find . -mindepth 1 -maxdepth 1 -not -type d -delete -print'''
return self.shellscript(s)
@depends(graph, cleaned_indexsgml)
@depends(cleaned_indexsgml)
def make_htmls(self):
'''create a single page HTML output (with incorrect name)'''
s = '''"{config.docbooksgml_jw}" \\
@ -162,13 +159,13 @@ class DocbookSGML(BaseDoctype, SignatureChecker):
"{source.filename}"'''
return self.shellscript(s)
@depends(graph, make_htmls)
@depends(make_htmls)
def make_name_htmls(self):
'''correct the single page HTML output name'''
s = 'mv -v --no-clobber -- "{output.name_html}" "{output.name_htmls}"'
return self.shellscript(s)
@depends(graph, make_name_htmls)
@depends(make_name_htmls)
def make_name_txt(self):
'''create text output (from single-page HTML)'''
s = '''"{config.docbooksgml_html2text}" > "{output.name_txt}" \\
@ -195,7 +192,7 @@ class DocbookSGML(BaseDoctype, SignatureChecker):
"{source.filename}"'''
return self.shellscript(s)
@depends(graph, cleaned_indexsgml)
@depends(cleaned_indexsgml)
def make_name_pdf(self):
stem = self.source.stem
classname = self.__class__.__name__
@ -209,7 +206,7 @@ class DocbookSGML(BaseDoctype, SignatureChecker):
stem, classname, 'make_pdf_with_dblatex')
return self.make_pdf_with_dblatex()
@depends(graph, make_name_htmls)
@depends(make_name_htmls)
def make_html(self):
'''create chunked HTML outputs'''
s = '''"{config.docbooksgml_jw}" \\
@ -222,13 +219,13 @@ class DocbookSGML(BaseDoctype, SignatureChecker):
"{source.filename}"'''
return self.shellscript(s)
@depends(graph, make_html)
@depends(make_html)
def make_name_html(self):
'''rename openjade's index.html to LDP standard name STEM.html'''
s = 'mv -v --no-clobber -- "{output.name_indexhtml}" "{output.name_html}"'
return self.shellscript(s)
@depends(graph, make_name_html)
@depends(make_name_html)
def make_name_indexhtml(self):
'''create final index.html symlink'''
s = 'ln -svr -- "{output.name_html}" "{output.name_indexhtml}"'

View File

@ -5,7 +5,6 @@ from __future__ import absolute_import, division, print_function
import os
import logging
import networkx as nx
from tldp.utils import which
from tldp.utils import arg_isexecutable, isexecutable
@ -24,13 +23,11 @@ class Linuxdoc(BaseDoctype, SignatureChecker):
'linuxdoc_htmldoc': isexecutable,
}
graph = nx.DiGraph()
def chdir_output(self):
os.chdir(self.output.dirname)
return True
@depends(graph, chdir_output)
@depends(chdir_output)
def copy_static_resources(self):
source = list()
for d in ('images', 'resources'):
@ -45,19 +42,19 @@ class Linuxdoc(BaseDoctype, SignatureChecker):
s = 'rsync --archive --verbose %s ./' % (' '.join(source))
return self.shellscript(s)
@depends(graph, copy_static_resources)
@depends(copy_static_resources)
def make_htmls(self):
'''create a single page HTML output (with incorrect name)'''
s = '"{config.linuxdoc_sgml2html}" --split=0 "{source.filename}"'
return self.shellscript(s)
@depends(graph, make_htmls)
@depends(make_htmls)
def make_name_htmls(self):
'''correct the single page HTML output name'''
s = 'mv -v --no-clobber -- "{output.name_html}" "{output.name_htmls}"'
return self.shellscript(s)
@depends(graph, make_name_htmls)
@depends(make_name_htmls)
def make_name_txt(self):
'''create text output (from single-page HTML)'''
s = '''"{config.linuxdoc_html2text}" > "{output.name_txt}" \\
@ -66,7 +63,7 @@ class Linuxdoc(BaseDoctype, SignatureChecker):
"{output.name_htmls}"'''
return self.shellscript(s)
@depends(graph, make_name_htmls)
@depends(make_name_htmls)
def make_name_pdf(self):
s = '''"{config.linuxdoc_htmldoc}" \\
--size universal \\
@ -76,13 +73,13 @@ class Linuxdoc(BaseDoctype, SignatureChecker):
"{output.name_htmls}"'''
return self.shellscript(s)
@depends(graph, make_name_htmls)
@depends(make_name_htmls)
def make_name_html(self):
'''create final index.html symlink'''
s = '"{config.linuxdoc_sgml2html}" "{source.filename}"'
return self.shellscript(s)
@depends(graph, make_name_html)
@depends(make_name_html)
def make_name_indexhtml(self):
'''create final index.html symlink'''
s = 'ln -svr -- "{output.name_html}" "{output.name_indexhtml}"'