⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mkhowto

📁 python s60 1.4.5版本的源代码
💻
📖 第 1 页 / 共 2 页
字号:

    def build_dvi(self):
        self.use_latex(LATEX_BINARY)

    def build_pdf(self):
        self.use_latex(PDFLATEX_BINARY)

    def use_latex(self, binary):
        self.require_temps(binary=binary)
        if self.latex_runs < 2:
            if os.path.isfile("mod%s.idx" % self.doc):
                self.run("%s mod%s.idx" % (MAKEINDEX_BINARY, self.doc))
            use_indfix = 0
            if os.path.isfile(self.doc + ".idx"):
                use_indfix = 1
                # call to Doc/tools/fix_hack omitted; doesn't appear necessary
                self.run("%s %s.idx" % (MAKEINDEX_BINARY, self.doc))
                import indfix
                indfix.process(self.doc + ".ind")
            if self.use_bibtex:
                self.run("%s %s" % (BIBTEX_BINARY, self.doc))
            self.process_synopsis_files()
            self.run("%s %s" % (binary, self.doc))
            self.latex_runs = self.latex_runs + 1
            if os.path.isfile("mod%s.idx" % self.doc):
                self.run("%s -s %s mod%s.idx"
                         % (MAKEINDEX_BINARY, ISTFILE, self.doc))
            if use_indfix:
                self.run("%s -s %s %s.idx"
                         % (MAKEINDEX_BINARY, ISTFILE, self.doc))
                indfix.process(self.doc + ".ind")
            self.process_synopsis_files()
        #
        # and now finish it off:
        #
        if os.path.isfile(self.doc + ".toc") and binary == PDFLATEX_BINARY:
            import toc2bkm
            if self.doctype == "manual":
                bigpart = "chapter"
            else:
                bigpart = "section"
            toc2bkm.process(self.doc + ".toc", self.doc + ".bkm", bigpart)
        if self.use_bibtex:
            self.run("%s %s" % (BIBTEX_BINARY, self.doc))
        self.run("%s %s" % (binary, self.doc))
        self.latex_runs = self.latex_runs + 1

    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):
        self.run("%s -N0 -o %s.ps %s" % (DVIPS_BINARY, self.doc, self.doc))

    def build_html(self, builddir, max_split_depth=None):
        if max_split_depth is None:
            max_split_depth = self.options.max_split_depth
        texfile = None
        for p in string.split(os.environ["TEXINPUTS"], os.pathsep):
            fn = os.path.join(p, self.doc + ".tex")
            if os.path.isfile(fn):
                texfile = fn
                break
        if not texfile:
            self.warning("Could not locate %s.tex; aborting." % self.doc)
            sys.exit(1)
        # remove leading ./ (or equiv.); might avoid problems w/ dvips
        if texfile[:2] == os.curdir + os.sep:
            texfile = texfile[2:]
        # build the command line and run LaTeX2HTML:
        if not os.path.isdir(builddir):
            os.mkdir(builddir)
        else:
            for fname in glob.glob(os.path.join(builddir, "*.html")):
                os.unlink(fname)
        args = [LATEX2HTML_BINARY,
                "-init_file", self.l2h_aux_init_file,
                "-dir", builddir,
                texfile
                ]
        self.run(string.join(args))     # XXX need quoting!
        # ... postprocess
        shutil.copyfile(self.options.style_file,
                        os.path.join(builddir, self.doc + ".css"))
        shutil.copyfile(os.path.join(builddir, self.doc + ".html"),
                        os.path.join(builddir, "index.html"))
        if max_split_depth != 1:
            label_file = os.path.join(builddir, "labels.pl")
            fp = open(label_file)
            about_node = None
            target = " = q/about/;\n"
            x = len(target)
            while 1:
                line = fp.readline()
                if not line:
                    break
                if line[-x:] == target:
                    line = fp.readline()
                    m = re.search(r"\|(node\d+\.[a-z]+)\|", line)
                    about_node = m.group(1)
                    shutil.copyfile(os.path.join(builddir, about_node),
                                    os.path.join(builddir, "about.html"))
                    break
            if not self.options.numeric:
                pwd = os.getcwd()
                try:
                    os.chdir(builddir)
                    self.run("%s %s *.html" % (PERL_BINARY, NODE2LABEL_SCRIPT))
                finally:
                    os.chdir(pwd)

    def build_text(self, tempdir=None):
        if tempdir is None:
            tempdir = self.doc
        indexfile = os.path.join(tempdir, "index.html")
        self.run("%s -nolist -dump %s >%s.txt"
                 % (LYNX_BINARY, indexfile, self.doc))

    def require_temps(self, binary=None):
        if not self.latex_runs:
            self.build_aux(binary=binary)

    def write_l2h_aux_init_file(self):
        options = self.options
        fp = open(self.l2h_aux_init_file, "w")
        d = string_to_perl(os.path.dirname(L2H_INIT_FILE))
        fp.write("package main;\n"
                 "push (@INC, '%s');\n"
                 "$mydir = '%s';\n"
                 % (d, d))
        fp.write(open(L2H_INIT_FILE).read())
        for filename in options.l2h_init_files:
            fp.write("\n# initialization code incorporated from:\n# ")
            fp.write(filename)
            fp.write("\n")
            fp.write(open(filename).read())
        fp.write("\n"
                 "# auxillary init file for latex2html\n"
                 "# generated by mkhowto\n"
                 "$NO_AUTO_LINK = 1;\n"
                 )
        l2hoption(fp, "ABOUT_FILE", options.about_file)
        l2hoption(fp, "ICONSERVER", options.icon_server)
        l2hoption(fp, "IMAGE_TYPE", options.image_type)
        l2hoption(fp, "ADDRESS", options.address)
        l2hoption(fp, "MAX_LINK_DEPTH", options.max_link_depth)
        l2hoption(fp, "MAX_SPLIT_DEPTH", options.max_split_depth)
        l2hoption(fp, "EXTERNAL_UP_LINK", options.up_link)
        l2hoption(fp, "EXTERNAL_UP_TITLE", options.up_title)
        l2hoption(fp, "GLOBAL_MODULE_INDEX", options.global_module_index)
        l2hoption(fp, "DVIPS_SAFE", options.dvips_safe)
        fp.write("1;\n")
        fp.close()

    def cleanup(self):
        self.__have_temps = 0
        for pattern in ("%s.aux", "%s.log", "%s.out", "%s.toc", "%s.bkm",
                        "%s.idx", "%s.ilg", "%s.ind", "%s.pla",
                        "%s.bbl", "%s.blg",
                        "mod%s.idx", "mod%s.ind", "mod%s.ilg",
                        ):
            safe_unlink(pattern % self.doc)
        map(safe_unlink, glob.glob(self.doc + "*.syn"))
        for spec in ("IMG*", "*.pl", "WARNINGS", "index.dat", "modindex.dat"):
            pattern = os.path.join(self.doc, spec)
            map(safe_unlink, glob.glob(pattern))
        if "dvi" not in self.options.formats:
            safe_unlink(self.doc + ".dvi")
        if os.path.isdir(self.doc + "-temp-html"):
            shutil.rmtree(self.doc + "-temp-html", ignore_errors=1)
        if not self.options.logging:
            os.unlink(self.log_filename)
        if not self.options.debugging:
            os.unlink(self.l2h_aux_init_file)

    def run(self, command):
        self.message(command)
        if sys.platform.startswith("win"):
            rc = os.system(command)
        else:
            rc = os.system("(%s) </dev/null >>%s 2>&1"
                           % (command, self.log_filename))
        if rc:
            self.warning(
                "Session transcript and error messages are in %s."
                % self.log_filename)
            if hasattr(os, "WIFEXITED"):
                if os.WIFEXITED(rc):
                    self.warning("Exited with status %s." % os.WEXITSTATUS(rc))
                else:
                    self.warning("Killed by signal %s." % os.WSTOPSIG(rc))
            else:
                self.warning("Return code: %s" % rc)
            sys.stderr.write("The relevant lines from the transcript are:\n")
            sys.stderr.write("-" * 72 + "\n")
            sys.stderr.writelines(get_run_transcript(self.log_filename))
            sys.exit(rc)

    def message(self, msg):
        msg = "+++ " + msg
        if not self.options.quiet:
            print msg
        self.log(msg + "\n")

    def warning(self, msg):
        msg = "*** %s\n" % msg
        sys.stderr.write(msg)
        self.log(msg)

    def log(self, msg):
        fp = open(self.log_filename, "a")
        fp.write(msg)
        fp.close()


