Updated for 2.1a3
[python/dscho.git] / Doc / tools / mksourcepkg
blobc3ea8639cdf91dffe7ba0f75ddbd12f8dd883411
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
30 quiet = 0
31 rx = re.compile(r":ext:(?:[a-zA-Z0-9]+)@cvs\.([a-zA-Z0-9]+).sourceforge.net:"
32 r"/cvsroot/\1")
35 def main():
36 global quiet
37 try:
38 opts, args = getopt.getopt(sys.argv[1:], "abgtzq",
39 ["all", "bzip2", "gzip", "tools", "zip",
40 "quiet"])
41 except getopt.error, e:
42 usage(warning=str(e))
43 sys.exit(2)
44 if len(args) not in (1, 2):
45 usage(warning="wrong number of parameters")
46 sys.exit(2)
47 tools = 0
48 formats = {}
49 for opt, arg in opts:
50 if opt in ("-t", "--tools"):
51 tools = 1
52 elif opt in ("-q", "--quiet"):
53 quiet = quiet + 1
54 elif opt in ("-b", "--bzip2"):
55 formats["bzip2"] = 1
56 elif opt in ("-g", "--gzip"):
57 formats["gzip"] = 1
58 elif opt in ("-z", "--zip"):
59 formats["zip"] = 1
60 elif opt in ("-a", "--all"):
61 formats["bzip2"] = 1
62 formats["gzip"] = 1
63 formats["zip"] = 1
64 if formats:
65 # make order human-predictable
66 formats = formats.keys()
67 formats.sort()
68 else:
69 formats = ["gzip"]
70 release = args[0]
71 cvstag = None
72 if len(args) > 1:
73 cvstag = args[1]
74 tempdir = tempfile.mktemp()
75 os.mkdir(tempdir)
76 pkgdir = os.path.join(tempdir, "Python-" + release)
77 os.mkdir(pkgdir)
78 pwd = os.getcwd()
79 mydir = os.path.abspath(os.path.dirname(sys.argv[0]))
80 info = cvsinfo.RepositoryInfo(mydir)
81 cvsroot = info.get_cvsroot()
82 m = rx.match(cvsroot)
83 if m:
84 # If this is an authenticated SourceForge repository, convert to
85 # anonymous usage for the export/checkout, since that avoids the
86 # SSH overhead.
87 group = m.group(1)
88 cvsroot = ":pserver:anonymous@cvs.%s.sourceforge.net:/cvsroot/%s" \
89 % (group, group)
90 # For some reason, SourceForge/CVS doesn't seem to care that we
91 # might not have done a "cvs login" to the anonymous server.
92 # That avoids a lot of painful gunk here.
93 os.chdir(pkgdir)
94 if not quiet:
95 print "--- current directory is:", pkgdir
96 if cvstag:
97 run("cvs -d%s export -r %s -d Doc python/dist/src/Doc"
98 % (cvsroot, cvstag))
99 else:
100 run("cvs -Q -d%s checkout -d Doc python/dist/src/Doc" % cvsroot)
101 # remove CVS directories
102 for p in ('*/CVS', '*/*/CVS', '*/*/*/CVS'):
103 map(shutil.rmtree, glob.glob(p))
104 for f in ('.cvsignore', '*/.cvsignore'):
105 map(os.unlink, glob.glob(f))
106 LICENSE = os.path.normpath(
107 os.path.join(mydir, os.pardir, os.pardir, "LICENSE"))
108 shutil.copyfile(LICENSE, "Doc/LICENSE")
109 if tools:
110 archive = "doctools-" + release
111 # we don't want the actual documents in this case:
112 for d in ("api", "dist", "doc", "ext", "inst",
113 "lib", "mac", "ref", "tut"):
114 shutil.rmtree(os.path.join(os.path.join(pkgdir, "Doc"), d))
115 else:
116 archive = "latex-" + release
118 # XXX should also remove the .cvsignore files at this point
120 os.chdir(tempdir)
121 archive = os.path.join(pwd, archive)
122 for format in formats:
123 if format == "bzip2":
124 run("tar cf - Python-%s | bzip2 -9 >%s.tar.bz2"
125 % (release, archive))
126 elif format == "gzip":
127 run("tar cf - Python-%s | gzip -9 >%s.tgz"
128 % (release, archive))
129 elif format == "zip":
130 if os.path.exists(archive + ".zip"):
131 os.unlink(archive + ".zip")
132 run("zip -q -r9 %s.zip Python-%s"
133 % (archive, release))
135 # clean up the work area:
136 os.chdir(pwd)
137 shutil.rmtree(tempdir)
140 def run(cmd):
141 if quiet < 2:
142 print "+++", cmd
143 if quiet:
144 cmd = "%s >/dev/null" % cmd
145 rc = os.system(cmd)
146 if rc:
147 sys.exit(rc)
150 def usage(warning=None):
151 stdout = sys.stdout
152 sys.stdout = sys.stderr
153 program = os.path.basename(sys.argv[0])
154 try:
155 if warning:
156 print "%s: %s\n" % (program, warning)
157 print __doc__ % {"program": program}
158 finally:
159 sys.stdout = stdout
162 if __name__ == "__main__":
163 main()