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

Skip to content

Commit 5c137c2

Browse files
committed
Patch #495598: add an -q (quiet) option to pycompile.
1 parent 73f570b commit 5c137c2

3 files changed

Lines changed: 31 additions & 11 deletions

File tree

Doc/lib/libcompileall.tex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,22 @@ \section{\module{compileall} ---
1717

1818

1919
\begin{funcdesc}{compile_dir}{dir\optional{, maxlevels\optional{,
20-
ddir\optional{, force}}}}
20+
ddir\optional{, force\optional{,
21+
rx\optional{, quiet}}}}}}
2122
Recursively descend the directory tree named by \var{dir}, compiling
2223
all \file{.py} files along the way. The \var{maxlevels} parameter
2324
is used to limit the depth of the recursion; it defaults to
2425
\code{10}. If \var{ddir} is given, it is used as the base path from
2526
which the filenames used in error messages will be generated. If
2627
\var{force} is true, modules are re-compiled even if the timestamps
27-
are up to date.
28+
are up to date.
29+
30+
If \var{rx} is given, it specifies a regular expression of file
31+
names to exclude from the search; that expression is searched for in
32+
the full path.
33+
34+
If \var{quiet} is true, nothing is printed to the standard output
35+
in normal operation.
2836
\end{funcdesc}
2937

3038
\begin{funcdesc}{compile_path}{\optional{skip_curdir\optional{,

Lib/compileall.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
__all__ = ["compile_dir","compile_path"]
2121

22-
def compile_dir(dir, maxlevels=10, ddir=None, force=0, rx=None):
22+
def compile_dir(dir, maxlevels=10, ddir=None,
23+
force=0, rx=None, quiet=0):
2324
"""Byte-compile all modules in the given directory tree.
2425
2526
Arguments (only dir is required):
@@ -29,9 +30,11 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=0, rx=None):
2930
ddir: if given, purported directory name (this is the
3031
directory name that will show up in error messages)
3132
force: if 1, force compilation, even if timestamps are up-to-date
33+
quiet: if 1, be quiet during compilation
3234
3335
"""
34-
print 'Listing', dir, '...'
36+
if not quiet:
37+
print 'Listing', dir, '...'
3538
try:
3639
names = os.listdir(dir)
3740
except os.error:
@@ -57,7 +60,8 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=0, rx=None):
5760
try: ctime = os.stat(cfile)[stat.ST_MTIME]
5861
except os.error: ctime = 0
5962
if (ctime > ftime) and not force: continue
60-
print 'Compiling', fullname, '...'
63+
if not quiet:
64+
print 'Compiling', fullname, '...'
6165
try:
6266
ok = py_compile.compile(fullname, None, dfile)
6367
except KeyboardInterrupt:
@@ -77,39 +81,42 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=0, rx=None):
7781
name != os.curdir and name != os.pardir and \
7882
os.path.isdir(fullname) and \
7983
not os.path.islink(fullname):
80-
if not compile_dir(fullname, maxlevels - 1, dfile, force, rx):
84+
if not compile_dir(fullname, maxlevels - 1, dfile, force, rx, quiet):
8185
success = 0
8286
return success
8387

84-
def compile_path(skip_curdir=1, maxlevels=0, force=0):
88+
def compile_path(skip_curdir=1, maxlevels=0, force=0, quiet=0):
8589
"""Byte-compile all module on sys.path.
8690
8791
Arguments (all optional):
8892
8993
skip_curdir: if true, skip current directory (default true)
9094
maxlevels: max recursion level (default 0)
9195
force: as for compile_dir() (default 0)
96+
quiet: as for compile_dir() (default 0)
9297
9398
"""
9499
success = 1
95100
for dir in sys.path:
96101
if (not dir or dir == os.curdir) and skip_curdir:
97102
print 'Skipping current directory'
98103
else:
99-
success = success and compile_dir(dir, maxlevels, None, force)
104+
success = success and compile_dir(dir, maxlevels, None,
105+
force, quiet=quiet)
100106
return success
101107

102108
def main():
103109
"""Script main program."""
104110
import getopt
105111
try:
106-
opts, args = getopt.getopt(sys.argv[1:], 'lfd:x:')
112+
opts, args = getopt.getopt(sys.argv[1:], 'lfqd:x:')
107113
except getopt.error, msg:
108114
print msg
109-
print "usage: python compileall.py [-l] [-f] [-d destdir] " \
115+
print "usage: python compileall.py [-l] [-f] [-q] [-d destdir] " \
110116
"[-s regexp] [directory ...]"
111117
print "-l: don't recurse down"
112118
print "-f: force rebuild even if timestamps are up-to-date"
119+
print "-q: quiet operation"
113120
print "-d destdir: purported directory name for error messages"
114121
print " if no directory arguments, -l sys.path is assumed"
115122
print "-x regexp: skip files matching the regular expression regexp"
@@ -118,11 +125,13 @@ def main():
118125
maxlevels = 10
119126
ddir = None
120127
force = 0
128+
quiet = 0
121129
rx = None
122130
for o, a in opts:
123131
if o == '-l': maxlevels = 0
124132
if o == '-d': ddir = a
125133
if o == '-f': force = 1
134+
if o == '-q': quiet = 1
126135
if o == '-x':
127136
import re
128137
rx = re.compile(a)
@@ -134,7 +143,8 @@ def main():
134143
try:
135144
if args:
136145
for dir in args:
137-
if not compile_dir(dir, maxlevels, ddir, force, rx):
146+
if not compile_dir(dir, maxlevels, ddir,
147+
force, rx, quiet):
138148
success = 0
139149
else:
140150
success = compile_path()

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Extension modules
4444

4545
Library
4646

47+
- compileall now supports quiet operation.
48+
4749
- The BaseHTTPServer implements now optionally HTTP/1.1 persistent
4850
connections.
4951

0 commit comments

Comments
 (0)