Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2....
File: compileall.py
"""Module/script to byte-compile all .py files to .pyc (or .pyo) files.
[0] Fix | Delete
[1] Fix | Delete
When called as a script with arguments, this compiles the directories
[2] Fix | Delete
given as arguments recursively; the -l option prevents it from
[3] Fix | Delete
recursing into directories.
[4] Fix | Delete
[5] Fix | Delete
Without arguments, if compiles all modules on sys.path, without
[6] Fix | Delete
recursing into subdirectories. (Even though it should do so for
[7] Fix | Delete
packages -- for now, you'll have to deal with packages separately.)
[8] Fix | Delete
[9] Fix | Delete
See module py_compile for details of the actual byte-compilation.
[10] Fix | Delete
"""
[11] Fix | Delete
import os
[12] Fix | Delete
import sys
[13] Fix | Delete
import py_compile
[14] Fix | Delete
import struct
[15] Fix | Delete
import imp
[16] Fix | Delete
[17] Fix | Delete
__all__ = ["compile_dir","compile_file","compile_path"]
[18] Fix | Delete
[19] Fix | Delete
def compile_dir(dir, maxlevels=10, ddir=None,
[20] Fix | Delete
force=0, rx=None, quiet=0):
[21] Fix | Delete
"""Byte-compile all modules in the given directory tree.
[22] Fix | Delete
[23] Fix | Delete
Arguments (only dir is required):
[24] Fix | Delete
[25] Fix | Delete
dir: the directory to byte-compile
[26] Fix | Delete
maxlevels: maximum recursion level (default 10)
[27] Fix | Delete
ddir: the directory that will be prepended to the path to the
[28] Fix | Delete
file as it is compiled into each byte-code file.
[29] Fix | Delete
force: if 1, force compilation, even if timestamps are up-to-date
[30] Fix | Delete
quiet: if 1, be quiet during compilation
[31] Fix | Delete
"""
[32] Fix | Delete
if not quiet:
[33] Fix | Delete
print 'Listing', dir, '...'
[34] Fix | Delete
try:
[35] Fix | Delete
names = os.listdir(dir)
[36] Fix | Delete
except os.error:
[37] Fix | Delete
print "Can't list", dir
[38] Fix | Delete
names = []
[39] Fix | Delete
names.sort()
[40] Fix | Delete
success = 1
[41] Fix | Delete
for name in names:
[42] Fix | Delete
fullname = os.path.join(dir, name)
[43] Fix | Delete
if ddir is not None:
[44] Fix | Delete
dfile = os.path.join(ddir, name)
[45] Fix | Delete
else:
[46] Fix | Delete
dfile = None
[47] Fix | Delete
if not os.path.isdir(fullname):
[48] Fix | Delete
if not compile_file(fullname, ddir, force, rx, quiet):
[49] Fix | Delete
success = 0
[50] Fix | Delete
elif maxlevels > 0 and \
[51] Fix | Delete
name != os.curdir and name != os.pardir and \
[52] Fix | Delete
os.path.isdir(fullname) and \
[53] Fix | Delete
not os.path.islink(fullname):
[54] Fix | Delete
if not compile_dir(fullname, maxlevels - 1, dfile, force, rx,
[55] Fix | Delete
quiet):
[56] Fix | Delete
success = 0
[57] Fix | Delete
return success
[58] Fix | Delete
[59] Fix | Delete
def compile_file(fullname, ddir=None, force=0, rx=None, quiet=0):
[60] Fix | Delete
"""Byte-compile one file.
[61] Fix | Delete
[62] Fix | Delete
Arguments (only fullname is required):
[63] Fix | Delete
[64] Fix | Delete
fullname: the file to byte-compile
[65] Fix | Delete
ddir: if given, the directory name compiled in to the
[66] Fix | Delete
byte-code file.
[67] Fix | Delete
force: if 1, force compilation, even if timestamps are up-to-date
[68] Fix | Delete
quiet: if 1, be quiet during compilation
[69] Fix | Delete
"""
[70] Fix | Delete
success = 1
[71] Fix | Delete
name = os.path.basename(fullname)
[72] Fix | Delete
if ddir is not None:
[73] Fix | Delete
dfile = os.path.join(ddir, name)
[74] Fix | Delete
else:
[75] Fix | Delete
dfile = None
[76] Fix | Delete
if rx is not None:
[77] Fix | Delete
mo = rx.search(fullname)
[78] Fix | Delete
if mo:
[79] Fix | Delete
return success
[80] Fix | Delete
if os.path.isfile(fullname):
[81] Fix | Delete
head, tail = name[:-3], name[-3:]
[82] Fix | Delete
if tail == '.py':
[83] Fix | Delete
if not force:
[84] Fix | Delete
try:
[85] Fix | Delete
mtime = int(os.stat(fullname).st_mtime)
[86] Fix | Delete
expect = struct.pack('<4sl', imp.get_magic(), mtime)
[87] Fix | Delete
cfile = fullname + (__debug__ and 'c' or 'o')
[88] Fix | Delete
with open(cfile, 'rb') as chandle:
[89] Fix | Delete
actual = chandle.read(8)
[90] Fix | Delete
if expect == actual:
[91] Fix | Delete
return success
[92] Fix | Delete
except IOError:
[93] Fix | Delete
pass
[94] Fix | Delete
if not quiet:
[95] Fix | Delete
print 'Compiling', fullname, '...'
[96] Fix | Delete
try:
[97] Fix | Delete
ok = py_compile.compile(fullname, None, dfile, True)
[98] Fix | Delete
except py_compile.PyCompileError,err:
[99] Fix | Delete
if quiet:
[100] Fix | Delete
print 'Compiling', fullname, '...'
[101] Fix | Delete
print err.msg
[102] Fix | Delete
success = 0
[103] Fix | Delete
except IOError, e:
[104] Fix | Delete
print "Sorry", e
[105] Fix | Delete
success = 0
[106] Fix | Delete
else:
[107] Fix | Delete
if ok == 0:
[108] Fix | Delete
success = 0
[109] Fix | Delete
return success
[110] Fix | Delete
[111] Fix | Delete
def compile_path(skip_curdir=1, maxlevels=0, force=0, quiet=0):
[112] Fix | Delete
"""Byte-compile all module on sys.path.
[113] Fix | Delete
[114] Fix | Delete
Arguments (all optional):
[115] Fix | Delete
[116] Fix | Delete
skip_curdir: if true, skip current directory (default true)
[117] Fix | Delete
maxlevels: max recursion level (default 0)
[118] Fix | Delete
force: as for compile_dir() (default 0)
[119] Fix | Delete
quiet: as for compile_dir() (default 0)
[120] Fix | Delete
"""
[121] Fix | Delete
success = 1
[122] Fix | Delete
for dir in sys.path:
[123] Fix | Delete
if (not dir or dir == os.curdir) and skip_curdir:
[124] Fix | Delete
print 'Skipping current directory'
[125] Fix | Delete
else:
[126] Fix | Delete
success = success and compile_dir(dir, maxlevels, None,
[127] Fix | Delete
force, quiet=quiet)
[128] Fix | Delete
return success
[129] Fix | Delete
[130] Fix | Delete
def expand_args(args, flist):
[131] Fix | Delete
"""read names in flist and append to args"""
[132] Fix | Delete
expanded = args[:]
[133] Fix | Delete
if flist:
[134] Fix | Delete
try:
[135] Fix | Delete
if flist == '-':
[136] Fix | Delete
fd = sys.stdin
[137] Fix | Delete
else:
[138] Fix | Delete
fd = open(flist)
[139] Fix | Delete
while 1:
[140] Fix | Delete
line = fd.readline()
[141] Fix | Delete
if not line:
[142] Fix | Delete
break
[143] Fix | Delete
expanded.append(line[:-1])
[144] Fix | Delete
except IOError:
[145] Fix | Delete
print "Error reading file list %s" % flist
[146] Fix | Delete
raise
[147] Fix | Delete
return expanded
[148] Fix | Delete
[149] Fix | Delete
def main():
[150] Fix | Delete
"""Script main program."""
[151] Fix | Delete
import getopt
[152] Fix | Delete
try:
[153] Fix | Delete
opts, args = getopt.getopt(sys.argv[1:], 'lfqd:x:i:')
[154] Fix | Delete
except getopt.error, msg:
[155] Fix | Delete
print msg
[156] Fix | Delete
print "usage: python compileall.py [-l] [-f] [-q] [-d destdir] " \
[157] Fix | Delete
"[-x regexp] [-i list] [directory|file ...]"
[158] Fix | Delete
print
[159] Fix | Delete
print "arguments: zero or more file and directory names to compile; " \
[160] Fix | Delete
"if no arguments given, "
[161] Fix | Delete
print " defaults to the equivalent of -l sys.path"
[162] Fix | Delete
print
[163] Fix | Delete
print "options:"
[164] Fix | Delete
print "-l: don't recurse into subdirectories"
[165] Fix | Delete
print "-f: force rebuild even if timestamps are up-to-date"
[166] Fix | Delete
print "-q: output only error messages"
[167] Fix | Delete
print "-d destdir: directory to prepend to file paths for use in " \
[168] Fix | Delete
"compile-time tracebacks and in"
[169] Fix | Delete
print " runtime tracebacks in cases where the source " \
[170] Fix | Delete
"file is unavailable"
[171] Fix | Delete
print "-x regexp: skip files matching the regular expression regexp; " \
[172] Fix | Delete
"the regexp is searched for"
[173] Fix | Delete
print " in the full path of each file considered for " \
[174] Fix | Delete
"compilation"
[175] Fix | Delete
print "-i file: add all the files and directories listed in file to " \
[176] Fix | Delete
"the list considered for"
[177] Fix | Delete
print ' compilation; if "-", names are read from stdin'
[178] Fix | Delete
[179] Fix | Delete
sys.exit(2)
[180] Fix | Delete
maxlevels = 10
[181] Fix | Delete
ddir = None
[182] Fix | Delete
force = 0
[183] Fix | Delete
quiet = 0
[184] Fix | Delete
rx = None
[185] Fix | Delete
flist = None
[186] Fix | Delete
for o, a in opts:
[187] Fix | Delete
if o == '-l': maxlevels = 0
[188] Fix | Delete
if o == '-d': ddir = a
[189] Fix | Delete
if o == '-f': force = 1
[190] Fix | Delete
if o == '-q': quiet = 1
[191] Fix | Delete
if o == '-x':
[192] Fix | Delete
import re
[193] Fix | Delete
rx = re.compile(a)
[194] Fix | Delete
if o == '-i': flist = a
[195] Fix | Delete
if ddir:
[196] Fix | Delete
if len(args) != 1 and not os.path.isdir(args[0]):
[197] Fix | Delete
print "-d destdir require exactly one directory argument"
[198] Fix | Delete
sys.exit(2)
[199] Fix | Delete
success = 1
[200] Fix | Delete
try:
[201] Fix | Delete
if args or flist:
[202] Fix | Delete
try:
[203] Fix | Delete
if flist:
[204] Fix | Delete
args = expand_args(args, flist)
[205] Fix | Delete
except IOError:
[206] Fix | Delete
success = 0
[207] Fix | Delete
if success:
[208] Fix | Delete
for arg in args:
[209] Fix | Delete
if os.path.isdir(arg):
[210] Fix | Delete
if not compile_dir(arg, maxlevels, ddir,
[211] Fix | Delete
force, rx, quiet):
[212] Fix | Delete
success = 0
[213] Fix | Delete
else:
[214] Fix | Delete
if not compile_file(arg, ddir, force, rx, quiet):
[215] Fix | Delete
success = 0
[216] Fix | Delete
else:
[217] Fix | Delete
success = compile_path()
[218] Fix | Delete
except KeyboardInterrupt:
[219] Fix | Delete
print "\n[interrupted]"
[220] Fix | Delete
success = 0
[221] Fix | Delete
return success
[222] Fix | Delete
[223] Fix | Delete
if __name__ == '__main__':
[224] Fix | Delete
exit_status = int(not main())
[225] Fix | Delete
sys.exit(exit_status)
[226] Fix | Delete
[227] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function