183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh"""Module/script to byte-compile all .py files to .pyc (or .pyo) files.
283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew HsiehWhen called as a script with arguments, this compiles the directories
483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehgiven as arguments recursively; the -l option prevents it from
583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehrecursing into directories.
683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew HsiehWithout arguments, if compiles all modules on sys.path, without
883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehrecursing into subdirectories.  (Even though it should do so for
983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehpackages -- for now, you'll have to deal with packages separately.)
1083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
1183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew HsiehSee module py_compile for details of the actual byte-compilation.
1283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh"""
1383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehimport os
1483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehimport sys
1583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehimport py_compile
1683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehimport struct
1783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehimport imp
1883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
1983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh__all__ = ["compile_dir","compile_file","compile_path"]
2083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
2183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehdef compile_dir(dir, maxlevels=10, ddir=None,
2283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                force=0, rx=None, quiet=0):
2383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    """Byte-compile all modules in the given directory tree.
2483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
2583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    Arguments (only dir is required):
2683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
2783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    dir:       the directory to byte-compile
2883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    maxlevels: maximum recursion level (default 10)
2983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    ddir:      the directory that will be prepended to the path to the
3083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh               file as it is compiled into each byte-code file.
3183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    force:     if 1, force compilation, even if timestamps are up-to-date
3283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    quiet:     if 1, be quiet during compilation
3383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    """
3483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    if not quiet:
3583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print 'Listing', dir, '...'
3683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    try:
3783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        names = os.listdir(dir)
3883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    except os.error:
3983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "Can't list", dir
4083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        names = []
4183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    names.sort()
4283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    success = 1
4383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    for name in names:
4483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        fullname = os.path.join(dir, name)
4583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if sys.platform == "win32" and sys.version.find("GCC") >= 0:
4683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            fullname = fullname.replace('\\','/')
4783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if ddir is not None:
4883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            dfile = os.path.join(ddir, name)
4983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        else:
5083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            dfile = None
5183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if not os.path.isdir(fullname):
5283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            if not compile_file(fullname, ddir, force, rx, quiet):
5383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                success = 0
5483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        elif maxlevels > 0 and \
5583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh             name != os.curdir and name != os.pardir and \
5683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh             os.path.isdir(fullname) and \
5783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh             not os.path.islink(fullname):
5883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            if not compile_dir(fullname, maxlevels - 1, dfile, force, rx,
5983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                               quiet):
6083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                success = 0
6183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    return success
6283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
6383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehdef compile_file(fullname, ddir=None, force=0, rx=None, quiet=0):
6483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    """Byte-compile one file.
6583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
6683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    Arguments (only fullname is required):
6783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
6883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    fullname:  the file to byte-compile
6983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    ddir:      if given, the directory name compiled in to the
7083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh               byte-code file.
7183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    force:     if 1, force compilation, even if timestamps are up-to-date
7283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    quiet:     if 1, be quiet during compilation
7383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    """
7483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    success = 1
7583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    name = os.path.basename(fullname)
7683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    if ddir is not None:
7783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        dfile = os.path.join(ddir, name)
7883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    else:
7983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        dfile = None
8083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    if rx is not None:
8183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        mo = rx.search(fullname)
8283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if mo:
8383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            return success
8483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    if os.path.isfile(fullname):
8583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        head, tail = name[:-3], name[-3:]
8683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if tail == '.py':
8783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            if not force:
8883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                try:
8983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                    mtime = int(os.stat(fullname).st_mtime)
9083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                    expect = struct.pack('<4sl', imp.get_magic(), mtime)
9183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                    cfile = fullname + (__debug__ and 'c' or 'o')
9283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                    with open(cfile, 'rb') as chandle:
9383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                        actual = chandle.read(8)
9483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                    if expect == actual:
9583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                        return success
9683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                except IOError:
9783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                    pass
9883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            if not quiet:
9983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                print 'Compiling', fullname, '...'
10083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            try:
10183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                ok = py_compile.compile(fullname, None, dfile, True)
10283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            except py_compile.PyCompileError,err:
10383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                if quiet:
10483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                    print 'Compiling', fullname, '...'
10583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                print err.msg
10683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                success = 0
10783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            except IOError, e:
10883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                print "Sorry", e
10983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                success = 0
11083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            else:
11183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                if ok == 0:
11283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                    success = 0
11383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    return success
11483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
11583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehdef compile_path(skip_curdir=1, maxlevels=0, force=0, quiet=0):
11683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    """Byte-compile all module on sys.path.
11783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
11883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    Arguments (all optional):
11983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
12083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    skip_curdir: if true, skip current directory (default true)
12183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    maxlevels:   max recursion level (default 0)
12283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    force: as for compile_dir() (default 0)
12383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    quiet: as for compile_dir() (default 0)
12483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    """
12583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    success = 1
12683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    for dir in sys.path:
12783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if (not dir or dir == os.curdir) and skip_curdir:
12883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            print 'Skipping current directory'
12983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        else:
13083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            success = success and compile_dir(dir, maxlevels, None,
13183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                                              force, quiet=quiet)
13283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    return success
13383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
13483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehdef expand_args(args, flist):
13583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    """read names in flist and append to args"""
13683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    expanded = args[:]
13783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    if flist:
13883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        try:
13983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            if flist == '-':
14083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                fd = sys.stdin
14183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            else:
14283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                fd = open(flist)
14383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            while 1:
14483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                line = fd.readline()
14583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                if not line:
14683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                    break
14783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                expanded.append(line[:-1])
14883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        except IOError:
14983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            print "Error reading file list %s" % flist
15083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            raise
15183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    return expanded
15283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
15383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehdef main():
15483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    """Script main program."""
15583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    import getopt
15683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    try:
15783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        opts, args = getopt.getopt(sys.argv[1:], 'lfqd:x:i:')
15883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    except getopt.error, msg:
15983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print msg
16083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "usage: python compileall.py [-l] [-f] [-q] [-d destdir] " \
16183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh              "[-x regexp] [-i list] [directory|file ...]"
16283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print
16383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "arguments: zero or more file and directory names to compile; " \
16483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh              "if no arguments given, "
16583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "           defaults to the equivalent of -l sys.path"
16683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print
16783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "options:"
16883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "-l: don't recurse into subdirectories"
16983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "-f: force rebuild even if timestamps are up-to-date"
17083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "-q: output only error messages"
17183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "-d destdir: directory to prepend to file paths for use in " \
17283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh              "compile-time tracebacks and in"
17383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "            runtime tracebacks in cases where the source " \
17483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh              "file is unavailable"
17583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "-x regexp: skip files matching the regular expression regexp; " \
17683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh              "the regexp is searched for"
17783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "           in the full path of each file considered for " \
17883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh              "compilation"
17983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "-i file: add all the files and directories listed in file to " \
18083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh              "the list considered for"
18183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print '         compilation; if "-", names are read from stdin'
18283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
18383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        sys.exit(2)
18483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    maxlevels = 10
18583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    ddir = None
18683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    force = 0
18783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    quiet = 0
18883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    rx = None
18983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    flist = None
19083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    for o, a in opts:
19183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if o == '-l': maxlevels = 0
19283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if o == '-d': ddir = a
19383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if o == '-f': force = 1
19483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if o == '-q': quiet = 1
19583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if o == '-x':
19683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            import re
19783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            rx = re.compile(a)
19883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if o == '-i': flist = a
19983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    if ddir:
20083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if len(args) != 1 and not os.path.isdir(args[0]):
20183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            print "-d destdir require exactly one directory argument"
20283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            sys.exit(2)
20383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    success = 1
20483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    try:
20583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        if args or flist:
20683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            try:
20783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                if flist:
20883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                    args = expand_args(args, flist)
20983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            except IOError:
21083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                success = 0
21183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            if success:
21283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                for arg in args:
21383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                    if os.path.isdir(arg):
21483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                        if not compile_dir(arg, maxlevels, ddir,
21583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                                           force, rx, quiet):
21683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                            success = 0
21783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                    else:
21883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                        if not compile_file(arg, ddir, force, rx, quiet):
21983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh                            success = 0
22083760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        else:
22183760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh            success = compile_path()
22283760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    except KeyboardInterrupt:
22383760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        print "\n[interrupted]"
22483760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh        success = 0
22583760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    return success
22683760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh
22783760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsiehif __name__ == '__main__':
22883760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    exit_status = int(not main())
22983760d213fb3bec7b4117d266fcfbf6fe2ba14abAndrew Hsieh    sys.exit(exit_status)
230