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

📄 mkhowto

📁 python s60 1.4.5版本的源代码
💻
📖 第 1 页 / 共 2 页
字号:
#! /usr/bin/env python
#  -*- Python -*-
"""usage: %(program)s [options...] file ...

Options specifying formats to build:
    --html		HyperText Markup Language (default)
    --pdf		Portable Document Format
    --ps		PostScript
    --dvi		'DeVice Indepentent' format from TeX
    --text		ASCII text (requires lynx)

    More than one output format may be specified, or --all.

HTML options:
    --address, -a	Specify an address for page footers.
    --link		Specify the number of levels to include on each page.
    --split, -s		Specify a section level for page splitting, default: %(max_split_depth)s.
    --iconserver, -i	Specify location of icons (default: ../).
    --image-type	Specify the image type to use in HTML output;
                        values: gif (default), png.
    --numeric           Don't rename the HTML files; just keep node#.html for
                        the filenames.
    --style             Specify the CSS file to use for the output (filename,
                        not a URL).
    --up-link           URL to a parent document.
    --up-title          Title of a parent document.

Other options:
    --a4		Format for A4 paper.
    --letter		Format for US letter paper (the default).
    --help, -H		Show this text.
    --logging, -l	Log stdout and stderr to a file (*.how).
    --debugging, -D	Echo commands as they are executed.
    --keep, -k		Keep temporary files around.
    --quiet, -q		Do not print command output to stdout.
			(stderr is also lost,  sorry; see *.how for errors)
"""

import getopt
import glob
import os
import re
import shutil
import string
import sys
import tempfile


if not hasattr(os.path, "abspath"):
    # Python 1.5.1 or earlier
    def abspath(path):
        """Return an absolute path."""
        if not os.path.isabs(path):
            path = os.path.join(os.getcwd(), path)
        return os.path.normpath(path)

    os.path.abspath = abspath


MYDIR = os.path.abspath(sys.path[0])
TOPDIR = os.path.dirname(MYDIR)

ISTFILE = os.path.join(TOPDIR, "texinputs", "python.ist")
NODE2LABEL_SCRIPT = os.path.join(MYDIR, "node2label.pl")
L2H_INIT_FILE = os.path.join(TOPDIR, "perl", "l2hinit.perl")

BIBTEX_BINARY = "bibtex"
DVIPS_BINARY = "dvips"
LATEX_BINARY = "latex"
LATEX2HTML_BINARY = "latex2html"
LYNX_BINARY = "lynx"
MAKEINDEX_BINARY = "makeindex"
PDFLATEX_BINARY = "pdflatex"
PERL_BINARY = "perl"
PYTHON_BINARY = "python"


def usage(options):
    print __doc__ % options

def error(options, message, err=2):
    sys.stdout = sys.stderr
    print message
    print
    usage(options)
    sys.exit(2)


class Options:
    program = os.path.basename(sys.argv[0])
    #
    address = ''
    builddir = None
    debugging = 0
    discard_temps = 1
    have_temps = 0
    icon_server = None
    image_type = "gif"
    logging = 0
    max_link_depth = 3
    max_split_depth = 6
    paper = "letter"
    quiet = 0
    runs = 0
    numeric = 0
    global_module_index = None
    style_file = os.path.join(TOPDIR, "html", "style.css")
    about_file = os.path.join(TOPDIR, "html", "about.dat")
    up_link = None
    up_title = None
    #
    # 'dvips_safe' is a weird option.  It is used mostly to make
    # LaTeX2HTML not try to be too smart about protecting the user
    # from a bad version of dvips -- some versions would core dump if
    # the path to the source DVI contained a dot, and it's appearantly
    # difficult to determine if the version available has that bug.
    # This option gets set when PostScript output is requested
    # (because we're going to run dvips regardless, and we'll either
    # know it succeeds before LaTeX2HTML is run, or we'll have
    # detected the failure and bailed), or the user asserts that it's
    # safe from the command line.
    #
    # So, why does LaTeX2HTML think it appropriate to protect the user
    # from a dvips that's only potentially going to core dump?  Only
    # because they want to avoid doing a lot of work just to have to
    # bail later with no useful intermediates.  Unfortunately, they
    # bail *before* they know whether dvips will be needed at all.
    # I've gone around the bush a few times with the LaTeX2HTML
    # developers over whether this is appropriate behavior, and they
    # don't seem interested in changing their position.
    #
    dvips_safe = 0
    #
    DEFAULT_FORMATS = ("html",)
    ALL_FORMATS = ("dvi", "html", "pdf", "ps", "text")

    def __init__(self):
        self.formats = []
        self.l2h_init_files = []

    def __getitem__(self, key):
        # This is used when formatting the usage message.
        try:
            return getattr(self, key)
        except AttributeError:
            raise KeyError, key

    def parse(self, args):
        opts, args = getopt.getopt(args, "Hi:a:s:lDkqr:",
                                   ["all", "postscript", "help", "iconserver=",
                                    "address=", "a4", "letter", "l2h-init=",
                                    "link=", "split=", "logging", "debugging",
                                    "keep", "quiet", "runs=", "image-type=",
                                    "about=", "numeric", "style=", "paper=",
                                    "up-link=", "up-title=", "dir=",
                                    "global-module-index=", "dvips-safe"]
                                   + list(self.ALL_FORMATS))
        for opt, arg in opts:
            if opt == "--all":
                self.formats = list(self.ALL_FORMATS)
                self.dvips_safe = "ps" in self.formats
            elif opt in ("-H", "--help"):
                usage(self)
                sys.exit()
            elif opt == "--iconserver":
                self.icon_server = arg
            elif opt in ("-a", "--address"):
                self.address = arg
            elif opt == "--a4":
                self.paper = "a4"
            elif opt == "--letter":
                self.paper = "letter"
            elif opt == "--link":
                self.max_link_depth = int(arg)
            elif opt in ("-s", "--split"):
                self.max_split_depth = int(arg)
            elif opt in ("-l", "--logging"):
                self.logging = self.logging + 1
            elif opt in ("-D", "--debugging"):
                self.debugging = self.debugging + 1
            elif opt in ("-k", "--keep"):
                self.discard_temps = 0
            elif opt in ("-q", "--quiet"):
                self.quiet = 1
            elif opt in ("-r", "--runs"):
                self.runs = int(arg)
            elif opt == "--image-type":
                self.image_type = arg
            elif opt == "--about":
                # always make this absolute:
                self.about_file = os.path.normpath(
                    os.path.abspath(arg))
            elif opt == "--numeric":
                self.numeric = 1
            elif opt == "--style":
                self.style_file = os.path.abspath(arg)
            elif opt == "--l2h-init":
                self.l2h_init_files.append(os.path.abspath(arg))
            elif opt == "--up-link":
                self.up_link = arg
            elif opt == "--up-title":
                self.up_title = arg
            elif opt == "--global-module-index":
                self.global_module_index = arg
            elif opt == "--dir":
                if os.sep == "\\":
                    arg = re.sub("/", "\\", arg)
                self.builddir = arg
            elif opt == "--paper":
                self.paper = arg
            elif opt == "--dvips-safe":
                self.dvips_safe = 1
            #
            # Format specifiers:
            #
            elif opt[2:] in self.ALL_FORMATS:
                self.add_format(opt[2:])
            elif opt == "--postscript":
                # synonym for --ps
                self.add_format("ps")
        self.initialize()
        #
        # return the args to allow the caller access:
        #
        return args

    def add_format(self, format):
        """Add a format to the formats list if not present."""
        if not format in self.formats:
            if format == "ps":
                # assume this is safe since we're going to run it anyway
                self.dvips_safe = 1
            self.formats.append(format)

    def initialize(self):
        """Complete initialization.  This is needed if parse() isn't used."""
        # add the default format if no formats were specified:
        if not self.formats:
            self.formats = self.DEFAULT_FORMATS
        # determine the base set of texinputs directories:
        texinputs = string.split(os.environ.get("TEXINPUTS", ""), os.pathsep)
        if not texinputs:
            texinputs = ['']
        self.base_texinputs = [
            os.path.join(TOPDIR, "paper-" + self.paper),
            os.path.join(TOPDIR, "texinputs"),
            ] + texinputs
        if self.builddir:
            self.builddir = os.path.abspath(self.builddir)