def get_run_transcript(filename):
    """Return lines from the transcript file for the most recent run() call."""
    fp = open(filename)
    lines = fp.readlines()
    fp.close()
    lines.reverse()
    L = []
    for line in lines:
        L.append(line)
        if line[:4] == "+++ ":
            break
    L.reverse()
    return L


def safe_unlink(path):
    """Unlink a file without raising an error if it doesn't exist."""
    try:
        os.unlink(path)
    except os.error:
        pass


def split_pathname(path):
    path = os.path.abspath(path)
    dirname, basename = os.path.split(path)
    if basename[-4:] == ".tex":
        basename = basename[:-4]
    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():
    options = Options()
    try:
        args = options.parse(sys.argv[1:])
    except getopt.error, msg:
        error(options, msg)
    if not args:
        # attempt to locate single .tex file in current directory:
        args = glob.glob("*.tex")
        if not args:
            error(options, "No file to process.")
        if len(args) > 1:
            error(options, "Could not deduce which files should be processed.")
    #
    # parameters are processed, let's go!
    #
    for path in args:
        Job(options, path).build()


def l2hoption(fp, option, value):
    if value:
        fp.write('$%s = "%s";\n' % (option, string_to_perl(str(value))))


_to_perl = {}
for c in map(chr, range(1, 256)):
    _to_perl[c] = c
_to_perl["@"] = "\\@"
_to_perl["$"] = "\\$"
_to_perl['"'] = '\\"'

def string_to_perl(s):
    return string.join(map(_to_perl.get, s), '')


def check_for_bibtex(filename):
    fp = open(filename)
    pos = string.find(fp.read(), r"\bibdata{")
    fp.close()
    return pos >= 0

def uniqify_module_table(filename):
    lines = open(filename).readlines()
    if len(lines) > 1:
        if lines[-1] == lines[-2]:
            del lines[-1]
    open(filename, "w").writelines(lines)


def new_index(filename, label="genindex"):
    fp = open(filename, "w")
    fp.write(r"""\
\begin{theindex}
\label{%s}
\end{theindex}
""" % label)
    fp.close()


if __name__ == "__main__":
    main()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -