annotate Lib/compileall.py @ 58925:eecf1bef052d 2.6

Merged revisions 78207 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line #7930: fix stripid ........
author Ezio Melotti <ezio.melotti@gmail.com>
date Tue, 16 Feb 2010 23:29:44 +0000
parents 495700ee3345
children 584c47d8c93f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
1 """Module/script to "compile" all .py files to .pyc (or .pyo) file.
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
2
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
3 When called as a script with arguments, this compiles the directories
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
4 given as arguments recursively; the -l option prevents it from
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
5 recursing into directories.
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
6
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
7 Without arguments, if compiles all modules on sys.path, without
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
8 recursing into subdirectories. (Even though it should do so for
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
9 packages -- for now, you'll have to deal with packages separately.)
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
10
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
11 See module py_compile for details of the actual byte-compilation.
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
12
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
13 """
1828
b464e1d0b2fb New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
b464e1d0b2fb New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 import os
b464e1d0b2fb New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 import sys
b464e1d0b2fb New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 import py_compile
b464e1d0b2fb New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
16070
b5345e99596b added __all__ lists to a number of Python modules
Skip Montanaro <skip@pobox.com>
parents: 10498
diff changeset
19 __all__ = ["compile_dir","compile_path"]
b5345e99596b added __all__ lists to a number of Python modules
Skip Montanaro <skip@pobox.com>
parents: 10498
diff changeset
20
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
21 def compile_dir(dir, maxlevels=10, ddir=None,
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
22 force=0, rx=None, quiet=0):
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
23 """Byte-compile all modules in the given directory tree.
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
24
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
25 Arguments (only dir is required):
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
26
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
27 dir: the directory to byte-compile
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
28 maxlevels: maximum recursion level (default 10)
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
29 ddir: if given, purported directory name (this is the
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
30 directory name that will show up in error messages)
9664
4eee061dac44 A mod whose author I forget. (I must've mislaid the email. If it's
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
31 force: if 1, force compilation, even if timestamps are up-to-date
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
32 quiet: if 1, be quiet during compilation
1828
b464e1d0b2fb New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff changeset
33
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
34 """
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
35 if not quiet:
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
36 print 'Listing', dir, '...'
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
37 try:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
38 names = os.listdir(dir)
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
39 except os.error:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
40 print "Can't list", dir
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
41 names = []
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
42 names.sort()
10498
fe8645e49314 When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents: 9664
diff changeset
43 success = 1
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
44 for name in names:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
45 fullname = os.path.join(dir, name)
23610
0a2818cc342c Use is None rather than general boolean
Raymond Hettinger <python@rcn.com>
parents: 22374
diff changeset
46 if ddir is not None:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
47 dfile = os.path.join(ddir, name)
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
48 else:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
49 dfile = None
23610
0a2818cc342c Use is None rather than general boolean
Raymond Hettinger <python@rcn.com>
parents: 22374
diff changeset
50 if rx is not None:
17559
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
51 mo = rx.search(fullname)
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
52 if mo:
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
53 continue
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
54 if os.path.isfile(fullname):
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
55 head, tail = name[:-3], name[-3:]
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
56 if tail == '.py':
9664
4eee061dac44 A mod whose author I forget. (I must've mislaid the email. If it's
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
57 cfile = fullname + (__debug__ and 'c' or 'o')
23625
65cf478950ff Replaced obsolete stat module constants with equivalent attributes
Raymond Hettinger <python@rcn.com>
parents: 23610
diff changeset
58 ftime = os.stat(fullname).st_mtime
65cf478950ff Replaced obsolete stat module constants with equivalent attributes
Raymond Hettinger <python@rcn.com>
parents: 23610
diff changeset
59 try: ctime = os.stat(cfile).st_mtime
9664
4eee061dac44 A mod whose author I forget. (I must've mislaid the email. If it's
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
60 except os.error: ctime = 0
4eee061dac44 A mod whose author I forget. (I must've mislaid the email. If it's
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
61 if (ctime > ftime) and not force: continue
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
62 if not quiet:
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
63 print 'Compiling', fullname, '...'
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
64 try:
27250
16a876746285 Patch #661719: Expose compilation errors as exceptions on request.
Martin v. Löwis <martin@v.loewis.de>
parents: 23625
diff changeset
65 ok = py_compile.compile(fullname, None, dfile, True)
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
66 except KeyboardInterrupt:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
67 raise KeyboardInterrupt
27250
16a876746285 Patch #661719: Expose compilation errors as exceptions on request.
Martin v. Löwis <martin@v.loewis.de>
parents: 23625
diff changeset
68 except py_compile.PyCompileError,err:
32391
6fc02915f637 Patch #975885: print file name in err msg in quiet mode
Martin v. Löwis <martin@v.loewis.de>
parents: 30223
diff changeset
69 if quiet:
6fc02915f637 Patch #975885: print file name in err msg in quiet mode
Martin v. Löwis <martin@v.loewis.de>
parents: 30223
diff changeset
70 print 'Compiling', fullname, '...'
27250
16a876746285 Patch #661719: Expose compilation errors as exceptions on request.
Martin v. Löwis <martin@v.loewis.de>
parents: 23625
diff changeset
71 print err.msg
10498
fe8645e49314 When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents: 9664
diff changeset
72 success = 0
27263
7acf57440f4e Catch IOErrors.
Martin v. Löwis <martin@v.loewis.de>
parents: 27250
diff changeset
73 except IOError, e:
7acf57440f4e Catch IOErrors.
Martin v. Löwis <martin@v.loewis.de>
parents: 27250
diff changeset
74 print "Sorry", e
7acf57440f4e Catch IOErrors.
Martin v. Löwis <martin@v.loewis.de>
parents: 27250
diff changeset
75 success = 0
17559
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
76 else:
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
77 if ok == 0:
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
78 success = 0
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
79 elif maxlevels > 0 and \
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
80 name != os.curdir and name != os.pardir and \
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
81 os.path.isdir(fullname) and \
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
82 not os.path.islink(fullname):
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
83 if not compile_dir(fullname, maxlevels - 1, dfile, force, rx, quiet):
17559
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
84 success = 0
10498
fe8645e49314 When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents: 9664
diff changeset
85 return success
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
86
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
87 def compile_path(skip_curdir=1, maxlevels=0, force=0, quiet=0):
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
88 """Byte-compile all module on sys.path.
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
89
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
90 Arguments (all optional):
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
91
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
92 skip_curdir: if true, skip current directory (default true)
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
93 maxlevels: max recursion level (default 0)
9664
4eee061dac44 A mod whose author I forget. (I must've mislaid the email. If it's
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
94 force: as for compile_dir() (default 0)
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
95 quiet: as for compile_dir() (default 0)
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
96
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
97 """
10498
fe8645e49314 When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents: 9664
diff changeset
98 success = 1
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
99 for dir in sys.path:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
100 if (not dir or dir == os.curdir) and skip_curdir:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
101 print 'Skipping current directory'
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
102 else:
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
103 success = success and compile_dir(dir, maxlevels, None,
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
104 force, quiet=quiet)
10498
fe8645e49314 When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents: 9664
diff changeset
105 return success
1828
b464e1d0b2fb New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff changeset
106
b464e1d0b2fb New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 def main():
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
108 """Script main program."""
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
109 import getopt
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
110 try:
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
111 opts, args = getopt.getopt(sys.argv[1:], 'lfqd:x:')
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
112 except getopt.error, msg:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
113 print msg
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
114 print "usage: python compileall.py [-l] [-f] [-q] [-d destdir] " \
30223
c06dffb6a982 Fix typo in docstring: The switch is '-x', not '-s'.
Thomas Heller <theller@ctypes.org>
parents: 27263
diff changeset
115 "[-x regexp] [directory ...]"
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
116 print "-l: don't recurse down"
9664
4eee061dac44 A mod whose author I forget. (I must've mislaid the email. If it's
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
117 print "-f: force rebuild even if timestamps are up-to-date"
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
118 print "-q: quiet operation"
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
119 print "-d destdir: purported directory name for error messages"
17559
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
120 print " if no directory arguments, -l sys.path is assumed"
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
121 print "-x regexp: skip files matching the regular expression regexp"
45657
495700ee3345 fix typo
Fred Drake <fdrake@acm.org>
parents: 34201
diff changeset
122 print " the regexp is searched for in the full path of the file"
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
123 sys.exit(2)
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
124 maxlevels = 10
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
125 ddir = None
9664
4eee061dac44 A mod whose author I forget. (I must've mislaid the email. If it's
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
126 force = 0
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
127 quiet = 0
17559
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
128 rx = None
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
129 for o, a in opts:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
130 if o == '-l': maxlevels = 0
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
131 if o == '-d': ddir = a
9664
4eee061dac44 A mod whose author I forget. (I must've mislaid the email. If it's
Guido van Rossum <guido@python.org>
parents: 7755
diff changeset
132 if o == '-f': force = 1
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
133 if o == '-q': quiet = 1
17559
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
134 if o == '-x':
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
135 import re
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
136 rx = re.compile(a)
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
137 if ddir:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
138 if len(args) != 1:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
139 print "-d destdir require exactly one directory argument"
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
140 sys.exit(2)
10498
fe8645e49314 When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents: 9664
diff changeset
141 success = 1
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
142 try:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
143 if args:
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
144 for dir in args:
22374
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
145 if not compile_dir(dir, maxlevels, ddir,
2417694324ef Patch #495598: add an -q (quiet) option to pycompile.
Martin v. Löwis <martin@v.loewis.de>
parents: 17559
diff changeset
146 force, rx, quiet):
17559
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
147 success = 0
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
148 else:
10498
fe8645e49314 When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents: 9664
diff changeset
149 success = compile_path()
7126
d2c110acc60c Revamped, to match py_compile.py:
Guido van Rossum <guido@python.org>
parents: 3902
diff changeset
150 except KeyboardInterrupt:
7755
fb4b4d069cc7 Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents: 7126
diff changeset
151 print "\n[interrupt]"
10498
fe8645e49314 When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents: 9664
diff changeset
152 success = 0
fe8645e49314 When run as a script, report failures in the exit code as well.
Fred Drake <fdrake@acm.org>
parents: 9664
diff changeset
153 return success
1828
b464e1d0b2fb New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff changeset
154
b464e1d0b2fb New way of generating .pyc files, thanks to Sjoerd.
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 if __name__ == '__main__':
34201
a0c7df52ba41 Bugs item #1069409 C:\Python24\Lib\compileall.py returns False
Raymond Hettinger <python@rcn.com>
parents: 32391
diff changeset
156 exit_status = int(not main())
17559
28c14a79ad22 Fix compileall.py so that it fails on SyntaxErrors
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 16070
diff changeset
157 sys.exit(exit_status)