Commit 1e3e986c authored by Fred Drake's avatar Fred Drake

Make it work for "manual" documents as well as "howto" documents.

This still doesn't understand anything about multiple source files or
checking time dependencies.
parent accaedf9
...@@ -31,6 +31,7 @@ Other options: ...@@ -31,6 +31,7 @@ Other options:
import getopt import getopt
import glob import glob
import os import os
import re
import shutil import shutil
import string import string
import sys import sys
...@@ -166,6 +167,7 @@ class Options: ...@@ -166,6 +167,7 @@ class Options:
class Job: class Job:
def __init__(self, options, path): def __init__(self, options, path):
self.options = options self.options = options
self.doctype = get_doctype(path)
self.filedir, self.doc = split_pathname(path) self.filedir, self.doc = split_pathname(path)
self.log_filename = self.doc + ".how" self.log_filename = self.doc + ".how"
if os.path.exists(self.log_filename): if os.path.exists(self.log_filename):
...@@ -243,26 +245,43 @@ class Job: ...@@ -243,26 +245,43 @@ class Job:
indfix.process(self.doc + ".ind") indfix.process(self.doc + ".ind")
if self.use_bibtex: if self.use_bibtex:
self.run("%s %s" % (BIBTEX_BINARY, self.doc)) self.run("%s %s" % (BIBTEX_BINARY, self.doc))
synopsis_file = self.doc + ".syn" self.process_synopsis_files()
if os.path.isfile(synopsis_file): #
# impose uniq requirement on last line.... # let the doctype-specific handler do some intermediate work:
uniqify_module_table(synopsis_file) #
self.run("%s %s" % (binary, self.doc)) if self.doctype == "manual":
if os.path.isfile("mod%s.idx" % self.doc): self.use_latex_manual(binary=binary)
self.run("%s -s %s mod%s.idx" elif self.doctype == "howto":
% (MAKEINDEX_BINARY, ISTFILE, self.doc)) self.use_latex_howto(binary=binary)
if os.path.isfile(self.doc + ".idx"): else:
self.run("%s -s %s %s.idx" % (MAKEINDEX_BINARY, ISTFILE, self.doc)) raise RuntimeError, "unsupported document type: " + self.doctype
#
# and now finish it off:
#
if os.path.isfile(self.doc + ".toc") and binary == PDFLATEX_BINARY: if os.path.isfile(self.doc + ".toc") and binary == PDFLATEX_BINARY:
import toc2bkm import toc2bkm
toc2bkm.process(self.doc + ".toc", self.doc + ".bkm", "section") toc2bkm.process(self.doc + ".toc", self.doc + ".bkm", "section")
if os.path.isfile(synopsis_file):
# impose uniq requirement on last line....
uniqify_module_table(synopsis_file)
if self.use_bibtex: if self.use_bibtex:
self.run("%s %s" % (BIBTEX_BINARY, self.doc)) self.run("%s %s" % (BIBTEX_BINARY, self.doc))
self.run("%s %s" % (binary, self.doc)) self.run("%s %s" % (binary, self.doc))
def use_latex_howto(self, binary):
self.run("%s %s" % (binary, self.doc))
if os.path.isfile("mod%s.idx" % self.doc):
self.run("%s -s %s mod%s.idx"
% (MAKEINDEX_BINARY, ISTFILE, self.doc))
if os.path.isfile(self.doc + ".idx"):
self.run("%s -s %s %s.idx" % (MAKEINDEX_BINARY, ISTFILE, self.doc))
self.process_synopsis_files()
def use_latex_manual(self, binary):
pass
def process_synopsis_files(self):
synopsis_files = glob.glob(self.doc + "*.syn")
for path in synopsis_files:
uniqify_module_table(path)
def build_ps(self): def build_ps(self):
self.run("%s -N0 -o %s.ps %s" % (DVIPS_BINARY, self.doc, self.doc)) self.run("%s -N0 -o %s.ps %s" % (DVIPS_BINARY, self.doc, self.doc))
...@@ -338,11 +357,12 @@ class Job: ...@@ -338,11 +357,12 @@ class Job:
def cleanup(self): def cleanup(self):
self.__have_temps = 0 self.__have_temps = 0
for pattern in ("%s.aux", "%s.log", "%s.out", "%s.toc", "%s.bkm", for pattern in ("%s.aux", "%s.log", "%s.out", "%s.toc", "%s.bkm",
"%s.idx", "%s.ilg", "%s.ind", "%s.syn", "%s.pla", "%s.idx", "%s.ilg", "%s.ind", "%s.pla",
"%s.bbl", "%s.blg", "%s.bbl", "%s.blg",
"mod%s.idx", "mod%s.ind", "mod%s.ilg", "mod%s.idx", "mod%s.ind", "mod%s.ilg",
): ):
safe_unlink(pattern % self.doc) safe_unlink(pattern % self.doc)
map(safe_unlink, glob.glob(self.doc + "*.syn"))
for spec in ("IMG*", "*.pl", "WARNINGS", "index.dat", "modindex.dat"): for spec in ("IMG*", "*.pl", "WARNINGS", "index.dat", "modindex.dat"):
pattern = os.path.join(self.doc, spec) pattern = os.path.join(self.doc, spec)
map(safe_unlink, glob.glob(pattern)) map(safe_unlink, glob.glob(pattern))
...@@ -381,14 +401,30 @@ def safe_unlink(path): ...@@ -381,14 +401,30 @@ def safe_unlink(path):
pass pass
def split_pathname(pathname): def split_pathname(path):
pathname = os.path.normpath(os.path.join(os.getcwd(), pathname)) path = os.path.normpath(os.path.join(os.getcwd(), path))
dirname, basename = os.path.split(pathname) dirname, basename = os.path.split(path)
if basename[-4:] == ".tex": if basename[-4:] == ".tex":
basename = basename[:-4] basename = basename[:-4]
return dirname, basename return dirname, basename
_doctype_rx = re.compile(r"\\documentclass(?:\[[^]]*\])?{([a-zA-Z]*)}")
def get_doctype(path):
fp = open(path)
doctype = None
while 1:
line = fp.readline()
if not line:
break
m = _doctype_rx.match(line)
if m:
doctype = m.group(1)
break
fp.close()
return doctype
def main(): def main():
options = Options() options = Options()
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment