added test of len() method for SQLTable
[pygr.git] / doc / tools / mksourcepkg
blobcad2b442b0518f1a74a93c975994f47eab49a21b
1 #! /usr/bin/env python
2 # -*- Python -*-
4 """%(program)s - script to create the latex source distribution
6 usage:
7 %(program)s [-t|--tools] release [tag]
9 with -t|--tools: doesn't include the documents, only the framework
11 without [tag]: generate from the current version that's checked in
12 (*NOT* what's in the current directory!)
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.
19 import getopt
20 import glob
21 import os
22 import re
23 import shutil
24 import sys
25 import tempfile
27 import cvsinfo
29 try:
30 __file__
31 except NameError:
32 __file__ = sys.argv[0]
34 tools = os.path.dirname(os.path.abspath(__file__))
35 Doc = os.path.dirname(tools)
36 patchlevel_tex = os.path.join(Doc, "commontex", "patchlevel.tex")
38 quiet = 0
39 rx = re.compile(r":ext:(?:[a-zA-Z0-9]+@)?cvs\.([a-zA-Z0-9]+).sourceforge.net:"
40 r"/cvsroot/\1")
43 def main():
44 global quiet
45 anonymous = False
46 try:
47 opts, args = getopt.getopt(sys.argv[1:], "Aabgtzq",
48 ["all", "bzip2", "gzip", "tools", "zip",
49 "quiet", "anonymous"])
50 except getopt.error, e:
51 usage(warning=str(e))
52 sys.exit(2)
53 if len(args) not in (1, 2):
54 usage(warning="wrong number of parameters")
55 sys.exit(2)
56 tools = 0
57 formats = {}
58 for opt, arg in opts:
59 if opt in ("-t", "--tools"):
60 tools = 1
61 elif opt in ("-q", "--quiet"):
62 quiet = quiet + 1
63 elif opt in ("-b", "--bzip2"):
64 formats["bzip2"] = 1
65 elif opt in ("-g", "--gzip"):
66 formats["gzip"] = 1
67 elif opt in ("-z", "--zip"):
68 formats["zip"] = 1
69 elif opt in ("-a", "--all"):
70 formats["bzip2"] = 1
71 formats["gzip"] = 1
72 formats["zip"] = 1
73 elif opt in ("-A", "--anonymous"):
74 anonymous = True
75 if formats:
76 # make order human-predictable
77 formats = formats.keys()
78 formats.sort()
79 else:
80 formats = ["gzip"]
81 release = args[0]
82 cvstag = None
83 if len(args) > 1:
84 cvstag = args[1]
85 tempdir = tempfile.mktemp()
86 os.mkdir(tempdir)
87 pkgdir = os.path.join(tempdir, "Python-Docs-" + release)
88 os.mkdir(pkgdir)
89 pwd = os.getcwd()
90 mydir = os.path.abspath(os.path.dirname(sys.argv[0]))
91 info = cvsinfo.RepositoryInfo(mydir)
92 cvsroot = info.get_cvsroot()
93 m = rx.match(cvsroot)
94 if m and anonymous:
95 # If this is an authenticated SourceForge repository, convert to
96 # anonymous usage for the export/checkout, since that avoids the
97 # SSH overhead.
98 group = m.group(1)
99 cvsroot = ":pserver:anonymous@cvs.%s.sourceforge.net:/cvsroot/%s" \
100 % (group, group)
101 # For some reason, SourceForge/CVS doesn't seem to care that we
102 # might not have done a "cvs login" to the anonymous server.
103 # That avoids a lot of painful gunk here.
104 os.chdir(tempdir)
105 if not quiet:
106 print "--- current directory is:", pkgdir
107 if cvstag:
108 run("cvs -d%s export -r %s -d Python-Docs-%s python/dist/src/Doc"
109 % (cvsroot, cvstag, release))
110 else:
111 run("cvs -Q -d%s checkout -d Python-Docs-%s python/dist/src/Doc"
112 % (cvsroot, release))
113 # remove CVS directories
114 for p in ('*/CVS', '*/*/CVS', '*/*/*/CVS'):
115 map(shutil.rmtree, glob.glob(p))
116 for f in ('.cvsignore', '*/.cvsignore'):
117 map(os.unlink, glob.glob(f))
119 # Copy in the version informtation, if we're not just going to
120 # rip it back out:
121 if not tools:
122 if not os.path.exists(patchlevel_tex):
123 run(os.path.join(here, "getversioninfo"))
124 dest = os.path.join("Python-Docs-" + release, "commontex",
125 "patchlevel.tex")
126 shutil.copyfile(patchlevel_tex, dest)
128 # Copy in the license file:
129 LICENSE = os.path.normpath(
130 os.path.join(mydir, os.pardir, os.pardir, "LICENSE"))
131 shutil.copyfile(LICENSE, "LICENSE")
132 if tools:
133 archive = "doctools-" + release
134 # we don't want the actual documents in this case:
135 for d in ("api", "dist", "doc", "ext", "inst",
136 "lib", "mac", "ref", "tut", "commontex"):
137 shutil.rmtree(os.path.join(pkgdir, d))
138 else:
139 archive = "latex-" + release
141 # XXX should also remove the .cvsignore files at this point
143 os.chdir(tempdir)
144 archive = os.path.join(pwd, archive)
145 for format in formats:
146 if format == "bzip2":
147 run("tar cf - Python-Docs-%s | bzip2 -9 >%s.tar.bz2"
148 % (release, archive))
149 elif format == "gzip":
150 run("tar cf - Python-Docs-%s | gzip -9 >%s.tgz"
151 % (release, archive))
152 elif format == "zip":
153 if os.path.exists(archive + ".zip"):
154 os.unlink(archive + ".zip")
155 run("zip -q -r9 %s.zip Python-Docs-%s"
156 % (archive, release))
158 # clean up the work area:
159 os.chdir(pwd)
160 shutil.rmtree(tempdir)
163 def run(cmd):
164 if quiet < 2:
165 print "+++", cmd
166 if quiet:
167 cmd = "%s >/dev/null" % cmd
168 rc = os.system(cmd)
169 if rc:
170 sys.exit(rc)
173 def usage(warning=None):
174 stdout = sys.stdout
175 sys.stdout = sys.stderr
176 program = os.path.basename(sys.argv[0])
177 try:
178 if warning:
179 print "%s: %s\n" % (program, warning)
180 print __doc__ % {"program": program}
181 finally:
182 sys.stdout = stdout
185 if __name__ == "__main__":
186 main()