| 1 | #! /usr/bin/env python
|
|---|
| 2 | # -*- Python -*-
|
|---|
| 3 |
|
|---|
| 4 | """%(program)s - script to create the latex source distribution
|
|---|
| 5 |
|
|---|
| 6 | usage:
|
|---|
| 7 | %(program)s [-t|--tools] release [tag]
|
|---|
| 8 |
|
|---|
| 9 | with -t|--tools: doesn't include the documents, only the framework
|
|---|
| 10 |
|
|---|
| 11 | without [tag]: generate from the current version that's checked in
|
|---|
| 12 | (*NOT* what's in the current directory!)
|
|---|
| 13 |
|
|---|
| 14 | with [tag]: generate from the named tag
|
|---|
| 15 | """
|
|---|
| 16 | #* should be modified to get the Python version number automatically
|
|---|
| 17 | # from the Makefile or someplace.
|
|---|
| 18 |
|
|---|
| 19 | import getopt
|
|---|
| 20 | import glob
|
|---|
| 21 | import os
|
|---|
| 22 | import re
|
|---|
| 23 | import shutil
|
|---|
| 24 | import sys
|
|---|
| 25 | import tempfile
|
|---|
| 26 |
|
|---|
| 27 | try:
|
|---|
| 28 | __file__
|
|---|
| 29 | except NameError:
|
|---|
| 30 | __file__ = sys.argv[0]
|
|---|
| 31 |
|
|---|
| 32 | tools = os.path.dirname(os.path.abspath(__file__))
|
|---|
| 33 | Doc = os.path.dirname(tools)
|
|---|
| 34 | patchlevel_tex = os.path.join(Doc, "commontex", "patchlevel.tex")
|
|---|
| 35 |
|
|---|
| 36 | quiet = 0
|
|---|
| 37 | rx = re.compile(r":ext:(?:[a-zA-Z0-9]+@)?cvs\.([a-zA-Z0-9]+).sourceforge.net:"
|
|---|
| 38 | r"/cvsroot/\1")
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | def main():
|
|---|
| 42 | global quiet
|
|---|
| 43 | anonymous = False
|
|---|
| 44 | try:
|
|---|
| 45 | opts, args = getopt.getopt(sys.argv[1:], "Aabgtzq",
|
|---|
| 46 | ["all", "bzip2", "gzip", "tools", "zip",
|
|---|
| 47 | "quiet", "anonymous"])
|
|---|
| 48 | except getopt.error, e:
|
|---|
| 49 | usage(warning=str(e))
|
|---|
| 50 | sys.exit(2)
|
|---|
| 51 | if len(args) not in (1, 2):
|
|---|
| 52 | usage(warning="wrong number of parameters")
|
|---|
| 53 | sys.exit(2)
|
|---|
| 54 | tools = 0
|
|---|
| 55 | formats = {}
|
|---|
| 56 | for opt, arg in opts:
|
|---|
| 57 | if opt in ("-t", "--tools"):
|
|---|
| 58 | tools = 1
|
|---|
| 59 | elif opt in ("-q", "--quiet"):
|
|---|
| 60 | quiet = quiet + 1
|
|---|
| 61 | elif opt in ("-b", "--bzip2"):
|
|---|
| 62 | formats["bzip2"] = 1
|
|---|
| 63 | elif opt in ("-g", "--gzip"):
|
|---|
| 64 | formats["gzip"] = 1
|
|---|
| 65 | elif opt in ("-z", "--zip"):
|
|---|
| 66 | formats["zip"] = 1
|
|---|
| 67 | elif opt in ("-a", "--all"):
|
|---|
| 68 | formats["bzip2"] = 1
|
|---|
| 69 | formats["gzip"] = 1
|
|---|
| 70 | formats["zip"] = 1
|
|---|
| 71 | elif opt in ("-A", "--anonymous"):
|
|---|
| 72 | anonymous = True
|
|---|
| 73 | if formats:
|
|---|
| 74 | # make order human-predictable
|
|---|
| 75 | formats = formats.keys()
|
|---|
| 76 | formats.sort()
|
|---|
| 77 | else:
|
|---|
| 78 | formats = ["gzip"]
|
|---|
| 79 | release = args[0]
|
|---|
| 80 | svntag = None
|
|---|
| 81 | if len(args) > 1:
|
|---|
| 82 | svntag = args[1]
|
|---|
| 83 | tempdir = tempfile.mktemp()
|
|---|
| 84 | os.mkdir(tempdir)
|
|---|
| 85 | pkgdir = os.path.join(tempdir, "Python-Docs-" + release)
|
|---|
| 86 | pwd = os.getcwd()
|
|---|
| 87 | mydir = os.path.abspath(os.path.dirname(sys.argv[0]))
|
|---|
| 88 | os.chdir(tempdir)
|
|---|
| 89 | if not quiet:
|
|---|
| 90 | print "--- current directory is:", tempdir
|
|---|
| 91 | if not svntag:
|
|---|
| 92 | svntag = "trunk"
|
|---|
| 93 | svnbase = "http://svn.python.org/projects/python"
|
|---|
| 94 | run("svn export %s/%s/Doc Python-Docs-%s"
|
|---|
| 95 | % (svnbase, svntag, release))
|
|---|
| 96 |
|
|---|
| 97 | # Copy in the version informtation, if we're not just going to
|
|---|
| 98 | # rip it back out:
|
|---|
| 99 | if not tools:
|
|---|
| 100 | if not os.path.exists(patchlevel_tex):
|
|---|
| 101 | run(os.path.join(here, "getversioninfo"))
|
|---|
| 102 | dest = os.path.join("Python-Docs-" + release, "commontex",
|
|---|
| 103 | "patchlevel.tex")
|
|---|
| 104 | shutil.copyfile(patchlevel_tex, dest)
|
|---|
| 105 |
|
|---|
| 106 | # Copy in the license file:
|
|---|
| 107 | LICENSE = os.path.normpath(
|
|---|
| 108 | os.path.join(mydir, os.pardir, os.pardir, "LICENSE"))
|
|---|
| 109 | shutil.copyfile(LICENSE, "LICENSE")
|
|---|
| 110 | if tools:
|
|---|
| 111 | archive = "doctools-" + release
|
|---|
| 112 | # we don't want the actual documents in this case:
|
|---|
| 113 | for d in ("api", "dist", "doc", "ext", "inst",
|
|---|
| 114 | "lib", "mac", "ref", "tut", "commontex"):
|
|---|
| 115 | shutil.rmtree(os.path.join(pkgdir, d))
|
|---|
| 116 | else:
|
|---|
| 117 | archive = "latex-" + release
|
|---|
| 118 |
|
|---|
| 119 | # XXX should also remove the .cvsignore files at this point
|
|---|
| 120 |
|
|---|
| 121 | os.chdir(tempdir)
|
|---|
| 122 | archive = os.path.join(pwd, archive)
|
|---|
| 123 | for format in formats:
|
|---|
| 124 | if format == "bzip2":
|
|---|
| 125 | run("tar cf - Python-Docs-%s | bzip2 -9 >%s.tar.bz2"
|
|---|
| 126 | % (release, archive))
|
|---|
| 127 | elif format == "gzip":
|
|---|
| 128 | run("tar cf - Python-Docs-%s | gzip -9 >%s.tgz"
|
|---|
| 129 | % (release, archive))
|
|---|
| 130 | elif format == "zip":
|
|---|
| 131 | if os.path.exists(archive + ".zip"):
|
|---|
| 132 | os.unlink(archive + ".zip")
|
|---|
| 133 | run("zip -q -r9 %s.zip Python-Docs-%s"
|
|---|
| 134 | % (archive, release))
|
|---|
| 135 |
|
|---|
| 136 | # clean up the work area:
|
|---|
| 137 | os.chdir(pwd)
|
|---|
| 138 | shutil.rmtree(tempdir)
|
|---|
| 139 |
|
|---|
| 140 |
|
|---|
| 141 | def run(cmd):
|
|---|
| 142 | if quiet < 2:
|
|---|
| 143 | print "+++", cmd
|
|---|
| 144 | if quiet:
|
|---|
| 145 | cmd = "%s >/dev/null" % cmd
|
|---|
| 146 | rc = os.system(cmd)
|
|---|
| 147 | if rc:
|
|---|
| 148 | sys.exit(rc)
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 | def usage(warning=None):
|
|---|
| 152 | stdout = sys.stdout
|
|---|
| 153 | sys.stdout = sys.stderr
|
|---|
| 154 | program = os.path.basename(sys.argv[0])
|
|---|
| 155 | try:
|
|---|
| 156 | if warning:
|
|---|
| 157 | print "%s: %s\n" % (program, warning)
|
|---|
| 158 | print __doc__ % {"program": program}
|
|---|
| 159 | finally:
|
|---|
| 160 | sys.stdout = stdout
|
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 | if __name__ == "__main__":
|
|---|
| 164 | main()
|
|---|