Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9f2b420

Browse files
committed
Re-implementation of mktarball.sh as a more portable Python script;
with a more descriptive name. Allow creation of multiple archive formats with a single pass; useful in this case since it uses a fresh export/checkout from CVS to ensure that the tree is "clean" (no build turds, saved files, &c). Use --all to create all supported formats.
1 parent 080c1b5 commit 9f2b420

1 file changed

Lines changed: 139 additions & 0 deletions

File tree

Doc/tools/mksourcepkg

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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+
__version__ = "$Revision$"
20+
21+
import getopt
22+
import glob
23+
import os
24+
import shutil
25+
import sys
26+
import tempfile
27+
28+
29+
quiet = 0
30+
31+
32+
def main():
33+
global quiet
34+
try:
35+
opts, args = getopt.getopt(sys.argv[1:], "abgtzq",
36+
["all", "bzip2", "gzip", "tools", "zip",
37+
"quiet"])
38+
except getopt.error, e:
39+
usage(warning=str(e))
40+
sys.exit(2)
41+
if len(args) not in (1, 2):
42+
usage(warning="wrong number of parameters")
43+
sys.exit(2)
44+
tools = 0
45+
formats = {}
46+
for opt, arg in opts:
47+
if opt in ("-t", "--tools"):
48+
tools = 1
49+
elif opt in ("-q", "--quiet"):
50+
quiet = quiet + 1
51+
elif opt in ("-b", "--bzip2"):
52+
formats["bzip2"] = 1
53+
elif opt in ("-g", "--gzip"):
54+
formats["gzip"] = 1
55+
elif opt in ("-z", "--zip"):
56+
formats["zip"] = 1
57+
elif opt in ("-a", "--all"):
58+
formats["bzip2"] = 1
59+
formats["gzip"] = 1
60+
formats["zip"] = 1
61+
formats = formats.keys()
62+
if formats:
63+
# make order human-predictable
64+
formats.sort()
65+
else:
66+
formats = ["gzip"]
67+
release = args[0]
68+
cvstag = None
69+
if len(args) > 1:
70+
cvstag = args[1]
71+
tempdir = tempfile.mktemp()
72+
os.mkdir(tempdir)
73+
os.mkdir(os.path.join(tempdir, "Python-%s" % release))
74+
docdir = os.path.join(tempdir, "Python-%s" % release, "Doc")
75+
os.mkdir(docdir)
76+
mydir = os.getcwd()
77+
if cvstag:
78+
run("cvs export -r %s -d %s/Python-%s/Doc python/dist/src/Doc"
79+
% (cvstag, tempdir, release))
80+
else:
81+
run("cvs checkout -d %s/Python-%s/Doc python/dist/src/Doc"
82+
% (tempdir, release))
83+
# remove CVS directories
84+
os.chdir("%s/Python-%s" % (tempdir, release))
85+
for p in ('*/CVS', '*/*/CVS', '*/*/*/CVS'):
86+
map(shutil.rmtree, glob.glob(p))
87+
os.chdir(mydir)
88+
if tools:
89+
archive = "tools-" + release
90+
# we don't want the actual documents in this case:
91+
for d in ("api", "doc", "ext", "lib", "mac", "ref", "tut"):
92+
shutil.rmtree(os.path.join(docdir, d))
93+
else:
94+
archive = "latex-" + release
95+
96+
# XXX should also remove the .cvsignore files at this point
97+
98+
os.chdir(tempdir)
99+
archive = os.path.join(mydir, archive)
100+
for format in formats:
101+
if format == "bzip2":
102+
run("tar cf - Python-%s | bzip2 -9 >%s.tar.bz2"
103+
% (release, archive))
104+
elif format == "gzip":
105+
run("tar cf - Python-%s | gzip -9 >%s.tgz"
106+
% (release, archive))
107+
elif format == "zip":
108+
run("zip -r9 %s.zip Python-%s"
109+
% (archive, release))
110+
111+
# clean up the work area:
112+
os.chdir(mydir)
113+
shutil.rmtree(tempdir)
114+
115+
116+
def run(cmd):
117+
if quiet < 2:
118+
print "+++", cmd
119+
if quiet:
120+
cmd = "(%s) >/dev/null" % cmd
121+
rc = os.system(cmd)
122+
if rc:
123+
sys.exit(rc)
124+
125+
126+
def usage(warning=None):
127+
stdout = sys.stdout
128+
sys.stdout = sys.stderr
129+
program = os.path.basename(sys.argv[0])
130+
try:
131+
if warning:
132+
print "%s: %s\n" % (program, warning)
133+
print __doc__ % {"program": program}
134+
finally:
135+
sys.stdout = stdout
136+
137+
138+
if __name__ == "__main__":
139+
main()

0 commit comments

Comments
 (0)