class Job:
    latex_runs = 0

    def __init__(self, options, path):
        self.options = options
        self.doctype = get_doctype(path)
        self.filedir, self.doc = split_pathname(path)
        self.builddir = os.path.abspath(options.builddir or self.doc)
        if ("html" in options.formats or "text" in options.formats):
            if not os.path.exists(self.builddir):
                os.mkdir(self.builddir)
            self.log_filename = os.path.join(self.builddir, self.doc + ".how")
        else:
            self.log_filename = os.path.abspath(self.doc + ".how")
        if os.path.exists(self.log_filename):
            os.unlink(self.log_filename)
        if os.path.exists(self.doc + ".l2h"):
            self.l2h_aux_init_file = tempfile.mktemp()
        else:
            self.l2h_aux_init_file = self.doc + ".l2h"
        self.write_l2h_aux_init_file()

    def build(self):
        self.setup_texinputs()
        formats = self.options.formats
        if "dvi" in formats or "ps" in formats:
            self.build_dvi()
        if "pdf" in formats:
            self.build_pdf()
        if "ps" in formats:
            self.build_ps()
        if "html" in formats:
            self.require_temps()
            self.build_html(self.builddir)
            if self.options.icon_server == ".":
                pattern = os.path.join(TOPDIR, "html", "icons",
                                       "*." + self.options.image_type)
                imgs = glob.glob(pattern)
                if not imgs:
                    self.warning(
                        "Could not locate support images of type %s."
                        % `self.options.image_type`)
                for fn in imgs:
                    new_fn = os.path.join(self.doc, os.path.basename(fn))
                    shutil.copyfile(fn, new_fn)
        if "text" in formats:
            self.require_temps()
            tempdir = self.doc
            need_html = "html" not in formats
            if self.options.max_split_depth != 1:
                fp = open(self.l2h_aux_init_file, "a")
                fp.write("# re-hack this file for --text:\n")
                l2hoption(fp, "MAX_SPLIT_DEPTH", "1")
                fp.write("1;\n")
                fp.close()
                tempdir = self.doc + "-temp-html"
                need_html = 1
            if need_html:
                self.build_html(tempdir, max_split_depth=1)
            self.build_text(tempdir)
        if self.options.discard_temps:
            self.cleanup()

    def setup_texinputs(self):
        texinputs = [self.filedir] + list(self.options.base_texinputs)
        os.environ["TEXINPUTS"] = string.join(texinputs, os.pathsep)
        self.message("TEXINPUTS=" + os.environ["TEXINPUTS"])

    def build_aux(self, binary=None):
        if binary is None:
            binary = LATEX_BINARY
        new_index(   "%s.ind" % self.doc, "genindex")
        new_index("mod%s.ind" % self.doc, "modindex")
        self.run("%s %s" % (binary, self.doc))
        self.use_bibtex = check_for_bibtex(self.doc + ".aux")
        self.latex_runs = 1

⌨️ 快捷键说明

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