mirror of
https://github.com/kennethreitz-archive/pyinstaller.git
synced 2026-06-05 07:36:12 +00:00
Reindenting python soucefiles.
git-svn-id: http://svn.pyinstaller.org/trunk@485 8dd32b29-ccff-0310-8a9a-9233e24343b1
This commit is contained in:
+1
-2
@@ -147,7 +147,7 @@ class ZlibArchive(archive.ZlibArchive):
|
||||
Check to see if the file object self.lib actually has a file
|
||||
we understand.
|
||||
"""
|
||||
self.lib.seek(self.start) #default - magic is at start of file
|
||||
self.lib.seek(self.start) #default - magic is at start of file
|
||||
if self.lib.read(len(self.MAGIC)) != self.MAGIC:
|
||||
raise RuntimeError, "%s is not a valid %s archive file" \
|
||||
% (self.path, self.__class__.__name__)
|
||||
@@ -157,4 +157,3 @@ class ZlibArchive(archive.ZlibArchive):
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
@@ -200,7 +200,7 @@ class Analysis(Target):
|
||||
paths[i] = absnormpath(paths[i])
|
||||
###################################################
|
||||
# Scan inputs and prepare:
|
||||
dirs = {} # input directories
|
||||
dirs = {} # input directories
|
||||
pynms = [] # python filenames with no extension
|
||||
for script in self.inputs:
|
||||
if not os.path.exists(script):
|
||||
|
||||
@@ -28,4 +28,3 @@ if len(sys.argv) < 2:
|
||||
else:
|
||||
vs = versionInfo.decode(sys.argv[1])
|
||||
print vs
|
||||
|
||||
|
||||
+3
-3
@@ -106,7 +106,7 @@ class Archive:
|
||||
Check to see if the file object self.lib actually has a file
|
||||
we understand.
|
||||
"""
|
||||
self.lib.seek(self.start) #default - magic is at start of file
|
||||
self.lib.seek(self.start) #default - magic is at start of file
|
||||
if self.lib.read(len(self.MAGIC)) != self.MAGIC:
|
||||
raise ArchiveReadError, "%s is not a valid %s archive file" \
|
||||
% (self.path, self.__class__.__name__)
|
||||
@@ -255,7 +255,7 @@ class Archive:
|
||||
assert ext in ('.pyc', '.pyo')
|
||||
self.toc[nm] = (ispkg, self.lib.tell())
|
||||
f = open(entry[1], 'rb')
|
||||
f.seek(8) #skip magic and timestamp
|
||||
f.seek(8) #skip magic and timestamp
|
||||
self.lib.write(f.read())
|
||||
|
||||
def save_toc(self, tocpos):
|
||||
@@ -345,7 +345,7 @@ class ZlibArchive(Archive):
|
||||
except (IOError, OSError):
|
||||
try:
|
||||
f = open(pth, 'rb')
|
||||
f.seek(8) #skip magic and timestamp
|
||||
f.seek(8) #skip magic and timestamp
|
||||
bytecode = f.read()
|
||||
marshal.loads(bytecode).co_filename # to make sure it's valid
|
||||
obj = zlib.compress(bytecode, self.LEVEL)
|
||||
|
||||
+89
-89
@@ -87,29 +87,29 @@ excludes = {'KERNEL32.DLL':1,
|
||||
excludesRe = re.compile('|'.join(excludes.keys()), re.I)
|
||||
|
||||
def getfullnameof(mod, xtrapath = None):
|
||||
"""Return the full path name of MOD.
|
||||
"""Return the full path name of MOD.
|
||||
|
||||
MOD is the basename of a dll or pyd.
|
||||
XTRAPATH is a path or list of paths to search first.
|
||||
Return the full path name of MOD.
|
||||
Will search the full Windows search path, as well as sys.path"""
|
||||
# Search sys.path first!
|
||||
epath = sys.path + getWindowsPath()
|
||||
if xtrapath is not None:
|
||||
if type(xtrapath) == type(''):
|
||||
epath.insert(0, xtrapath)
|
||||
else:
|
||||
epath = xtrapath + epath
|
||||
for p in epath:
|
||||
npth = os.path.join(p, mod)
|
||||
if os.path.exists(npth):
|
||||
return npth
|
||||
# second try: lower case filename
|
||||
MOD is the basename of a dll or pyd.
|
||||
XTRAPATH is a path or list of paths to search first.
|
||||
Return the full path name of MOD.
|
||||
Will search the full Windows search path, as well as sys.path"""
|
||||
# Search sys.path first!
|
||||
epath = sys.path + getWindowsPath()
|
||||
if xtrapath is not None:
|
||||
if type(xtrapath) == type(''):
|
||||
epath.insert(0, xtrapath)
|
||||
else:
|
||||
epath = xtrapath + epath
|
||||
for p in epath:
|
||||
npth = os.path.join(p, string.lower(mod))
|
||||
npth = os.path.join(p, mod)
|
||||
if os.path.exists(npth):
|
||||
return npth
|
||||
return ''
|
||||
# second try: lower case filename
|
||||
for p in epath:
|
||||
npth = os.path.join(p, string.lower(mod))
|
||||
if os.path.exists(npth):
|
||||
return npth
|
||||
return ''
|
||||
|
||||
def _getImports_dumpbin(pth):
|
||||
"""Find the binary dependencies of PTH.
|
||||
@@ -137,58 +137,58 @@ def _getImports_pe_x(pth):
|
||||
import struct
|
||||
rslt = []
|
||||
try:
|
||||
f = open(pth, 'rb').read()
|
||||
pehdrd = struct.unpack('l', f[60:64])[0] #after the MSDOS loader is the offset of the peheader
|
||||
magic = struct.unpack('l', f[pehdrd:pehdrd+4])[0] # pehdr starts with magic 'PE\000\000' (or 17744)
|
||||
# then 20 bytes of COFF header
|
||||
numsecs = struct.unpack('h', f[pehdrd+6:pehdrd+8])[0] # whence we get number of sections
|
||||
opthdrmagic = struct.unpack('h', f[pehdrd+24:pehdrd+26])[0]
|
||||
if opthdrmagic == 0x10b: # PE32 format
|
||||
numdictoffset = 116
|
||||
importoffset = 128
|
||||
elif opthdrmagic == 0x20b: # PE32+ format
|
||||
numdictoffset = 132
|
||||
importoffset = 148
|
||||
else:
|
||||
print "E: bindepend cannot analyze %s - unknown header format! %x" % (pth, opthdrmagic)
|
||||
return rslt
|
||||
numdirs = struct.unpack('l', f[pehdrd+numdictoffset:pehdrd+numdictoffset+4])[0]
|
||||
idata = ''
|
||||
if magic == 17744:
|
||||
importsec, sz = struct.unpack('2l', f[pehdrd+importoffset:pehdrd+importoffset+8])
|
||||
if sz == 0:
|
||||
return rslt
|
||||
secttbl = pehdrd + numdictoffset + 4 + 8*numdirs
|
||||
secttblfmt = '8s7l2h'
|
||||
seclist = []
|
||||
for i in range(numsecs):
|
||||
seclist.append(struct.unpack(secttblfmt, f[secttbl+i*40:secttbl+(i+1)*40]))
|
||||
#nm, vsz, va, rsz, praw, preloc, plnnums, qrelocs, qlnnums, flags \
|
||||
# = seclist[-1]
|
||||
for i in range(len(seclist)-1):
|
||||
if seclist[i][2] <= importsec < seclist[i+1][2]:
|
||||
break
|
||||
vbase = seclist[i][2]
|
||||
raw = seclist[i][4]
|
||||
idatastart = raw + importsec - vbase
|
||||
idata = f[idatastart:idatastart+seclist[i][1]]
|
||||
i = 0
|
||||
while 1:
|
||||
chunk = idata[i*20:(i+1)*20]
|
||||
if len(chunk) != 20:
|
||||
print "E: premature end of import table (chunk is %d, not 20)" % len(chunk)
|
||||
break
|
||||
vsa = struct.unpack('5l', chunk)[3]
|
||||
if vsa == 0:
|
||||
break
|
||||
sa = raw + vsa - vbase
|
||||
end = string.find(f, '\000', sa)
|
||||
nm = f[sa:end]
|
||||
if nm:
|
||||
rslt.append(nm)
|
||||
i = i + 1
|
||||
else:
|
||||
print "E: bindepend cannot analyze %s - file is not in PE format!" % pth
|
||||
f = open(pth, 'rb').read()
|
||||
pehdrd = struct.unpack('l', f[60:64])[0] #after the MSDOS loader is the offset of the peheader
|
||||
magic = struct.unpack('l', f[pehdrd:pehdrd+4])[0] # pehdr starts with magic 'PE\000\000' (or 17744)
|
||||
# then 20 bytes of COFF header
|
||||
numsecs = struct.unpack('h', f[pehdrd+6:pehdrd+8])[0] # whence we get number of sections
|
||||
opthdrmagic = struct.unpack('h', f[pehdrd+24:pehdrd+26])[0]
|
||||
if opthdrmagic == 0x10b: # PE32 format
|
||||
numdictoffset = 116
|
||||
importoffset = 128
|
||||
elif opthdrmagic == 0x20b: # PE32+ format
|
||||
numdictoffset = 132
|
||||
importoffset = 148
|
||||
else:
|
||||
print "E: bindepend cannot analyze %s - unknown header format! %x" % (pth, opthdrmagic)
|
||||
return rslt
|
||||
numdirs = struct.unpack('l', f[pehdrd+numdictoffset:pehdrd+numdictoffset+4])[0]
|
||||
idata = ''
|
||||
if magic == 17744:
|
||||
importsec, sz = struct.unpack('2l', f[pehdrd+importoffset:pehdrd+importoffset+8])
|
||||
if sz == 0:
|
||||
return rslt
|
||||
secttbl = pehdrd + numdictoffset + 4 + 8*numdirs
|
||||
secttblfmt = '8s7l2h'
|
||||
seclist = []
|
||||
for i in range(numsecs):
|
||||
seclist.append(struct.unpack(secttblfmt, f[secttbl+i*40:secttbl+(i+1)*40]))
|
||||
#nm, vsz, va, rsz, praw, preloc, plnnums, qrelocs, qlnnums, flags \
|
||||
# = seclist[-1]
|
||||
for i in range(len(seclist)-1):
|
||||
if seclist[i][2] <= importsec < seclist[i+1][2]:
|
||||
break
|
||||
vbase = seclist[i][2]
|
||||
raw = seclist[i][4]
|
||||
idatastart = raw + importsec - vbase
|
||||
idata = f[idatastart:idatastart+seclist[i][1]]
|
||||
i = 0
|
||||
while 1:
|
||||
chunk = idata[i*20:(i+1)*20]
|
||||
if len(chunk) != 20:
|
||||
print "E: premature end of import table (chunk is %d, not 20)" % len(chunk)
|
||||
break
|
||||
vsa = struct.unpack('5l', chunk)[3]
|
||||
if vsa == 0:
|
||||
break
|
||||
sa = raw + vsa - vbase
|
||||
end = string.find(f, '\000', sa)
|
||||
nm = f[sa:end]
|
||||
if nm:
|
||||
rslt.append(nm)
|
||||
i = i + 1
|
||||
else:
|
||||
print "E: bindepend cannot analyze %s - file is not in PE format!" % pth
|
||||
except IOError:
|
||||
print "E: bindepend cannot analyze %s - file not found!" % pth
|
||||
#except struct.error:
|
||||
@@ -264,23 +264,23 @@ def _getImports_pe(path):
|
||||
return dlls
|
||||
|
||||
def Dependencies(lTOC, platform=sys.platform, xtrapath=None):
|
||||
"""Expand LTOC to include all the closure of binary dependencies.
|
||||
"""Expand LTOC to include all the closure of binary dependencies.
|
||||
|
||||
LTOC is a logical table of contents, ie, a seq of tuples (name, path).
|
||||
Return LTOC expanded by all the binary dependencies of the entries
|
||||
in LTOC, except those listed in the module global EXCLUDES"""
|
||||
for nm, pth, typ in lTOC:
|
||||
fullnm = string.upper(os.path.basename(pth))
|
||||
if seen.get(string.upper(nm),0):
|
||||
continue
|
||||
#print "I: analyzing", pth
|
||||
seen[string.upper(nm)] = 1
|
||||
for lib, npth in selectImports(pth, platform, xtrapath):
|
||||
if seen.get(string.upper(lib),0):
|
||||
LTOC is a logical table of contents, ie, a seq of tuples (name, path).
|
||||
Return LTOC expanded by all the binary dependencies of the entries
|
||||
in LTOC, except those listed in the module global EXCLUDES"""
|
||||
for nm, pth, typ in lTOC:
|
||||
fullnm = string.upper(os.path.basename(pth))
|
||||
if seen.get(string.upper(nm),0):
|
||||
continue
|
||||
lTOC.append((lib, npth, 'BINARY'))
|
||||
#print "I: analyzing", pth
|
||||
seen[string.upper(nm)] = 1
|
||||
for lib, npth in selectImports(pth, platform, xtrapath):
|
||||
if seen.get(string.upper(lib),0):
|
||||
continue
|
||||
lTOC.append((lib, npth, 'BINARY'))
|
||||
|
||||
return lTOC
|
||||
return lTOC
|
||||
|
||||
def selectImports(pth, platform=sys.platform, xtrapath=None):
|
||||
"""Return the dependencies of a binary that should be included.
|
||||
@@ -297,7 +297,7 @@ def selectImports(pth, platform=sys.platform, xtrapath=None):
|
||||
iswin = platform[:3] == 'win'
|
||||
for lib in dlls:
|
||||
if not iswin and not cygwin:
|
||||
# plain win case
|
||||
# plain win case
|
||||
npth = lib
|
||||
dir, lib = os.path.split(lib)
|
||||
if excludes.get(dir,0):
|
||||
@@ -305,7 +305,7 @@ def selectImports(pth, platform=sys.platform, xtrapath=None):
|
||||
else:
|
||||
# all other platforms
|
||||
npth = getfullnameof(lib, xtrapath)
|
||||
|
||||
|
||||
# now npth is a candidate lib
|
||||
# check again for excludes but with regex FIXME: split the list
|
||||
if excludesRe.search(npth):
|
||||
@@ -316,7 +316,7 @@ def selectImports(pth, platform=sys.platform, xtrapath=None):
|
||||
else:
|
||||
#print "I: inserting %20s <- %s" % (npth, pth)
|
||||
pass
|
||||
|
||||
|
||||
if npth:
|
||||
rv.append((lib, npth))
|
||||
else:
|
||||
@@ -453,7 +453,7 @@ if __name__ == "__main__":
|
||||
parser = OptionParser(usage="%prog [options] <executable_or_dynamic_library>")
|
||||
parser.add_option('--target-platform', default=sys.platform,
|
||||
help='Target platform, required for cross-bundling (default: current platform)')
|
||||
|
||||
|
||||
opts, args = parser.parse_args()
|
||||
if len (args) != 1:
|
||||
parser.error('Requires exactly one filename')
|
||||
|
||||
@@ -5,6 +5,3 @@ import pkg2
|
||||
import sys
|
||||
sys.modules[__name__] = pkg2
|
||||
from pkg2 import *
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,5 +2,3 @@
|
||||
|
||||
print " %s" % __doc__
|
||||
print " %s %s" % (__name__, __file__)
|
||||
|
||||
|
||||
@@ -3,4 +3,3 @@
|
||||
def a_func():
|
||||
return "a_func from pkg2.a"
|
||||
print "pkg2.a imported"
|
||||
|
||||
|
||||
@@ -59,8 +59,8 @@ def runtests(alltests, filters=None):
|
||||
print "*"*len(info)
|
||||
print info
|
||||
print "*"*len(info)
|
||||
build_python = open("python_exe.build", "w")
|
||||
build_python.write(sys.executable)
|
||||
build_python = open("python_exe.build", "w")
|
||||
build_python.write(sys.executable)
|
||||
build_python.close()
|
||||
if not filters:
|
||||
tests = alltests
|
||||
@@ -96,7 +96,7 @@ if __name__ == '__main__':
|
||||
normal_tests = glob.glob('test*[0-9].py')
|
||||
interactive_tests = glob.glob('test*[0-9]i.py')
|
||||
args = sys.argv[1:]
|
||||
|
||||
|
||||
if "-i" in args:
|
||||
print "Running interactive tests"
|
||||
tests = interactive_tests
|
||||
@@ -106,4 +106,3 @@ if __name__ == '__main__':
|
||||
|
||||
clean()
|
||||
runtests(tests)
|
||||
|
||||
|
||||
@@ -23,4 +23,3 @@ if sys.version_info[:2] >= (2, 5):
|
||||
print "test13 DONE"
|
||||
else:
|
||||
print "Python 2.5 test13 skipped"
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ print "test14 - Used to fail if _xmlplus is installed"
|
||||
|
||||
import sys
|
||||
if sys.version_info[:2] >= (2, 5):
|
||||
import subprocess
|
||||
import subprocess
|
||||
import xml.etree.ElementTree as ET
|
||||
print "#"*50
|
||||
print "xml.etree.ElementTree", dir(ET)
|
||||
@@ -35,4 +35,3 @@ if sys.version_info[:2] >= (2, 5):
|
||||
print "test14 DONE"
|
||||
else:
|
||||
print "Python 2.5 test14 skipped"
|
||||
|
||||
|
||||
@@ -32,4 +32,3 @@ if sys.version_info[:2] >= (2, 5):
|
||||
print "test15 DONE"
|
||||
else:
|
||||
print "Python 2.5 test14 skipped"
|
||||
|
||||
|
||||
@@ -32,4 +32,3 @@ else:
|
||||
# as in setuptools/site.py
|
||||
|
||||
print "test16 DONE"
|
||||
|
||||
|
||||
@@ -26,4 +26,3 @@ else:
|
||||
open(test6x.__file__, 'w').write(txt)
|
||||
reload(test6x)
|
||||
print "test6x.x is now", test6x.x
|
||||
|
||||
|
||||
@@ -29,4 +29,3 @@ t2.start()
|
||||
doit('main')
|
||||
t1.join()
|
||||
t2.join()
|
||||
|
||||
|
||||
+212
-212
@@ -18,9 +18,9 @@
|
||||
import archive
|
||||
import struct
|
||||
try:
|
||||
import zlib
|
||||
import zlib
|
||||
except ImportError:
|
||||
zlib = archive.DummyZlib()
|
||||
zlib = archive.DummyZlib()
|
||||
import sys
|
||||
if sys.version[0] == '1':
|
||||
import strop
|
||||
@@ -33,241 +33,241 @@ else:
|
||||
return s.split(delim, count)
|
||||
|
||||
class CTOC:
|
||||
"""A class encapsulating the table of contents of a CArchive.
|
||||
"""A class encapsulating the table of contents of a CArchive.
|
||||
|
||||
When written to disk, it is easily read from C."""
|
||||
ENTRYSTRUCT = '!iiiibc' #(structlen, dpos, dlen, ulen, flag, typcd) followed by name
|
||||
def __init__(self):
|
||||
self.data = []
|
||||
When written to disk, it is easily read from C."""
|
||||
ENTRYSTRUCT = '!iiiibc' #(structlen, dpos, dlen, ulen, flag, typcd) followed by name
|
||||
def __init__(self):
|
||||
self.data = []
|
||||
|
||||
def frombinary(self, s):
|
||||
"""Decode the binary string into an in memory list.
|
||||
def frombinary(self, s):
|
||||
"""Decode the binary string into an in memory list.
|
||||
|
||||
S is a binary string."""
|
||||
entrylen = struct.calcsize(self.ENTRYSTRUCT)
|
||||
p = 0
|
||||
while p<len(s):
|
||||
(slen, dpos, dlen, ulen, flag, typcd) = struct.unpack(self.ENTRYSTRUCT,
|
||||
s[p:p+entrylen])
|
||||
nmlen = slen - entrylen
|
||||
p = p + entrylen
|
||||
(nm,) = struct.unpack(`nmlen`+'s', s[p:p+nmlen])
|
||||
p = p + nmlen
|
||||
# version 4
|
||||
# self.data.append((dpos, dlen, ulen, flag, typcd, nm[:-1]))
|
||||
# version 5
|
||||
# nm may have up to 15 bytes of padding
|
||||
pos = find(nm, '\0')
|
||||
if pos < 0:
|
||||
self.data.append((dpos, dlen, ulen, flag, typcd, nm))
|
||||
else:
|
||||
self.data.append((dpos, dlen, ulen, flag, typcd, nm[:pos]))
|
||||
#end version 5
|
||||
S is a binary string."""
|
||||
entrylen = struct.calcsize(self.ENTRYSTRUCT)
|
||||
p = 0
|
||||
while p<len(s):
|
||||
(slen, dpos, dlen, ulen, flag, typcd) = struct.unpack(self.ENTRYSTRUCT,
|
||||
s[p:p+entrylen])
|
||||
nmlen = slen - entrylen
|
||||
p = p + entrylen
|
||||
(nm,) = struct.unpack(`nmlen`+'s', s[p:p+nmlen])
|
||||
p = p + nmlen
|
||||
# version 4
|
||||
# self.data.append((dpos, dlen, ulen, flag, typcd, nm[:-1]))
|
||||
# version 5
|
||||
# nm may have up to 15 bytes of padding
|
||||
pos = find(nm, '\0')
|
||||
if pos < 0:
|
||||
self.data.append((dpos, dlen, ulen, flag, typcd, nm))
|
||||
else:
|
||||
self.data.append((dpos, dlen, ulen, flag, typcd, nm[:pos]))
|
||||
#end version 5
|
||||
|
||||
|
||||
def tobinary(self):
|
||||
"""Return self as a binary string."""
|
||||
import string
|
||||
entrylen = struct.calcsize(self.ENTRYSTRUCT)
|
||||
rslt = []
|
||||
for (dpos, dlen, ulen, flag, typcd, nm) in self.data:
|
||||
nmlen = len(nm) + 1 # add 1 for a '\0'
|
||||
# version 4
|
||||
# rslt.append(struct.pack(self.ENTRYSTRUCT+`nmlen`+'s',
|
||||
# nmlen+entrylen, dpos, dlen, ulen, flag, typcd, nm+'\0'))
|
||||
# version 5
|
||||
# align to 16 byte boundary so xplatform C can read
|
||||
toclen = nmlen + entrylen
|
||||
if toclen % 16 == 0:
|
||||
pad = '\0'
|
||||
else:
|
||||
padlen = 16 - (toclen % 16)
|
||||
pad = '\0'*padlen
|
||||
nmlen = nmlen + padlen
|
||||
rslt.append(struct.pack(self.ENTRYSTRUCT+`nmlen`+'s',
|
||||
nmlen+entrylen, dpos, dlen, ulen, flag, typcd, nm+pad))
|
||||
# end version 5
|
||||
def tobinary(self):
|
||||
"""Return self as a binary string."""
|
||||
import string
|
||||
entrylen = struct.calcsize(self.ENTRYSTRUCT)
|
||||
rslt = []
|
||||
for (dpos, dlen, ulen, flag, typcd, nm) in self.data:
|
||||
nmlen = len(nm) + 1 # add 1 for a '\0'
|
||||
# version 4
|
||||
# rslt.append(struct.pack(self.ENTRYSTRUCT+`nmlen`+'s',
|
||||
# nmlen+entrylen, dpos, dlen, ulen, flag, typcd, nm+'\0'))
|
||||
# version 5
|
||||
# align to 16 byte boundary so xplatform C can read
|
||||
toclen = nmlen + entrylen
|
||||
if toclen % 16 == 0:
|
||||
pad = '\0'
|
||||
else:
|
||||
padlen = 16 - (toclen % 16)
|
||||
pad = '\0'*padlen
|
||||
nmlen = nmlen + padlen
|
||||
rslt.append(struct.pack(self.ENTRYSTRUCT+`nmlen`+'s',
|
||||
nmlen+entrylen, dpos, dlen, ulen, flag, typcd, nm+pad))
|
||||
# end version 5
|
||||
|
||||
return string.join(rslt, '')
|
||||
return string.join(rslt, '')
|
||||
|
||||
def add(self, dpos, dlen, ulen, flag, typcd, nm):
|
||||
"""Add an entry to the table of contents.
|
||||
def add(self, dpos, dlen, ulen, flag, typcd, nm):
|
||||
"""Add an entry to the table of contents.
|
||||
|
||||
DPOS is data position.
|
||||
DLEN is data length.
|
||||
ULEN is the uncompressed data len.
|
||||
FLAG says if the data is compressed.
|
||||
TYPCD is the "type" of the entry (used by the C code)
|
||||
NM is the entry's name."""
|
||||
self.data.append((dpos, dlen, ulen, flag, typcd, nm))
|
||||
DPOS is data position.
|
||||
DLEN is data length.
|
||||
ULEN is the uncompressed data len.
|
||||
FLAG says if the data is compressed.
|
||||
TYPCD is the "type" of the entry (used by the C code)
|
||||
NM is the entry's name."""
|
||||
self.data.append((dpos, dlen, ulen, flag, typcd, nm))
|
||||
|
||||
def get(self, ndx):
|
||||
"""return the toc entry (tuple) at index NDX"""
|
||||
return self.data[ndx]
|
||||
def get(self, ndx):
|
||||
"""return the toc entry (tuple) at index NDX"""
|
||||
return self.data[ndx]
|
||||
|
||||
def __getitem__(self, ndx):
|
||||
return self.data[ndx]
|
||||
def __getitem__(self, ndx):
|
||||
return self.data[ndx]
|
||||
|
||||
def find(self, name):
|
||||
"""Return the index of the toc entry with name NAME.
|
||||
def find(self, name):
|
||||
"""Return the index of the toc entry with name NAME.
|
||||
|
||||
Return -1 for failure."""
|
||||
for i in range(len(self.data)):
|
||||
if self.data[i][-1] == name:
|
||||
return i
|
||||
return -1
|
||||
Return -1 for failure."""
|
||||
for i in range(len(self.data)):
|
||||
if self.data[i][-1] == name:
|
||||
return i
|
||||
return -1
|
||||
|
||||
class CArchive(archive.Archive):
|
||||
"""An Archive subclass that an hold arbitrary data.
|
||||
"""An Archive subclass that an hold arbitrary data.
|
||||
|
||||
Easily handled from C or from Python."""
|
||||
MAGIC = 'MEI\014\013\012\013\016'
|
||||
HDRLEN = 0
|
||||
TOCTMPLT = CTOC
|
||||
TRLSTRUCT = '!8siiii'
|
||||
TRLLEN = 24
|
||||
LEVEL = 9
|
||||
def __init__(self, path=None, start=0, len=0):
|
||||
"""Constructor.
|
||||
Easily handled from C or from Python."""
|
||||
MAGIC = 'MEI\014\013\012\013\016'
|
||||
HDRLEN = 0
|
||||
TOCTMPLT = CTOC
|
||||
TRLSTRUCT = '!8siiii'
|
||||
TRLLEN = 24
|
||||
LEVEL = 9
|
||||
def __init__(self, path=None, start=0, len=0):
|
||||
"""Constructor.
|
||||
|
||||
PATH is path name of file (create an empty CArchive if path is None).
|
||||
START is the seekposition within PATH.
|
||||
LEN is the length of the CArchive (if 0, then read till EOF). """
|
||||
self.len = len
|
||||
archive.Archive.__init__(self, path, start)
|
||||
PATH is path name of file (create an empty CArchive if path is None).
|
||||
START is the seekposition within PATH.
|
||||
LEN is the length of the CArchive (if 0, then read till EOF). """
|
||||
self.len = len
|
||||
archive.Archive.__init__(self, path, start)
|
||||
|
||||
def checkmagic(self):
|
||||
"""Verify that self is a valid CArchive.
|
||||
def checkmagic(self):
|
||||
"""Verify that self is a valid CArchive.
|
||||
|
||||
Magic signature is at end of the archive."""
|
||||
#magic is at EOF; if we're embedded, we need to figure where that is
|
||||
if self.len:
|
||||
self.lib.seek(self.start+self.len, 0)
|
||||
else:
|
||||
self.lib.seek(0, 2)
|
||||
filelen = self.lib.tell()
|
||||
if self.len:
|
||||
self.lib.seek(self.start+self.len-self.TRLLEN, 0)
|
||||
else:
|
||||
self.lib.seek(-self.TRLLEN, 2)
|
||||
(magic, totallen, tocpos, toclen, pyvers) = struct.unpack(self.TRLSTRUCT,
|
||||
self.lib.read(self.TRLLEN))
|
||||
if magic != self.MAGIC:
|
||||
raise RuntimeError, "%s is not a valid %s archive file" \
|
||||
% (self.path, self.__class__.__name__)
|
||||
self.pkgstart = filelen - totallen
|
||||
if self.len:
|
||||
if totallen != self.len or self.pkgstart != self.start:
|
||||
raise RuntimeError, "Problem with embedded archive in %s" % self.path
|
||||
self.tocpos, self.toclen = tocpos, toclen
|
||||
Magic signature is at end of the archive."""
|
||||
#magic is at EOF; if we're embedded, we need to figure where that is
|
||||
if self.len:
|
||||
self.lib.seek(self.start+self.len, 0)
|
||||
else:
|
||||
self.lib.seek(0, 2)
|
||||
filelen = self.lib.tell()
|
||||
if self.len:
|
||||
self.lib.seek(self.start+self.len-self.TRLLEN, 0)
|
||||
else:
|
||||
self.lib.seek(-self.TRLLEN, 2)
|
||||
(magic, totallen, tocpos, toclen, pyvers) = struct.unpack(self.TRLSTRUCT,
|
||||
self.lib.read(self.TRLLEN))
|
||||
if magic != self.MAGIC:
|
||||
raise RuntimeError, "%s is not a valid %s archive file" \
|
||||
% (self.path, self.__class__.__name__)
|
||||
self.pkgstart = filelen - totallen
|
||||
if self.len:
|
||||
if totallen != self.len or self.pkgstart != self.start:
|
||||
raise RuntimeError, "Problem with embedded archive in %s" % self.path
|
||||
self.tocpos, self.toclen = tocpos, toclen
|
||||
|
||||
def loadtoc(self):
|
||||
"""Load the table of contents into memory."""
|
||||
self.toc = self.TOCTMPLT()
|
||||
self.lib.seek(self.pkgstart+self.tocpos)
|
||||
tocstr = self.lib.read(self.toclen)
|
||||
self.toc.frombinary(tocstr)
|
||||
def loadtoc(self):
|
||||
"""Load the table of contents into memory."""
|
||||
self.toc = self.TOCTMPLT()
|
||||
self.lib.seek(self.pkgstart+self.tocpos)
|
||||
tocstr = self.lib.read(self.toclen)
|
||||
self.toc.frombinary(tocstr)
|
||||
|
||||
def extract(self, name):
|
||||
"""Get the contents of an entry.
|
||||
def extract(self, name):
|
||||
"""Get the contents of an entry.
|
||||
|
||||
NAME is an entry name.
|
||||
Return the tuple (ispkg, contents).
|
||||
For non-Python resoures, ispkg is meaningless (and 0).
|
||||
Used by the import mechanism."""
|
||||
if type(name) == type(''):
|
||||
ndx = self.toc.find(name)
|
||||
if ndx == -1:
|
||||
return None
|
||||
else:
|
||||
ndx = name
|
||||
(dpos, dlen, ulen, flag, typcd, nm) = self.toc.get(ndx)
|
||||
self.lib.seek(self.pkgstart+dpos)
|
||||
rslt = self.lib.read(dlen)
|
||||
if flag == 1:
|
||||
rslt = zlib.decompress(rslt)
|
||||
if typcd == 'M':
|
||||
return (1, rslt)
|
||||
return (0, rslt)
|
||||
NAME is an entry name.
|
||||
Return the tuple (ispkg, contents).
|
||||
For non-Python resoures, ispkg is meaningless (and 0).
|
||||
Used by the import mechanism."""
|
||||
if type(name) == type(''):
|
||||
ndx = self.toc.find(name)
|
||||
if ndx == -1:
|
||||
return None
|
||||
else:
|
||||
ndx = name
|
||||
(dpos, dlen, ulen, flag, typcd, nm) = self.toc.get(ndx)
|
||||
self.lib.seek(self.pkgstart+dpos)
|
||||
rslt = self.lib.read(dlen)
|
||||
if flag == 1:
|
||||
rslt = zlib.decompress(rslt)
|
||||
if typcd == 'M':
|
||||
return (1, rslt)
|
||||
return (0, rslt)
|
||||
|
||||
def contents(self):
|
||||
"""Return the names of the entries"""
|
||||
rslt = []
|
||||
for (dpos, dlen, ulen, flag, typcd, nm) in self.toc:
|
||||
rslt.append(nm)
|
||||
return rslt
|
||||
def contents(self):
|
||||
"""Return the names of the entries"""
|
||||
rslt = []
|
||||
for (dpos, dlen, ulen, flag, typcd, nm) in self.toc:
|
||||
rslt.append(nm)
|
||||
return rslt
|
||||
|
||||
def add(self, entry):
|
||||
"""Add an ENTRY to the CArchive.
|
||||
def add(self, entry):
|
||||
"""Add an ENTRY to the CArchive.
|
||||
|
||||
ENTRY must have:
|
||||
entry[0] is name (under which it will be saved).
|
||||
entry[1] is fullpathname of the file.
|
||||
entry[2] is a flag for it's storage format (0==uncompressed,
|
||||
1==compressed)
|
||||
entry[3] is the entry's type code.
|
||||
Version 5:
|
||||
If the type code is 'o':
|
||||
entry[0] is the runtime option
|
||||
eg: v (meaning verbose imports)
|
||||
u (menaing unbuffered)
|
||||
W arg (warning option arg)
|
||||
s (meaning do site.py processing."""
|
||||
(nm, pathnm, flag, typcd) = entry[:4]
|
||||
# version 5 - allow type 'o' = runtime option
|
||||
try:
|
||||
if typcd == 'o':
|
||||
s = ''
|
||||
flag = 0
|
||||
elif typcd == 's':
|
||||
# If it's a source code file, add \0 terminator as it will be
|
||||
# executed as-is by the bootloader.
|
||||
s = open(pathnm, 'r').read()
|
||||
s = s + '\n\0'
|
||||
else:
|
||||
s = open(pathnm, 'rb').read()
|
||||
except IOError:
|
||||
print "Cannot find ('%s', '%s', %s, '%s')" % (nm, pathnm, flag, typcd)
|
||||
raise
|
||||
ulen = len(s)
|
||||
if flag == 1:
|
||||
s = zlib.compress(s, self.LEVEL)
|
||||
dlen = len(s)
|
||||
where = self.lib.tell()
|
||||
if typcd == 'm':
|
||||
if find(pathnm, '.__init__.py') > -1:
|
||||
typcd = 'M'
|
||||
self.toc.add(where, dlen, ulen, flag, typcd, nm)
|
||||
self.lib.write(s)
|
||||
ENTRY must have:
|
||||
entry[0] is name (under which it will be saved).
|
||||
entry[1] is fullpathname of the file.
|
||||
entry[2] is a flag for it's storage format (0==uncompressed,
|
||||
1==compressed)
|
||||
entry[3] is the entry's type code.
|
||||
Version 5:
|
||||
If the type code is 'o':
|
||||
entry[0] is the runtime option
|
||||
eg: v (meaning verbose imports)
|
||||
u (menaing unbuffered)
|
||||
W arg (warning option arg)
|
||||
s (meaning do site.py processing."""
|
||||
(nm, pathnm, flag, typcd) = entry[:4]
|
||||
# version 5 - allow type 'o' = runtime option
|
||||
try:
|
||||
if typcd == 'o':
|
||||
s = ''
|
||||
flag = 0
|
||||
elif typcd == 's':
|
||||
# If it's a source code file, add \0 terminator as it will be
|
||||
# executed as-is by the bootloader.
|
||||
s = open(pathnm, 'r').read()
|
||||
s = s + '\n\0'
|
||||
else:
|
||||
s = open(pathnm, 'rb').read()
|
||||
except IOError:
|
||||
print "Cannot find ('%s', '%s', %s, '%s')" % (nm, pathnm, flag, typcd)
|
||||
raise
|
||||
ulen = len(s)
|
||||
if flag == 1:
|
||||
s = zlib.compress(s, self.LEVEL)
|
||||
dlen = len(s)
|
||||
where = self.lib.tell()
|
||||
if typcd == 'm':
|
||||
if find(pathnm, '.__init__.py') > -1:
|
||||
typcd = 'M'
|
||||
self.toc.add(where, dlen, ulen, flag, typcd, nm)
|
||||
self.lib.write(s)
|
||||
|
||||
def save_toc(self, tocpos):
|
||||
"""Save the table of contents to disk."""
|
||||
self.tocpos = tocpos
|
||||
tocstr = self.toc.tobinary()
|
||||
self.toclen = len(tocstr)
|
||||
self.lib.write(tocstr)
|
||||
def save_toc(self, tocpos):
|
||||
"""Save the table of contents to disk."""
|
||||
self.tocpos = tocpos
|
||||
tocstr = self.toc.tobinary()
|
||||
self.toclen = len(tocstr)
|
||||
self.lib.write(tocstr)
|
||||
|
||||
def save_trailer(self, tocpos):
|
||||
"""Save the trailer to disk.
|
||||
def save_trailer(self, tocpos):
|
||||
"""Save the trailer to disk.
|
||||
|
||||
CArchives can be opened from the end - the trailer points
|
||||
back to the start. """
|
||||
totallen = tocpos + self.toclen + self.TRLLEN
|
||||
if hasattr(sys, "version_info"):
|
||||
pyvers = sys.version_info[0]*10 + sys.version_info[1]
|
||||
else:
|
||||
toks = split(sys.version, '.', 2)
|
||||
pyvers = int(toks[0])*10 + int(toks[1])
|
||||
trl = struct.pack(self.TRLSTRUCT, self.MAGIC, totallen,
|
||||
tocpos, self.toclen, pyvers)
|
||||
self.lib.write(trl)
|
||||
CArchives can be opened from the end - the trailer points
|
||||
back to the start. """
|
||||
totallen = tocpos + self.toclen + self.TRLLEN
|
||||
if hasattr(sys, "version_info"):
|
||||
pyvers = sys.version_info[0]*10 + sys.version_info[1]
|
||||
else:
|
||||
toks = split(sys.version, '.', 2)
|
||||
pyvers = int(toks[0])*10 + int(toks[1])
|
||||
trl = struct.pack(self.TRLSTRUCT, self.MAGIC, totallen,
|
||||
tocpos, self.toclen, pyvers)
|
||||
self.lib.write(trl)
|
||||
|
||||
def openEmbedded(self, name):
|
||||
"""Open a CArchive of name NAME embedded within this CArchive."""
|
||||
ndx = self.toc.find(name)
|
||||
if ndx == -1:
|
||||
raise KeyError, "Member '%s' not found in %s" % (name, self.path)
|
||||
(dpos, dlen, ulen, flag, typcd, nm) = self.toc.get(ndx)
|
||||
if flag:
|
||||
raise ValueError, "Cannot open compressed archive %s in place"
|
||||
return CArchive(self.path, self.pkgstart+dpos, dlen)
|
||||
def openEmbedded(self, name):
|
||||
"""Open a CArchive of name NAME embedded within this CArchive."""
|
||||
ndx = self.toc.find(name)
|
||||
if ndx == -1:
|
||||
raise KeyError, "Member '%s' not found in %s" % (name, self.path)
|
||||
(dpos, dlen, ulen, flag, typcd, nm) = self.toc.get(ndx)
|
||||
if flag:
|
||||
raise ValueError, "Cannot open compressed archive %s in place"
|
||||
return CArchive(self.path, self.pkgstart+dpos, dlen)
|
||||
|
||||
@@ -31,18 +31,18 @@ import os
|
||||
import os.path
|
||||
import copy
|
||||
try:
|
||||
import docutils
|
||||
from docutils import ApplicationError
|
||||
from docutils import core, frontend
|
||||
from docutils.parsers import rst
|
||||
from docutils.readers import standalone, pep
|
||||
from docutils.writers import html4css1, pep_html
|
||||
import docutils
|
||||
from docutils import ApplicationError
|
||||
from docutils import core, frontend
|
||||
from docutils.parsers import rst
|
||||
from docutils.readers import standalone, pep
|
||||
from docutils.writers import html4css1, pep_html
|
||||
except:
|
||||
print "################################################################"
|
||||
print "# You need 'docutils' installed to execute this program. #"
|
||||
print "# 'docutils' is available from http://docutils.sourceforge.net #"
|
||||
print "################################################################"
|
||||
sys.exit(1)
|
||||
print "################################################################"
|
||||
print "# You need 'docutils' installed to execute this program. #"
|
||||
print "# 'docutils' is available from http://docutils.sourceforge.net #"
|
||||
print "################################################################"
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
usage = '%prog [options] [<directory> ...]'
|
||||
|
||||
+110
-110
@@ -16,139 +16,139 @@ from Tkinter import *
|
||||
# Basic Towers-of-Hanoi algorithm: move n pieces from a to b, using c
|
||||
# as temporary. For each move, call report()
|
||||
def hanoi(n, a, b, c, report):
|
||||
if n <= 0: return
|
||||
hanoi(n-1, a, c, b, report)
|
||||
report(n, a, b)
|
||||
hanoi(n-1, c, b, a, report)
|
||||
if n <= 0: return
|
||||
hanoi(n-1, a, c, b, report)
|
||||
report(n, a, b)
|
||||
hanoi(n-1, c, b, a, report)
|
||||
|
||||
|
||||
# The graphical interface
|
||||
class Tkhanoi:
|
||||
|
||||
# Create our objects
|
||||
def __init__(self, n, bitmap = None):
|
||||
self.n = n
|
||||
self.tk = tk = Tk()
|
||||
self.canvas = c = Canvas(tk)
|
||||
c.pack()
|
||||
width, height = tk.getint(c['width']), tk.getint(c['height'])
|
||||
# Create our objects
|
||||
def __init__(self, n, bitmap = None):
|
||||
self.n = n
|
||||
self.tk = tk = Tk()
|
||||
self.canvas = c = Canvas(tk)
|
||||
c.pack()
|
||||
width, height = tk.getint(c['width']), tk.getint(c['height'])
|
||||
|
||||
# Add background bitmap
|
||||
if bitmap:
|
||||
self.bitmap = c.create_bitmap(width/2, height/2,
|
||||
bitmap=bitmap,
|
||||
foreground='blue')
|
||||
# Add background bitmap
|
||||
if bitmap:
|
||||
self.bitmap = c.create_bitmap(width/2, height/2,
|
||||
bitmap=bitmap,
|
||||
foreground='blue')
|
||||
|
||||
# Generate pegs
|
||||
pegwidth = 10
|
||||
pegheight = height/2
|
||||
pegdist = width/3
|
||||
x1, y1 = (pegdist-pegwidth)/2, height*1/3
|
||||
x2, y2 = x1+pegwidth, y1+pegheight
|
||||
self.pegs = []
|
||||
p = c.create_rectangle(x1, y1, x2, y2, fill='black')
|
||||
self.pegs.append(p)
|
||||
x1, x2 = x1+pegdist, x2+pegdist
|
||||
p = c.create_rectangle(x1, y1, x2, y2, fill='black')
|
||||
self.pegs.append(p)
|
||||
x1, x2 = x1+pegdist, x2+pegdist
|
||||
p = c.create_rectangle(x1, y1, x2, y2, fill='black')
|
||||
self.pegs.append(p)
|
||||
self.tk.update()
|
||||
# Generate pegs
|
||||
pegwidth = 10
|
||||
pegheight = height/2
|
||||
pegdist = width/3
|
||||
x1, y1 = (pegdist-pegwidth)/2, height*1/3
|
||||
x2, y2 = x1+pegwidth, y1+pegheight
|
||||
self.pegs = []
|
||||
p = c.create_rectangle(x1, y1, x2, y2, fill='black')
|
||||
self.pegs.append(p)
|
||||
x1, x2 = x1+pegdist, x2+pegdist
|
||||
p = c.create_rectangle(x1, y1, x2, y2, fill='black')
|
||||
self.pegs.append(p)
|
||||
x1, x2 = x1+pegdist, x2+pegdist
|
||||
p = c.create_rectangle(x1, y1, x2, y2, fill='black')
|
||||
self.pegs.append(p)
|
||||
self.tk.update()
|
||||
|
||||
# Generate pieces
|
||||
pieceheight = pegheight/16
|
||||
maxpiecewidth = pegdist*2/3
|
||||
minpiecewidth = 2*pegwidth
|
||||
self.pegstate = [[], [], []]
|
||||
self.pieces = {}
|
||||
x1, y1 = (pegdist-maxpiecewidth)/2, y2-pieceheight-2
|
||||
x2, y2 = x1+maxpiecewidth, y1+pieceheight
|
||||
dx = (maxpiecewidth-minpiecewidth) / (2*max(1, n-1))
|
||||
for i in range(n, 0, -1):
|
||||
p = c.create_rectangle(x1, y1, x2, y2, fill='red')
|
||||
self.pieces[i] = p
|
||||
self.pegstate[0].append(i)
|
||||
x1, x2 = x1 + dx, x2-dx
|
||||
y1, y2 = y1 - pieceheight-2, y2-pieceheight-2
|
||||
self.tk.update()
|
||||
self.tk.after(25)
|
||||
# Generate pieces
|
||||
pieceheight = pegheight/16
|
||||
maxpiecewidth = pegdist*2/3
|
||||
minpiecewidth = 2*pegwidth
|
||||
self.pegstate = [[], [], []]
|
||||
self.pieces = {}
|
||||
x1, y1 = (pegdist-maxpiecewidth)/2, y2-pieceheight-2
|
||||
x2, y2 = x1+maxpiecewidth, y1+pieceheight
|
||||
dx = (maxpiecewidth-minpiecewidth) / (2*max(1, n-1))
|
||||
for i in range(n, 0, -1):
|
||||
p = c.create_rectangle(x1, y1, x2, y2, fill='red')
|
||||
self.pieces[i] = p
|
||||
self.pegstate[0].append(i)
|
||||
x1, x2 = x1 + dx, x2-dx
|
||||
y1, y2 = y1 - pieceheight-2, y2-pieceheight-2
|
||||
self.tk.update()
|
||||
self.tk.after(25)
|
||||
|
||||
# Run -- never returns
|
||||
def run(self):
|
||||
while 1:
|
||||
hanoi(self.n, 0, 1, 2, self.report)
|
||||
hanoi(self.n, 1, 2, 0, self.report)
|
||||
hanoi(self.n, 2, 0, 1, self.report)
|
||||
hanoi(self.n, 0, 2, 1, self.report)
|
||||
hanoi(self.n, 2, 1, 0, self.report)
|
||||
hanoi(self.n, 1, 0, 2, self.report)
|
||||
# Run -- never returns
|
||||
def run(self):
|
||||
while 1:
|
||||
hanoi(self.n, 0, 1, 2, self.report)
|
||||
hanoi(self.n, 1, 2, 0, self.report)
|
||||
hanoi(self.n, 2, 0, 1, self.report)
|
||||
hanoi(self.n, 0, 2, 1, self.report)
|
||||
hanoi(self.n, 2, 1, 0, self.report)
|
||||
hanoi(self.n, 1, 0, 2, self.report)
|
||||
|
||||
# Reporting callback for the actual hanoi function
|
||||
def report(self, i, a, b):
|
||||
if self.pegstate[a][-1] != i: raise RuntimeError # Assertion
|
||||
del self.pegstate[a][-1]
|
||||
p = self.pieces[i]
|
||||
c = self.canvas
|
||||
# Reporting callback for the actual hanoi function
|
||||
def report(self, i, a, b):
|
||||
if self.pegstate[a][-1] != i: raise RuntimeError # Assertion
|
||||
del self.pegstate[a][-1]
|
||||
p = self.pieces[i]
|
||||
c = self.canvas
|
||||
|
||||
# Lift the piece above peg a
|
||||
ax1, ay1, ax2, ay2 = c.bbox(self.pegs[a])
|
||||
while 1:
|
||||
x1, y1, x2, y2 = c.bbox(p)
|
||||
if y2 < ay1: break
|
||||
c.move(p, 0, -1)
|
||||
self.tk.update()
|
||||
# Lift the piece above peg a
|
||||
ax1, ay1, ax2, ay2 = c.bbox(self.pegs[a])
|
||||
while 1:
|
||||
x1, y1, x2, y2 = c.bbox(p)
|
||||
if y2 < ay1: break
|
||||
c.move(p, 0, -1)
|
||||
self.tk.update()
|
||||
|
||||
# Move it towards peg b
|
||||
bx1, by1, bx2, by2 = c.bbox(self.pegs[b])
|
||||
newcenter = (bx1+bx2)/2
|
||||
while 1:
|
||||
x1, y1, x2, y2 = c.bbox(p)
|
||||
center = (x1+x2)/2
|
||||
if center == newcenter: break
|
||||
if center > newcenter: c.move(p, -1, 0)
|
||||
else: c.move(p, 1, 0)
|
||||
self.tk.update()
|
||||
# Move it towards peg b
|
||||
bx1, by1, bx2, by2 = c.bbox(self.pegs[b])
|
||||
newcenter = (bx1+bx2)/2
|
||||
while 1:
|
||||
x1, y1, x2, y2 = c.bbox(p)
|
||||
center = (x1+x2)/2
|
||||
if center == newcenter: break
|
||||
if center > newcenter: c.move(p, -1, 0)
|
||||
else: c.move(p, 1, 0)
|
||||
self.tk.update()
|
||||
|
||||
# Move it down on top of the previous piece
|
||||
pieceheight = y2-y1
|
||||
newbottom = by2 - pieceheight*len(self.pegstate[b]) - 2
|
||||
while 1:
|
||||
x1, y1, x2, y2 = c.bbox(p)
|
||||
if y2 >= newbottom: break
|
||||
c.move(p, 0, 1)
|
||||
self.tk.update()
|
||||
# Move it down on top of the previous piece
|
||||
pieceheight = y2-y1
|
||||
newbottom = by2 - pieceheight*len(self.pegstate[b]) - 2
|
||||
while 1:
|
||||
x1, y1, x2, y2 = c.bbox(p)
|
||||
if y2 >= newbottom: break
|
||||
c.move(p, 0, 1)
|
||||
self.tk.update()
|
||||
|
||||
# Update peg state
|
||||
self.pegstate[b].append(i)
|
||||
# Update peg state
|
||||
self.pegstate[b].append(i)
|
||||
|
||||
|
||||
# Main program
|
||||
def main():
|
||||
import sys, string
|
||||
import sys, string
|
||||
|
||||
# First argument is number of pegs, default 4
|
||||
if sys.argv[1:]:
|
||||
n = string.atoi(sys.argv[1])
|
||||
else:
|
||||
n = 4
|
||||
# First argument is number of pegs, default 4
|
||||
if sys.argv[1:]:
|
||||
n = string.atoi(sys.argv[1])
|
||||
else:
|
||||
n = 4
|
||||
|
||||
# Second argument is bitmap file, default none
|
||||
if sys.argv[2:]:
|
||||
bitmap = sys.argv[2]
|
||||
# Reverse meaning of leading '@' compared to Tk
|
||||
if bitmap[0] == '@': bitmap = bitmap[1:]
|
||||
else: bitmap = '@' + bitmap
|
||||
else:
|
||||
bitmap = None
|
||||
# Second argument is bitmap file, default none
|
||||
if sys.argv[2:]:
|
||||
bitmap = sys.argv[2]
|
||||
# Reverse meaning of leading '@' compared to Tk
|
||||
if bitmap[0] == '@': bitmap = bitmap[1:]
|
||||
else: bitmap = '@' + bitmap
|
||||
else:
|
||||
bitmap = None
|
||||
|
||||
# Create the graphical objects...
|
||||
h = Tkhanoi(n, bitmap)
|
||||
# Create the graphical objects...
|
||||
h = Tkhanoi(n, bitmap)
|
||||
|
||||
# ...and run!
|
||||
h.run()
|
||||
# ...and run!
|
||||
h.run()
|
||||
|
||||
|
||||
# Call main when run as script
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
@@ -48,4 +48,3 @@ for bldconfig in ('--onedir', '--onefile'):
|
||||
else:
|
||||
os.system("ln -s /u/temp/t%d/hanoi hanoi%d" % (i,i))
|
||||
i += 1
|
||||
|
||||
|
||||
@@ -76,4 +76,3 @@ if __name__ == '__main__':
|
||||
import win32com.server.localserver
|
||||
win32com.server.localserver.main()
|
||||
raw_input("Press any key...")
|
||||
|
||||
|
||||
+127
-128
@@ -34,166 +34,165 @@ error = "MSOffice test error"
|
||||
|
||||
# Test a few of the MSOffice components.
|
||||
def TestWord():
|
||||
# Try and load the object exposed by Word 8
|
||||
# Office 97 - _totally_ different object model!
|
||||
try:
|
||||
# NOTE - using "client.Dispatch" would return an msword8.py instance!
|
||||
print "Starting Word 8 for dynamic test"
|
||||
word = win32com.client.dynamic.Dispatch("Word.Application")
|
||||
TestWord8(word)
|
||||
# Try and load the object exposed by Word 8
|
||||
# Office 97 - _totally_ different object model!
|
||||
try:
|
||||
# NOTE - using "client.Dispatch" would return an msword8.py instance!
|
||||
print "Starting Word 8 for dynamic test"
|
||||
word = win32com.client.dynamic.Dispatch("Word.Application")
|
||||
TestWord8(word)
|
||||
|
||||
word = None
|
||||
# Now we will test Dispatch without the new "lazy" capabilities
|
||||
print "Starting Word 8 for non-lazy dynamic test"
|
||||
dispatch = win32com.client.dynamic._GetGoodDispatch("Word.Application")
|
||||
typeinfo = dispatch.GetTypeInfo()
|
||||
attr = typeinfo.GetTypeAttr()
|
||||
olerepr = win32com.client.build.DispatchItem(typeinfo, attr, None, 0)
|
||||
word = win32com.client.dynamic.CDispatch(dispatch, olerepr)
|
||||
dispatch = typeinfo = attr = olerepr = None
|
||||
TestWord8(word)
|
||||
word = None
|
||||
# Now we will test Dispatch without the new "lazy" capabilities
|
||||
print "Starting Word 8 for non-lazy dynamic test"
|
||||
dispatch = win32com.client.dynamic._GetGoodDispatch("Word.Application")
|
||||
typeinfo = dispatch.GetTypeInfo()
|
||||
attr = typeinfo.GetTypeAttr()
|
||||
olerepr = win32com.client.build.DispatchItem(typeinfo, attr, None, 0)
|
||||
word = win32com.client.dynamic.CDispatch(dispatch, olerepr)
|
||||
dispatch = typeinfo = attr = olerepr = None
|
||||
TestWord8(word)
|
||||
|
||||
except pythoncom.com_error:
|
||||
print "Starting Word 7 for dynamic test"
|
||||
word = win32com.client.Dispatch("Word.Basic")
|
||||
TestWord7(word)
|
||||
except pythoncom.com_error:
|
||||
print "Starting Word 7 for dynamic test"
|
||||
word = win32com.client.Dispatch("Word.Basic")
|
||||
TestWord7(word)
|
||||
|
||||
try:
|
||||
print "Starting MSWord for generated test"
|
||||
# Typelib, lcid, major and minor for the typelib
|
||||
try:
|
||||
o = gencache.EnsureModule("{00020905-0000-0000-C000-000000000046}", 1033, 8, 0, bForDemand=1)
|
||||
except TypeError:
|
||||
o = gencache.EnsureModule("{00020905-0000-0000-C000-000000000046}", 1033, 8, 0)
|
||||
if o is None :
|
||||
raise ImportError, "Can not load the Word8 typelibrary."
|
||||
word = win32com.client.Dispatch("Word.Application.8")
|
||||
TestWord8(word)
|
||||
except ImportError, details:
|
||||
print "Can not test MSWord8 -", details
|
||||
try:
|
||||
print "Starting MSWord for generated test"
|
||||
# Typelib, lcid, major and minor for the typelib
|
||||
try:
|
||||
o = gencache.EnsureModule("{00020905-0000-0000-C000-000000000046}", 1033, 8, 0, bForDemand=1)
|
||||
except TypeError:
|
||||
o = gencache.EnsureModule("{00020905-0000-0000-C000-000000000046}", 1033, 8, 0)
|
||||
if o is None :
|
||||
raise ImportError, "Can not load the Word8 typelibrary."
|
||||
word = win32com.client.Dispatch("Word.Application.8")
|
||||
TestWord8(word)
|
||||
except ImportError, details:
|
||||
print "Can not test MSWord8 -", details
|
||||
|
||||
def TestWord7(word):
|
||||
word.FileNew()
|
||||
# If not shown, show the app.
|
||||
if not word.AppShow(): word._proc_("AppShow")
|
||||
word.FileNew()
|
||||
# If not shown, show the app.
|
||||
if not word.AppShow(): word._proc_("AppShow")
|
||||
|
||||
for i in xrange(12):
|
||||
word.FormatFont(Color=i+1, Points=i+12)
|
||||
word.Insert("Hello from Python %d\n" % i)
|
||||
for i in xrange(12):
|
||||
word.FormatFont(Color=i+1, Points=i+12)
|
||||
word.Insert("Hello from Python %d\n" % i)
|
||||
|
||||
word.FileClose(2)
|
||||
word.FileClose(2)
|
||||
|
||||
def TestWord8(word):
|
||||
word.Visible = 1
|
||||
doc = word.Documents.Add()
|
||||
wrange = doc.Range()
|
||||
for i in range(10):
|
||||
wrange.InsertAfter("Hello from Python %d\n" % i)
|
||||
paras = doc.Paragraphs
|
||||
for i in range(len(paras)):
|
||||
paras[i]().Font.ColorIndex = i+1
|
||||
paras[i]().Font.Size = 12 + (4 * i)
|
||||
# XXX - note that
|
||||
# for para in paras:
|
||||
# para().Font...
|
||||
# doesnt seem to work - no error, just doesnt work
|
||||
# Should check if it works for VB!
|
||||
doc.Close(SaveChanges = 0)
|
||||
word.Quit()
|
||||
win32api.Sleep(1000) # Wait for word to close, else we
|
||||
# may get OA error.
|
||||
word.Visible = 1
|
||||
doc = word.Documents.Add()
|
||||
wrange = doc.Range()
|
||||
for i in range(10):
|
||||
wrange.InsertAfter("Hello from Python %d\n" % i)
|
||||
paras = doc.Paragraphs
|
||||
for i in range(len(paras)):
|
||||
paras[i]().Font.ColorIndex = i+1
|
||||
paras[i]().Font.Size = 12 + (4 * i)
|
||||
# XXX - note that
|
||||
# for para in paras:
|
||||
# para().Font...
|
||||
# doesnt seem to work - no error, just doesnt work
|
||||
# Should check if it works for VB!
|
||||
doc.Close(SaveChanges = 0)
|
||||
word.Quit()
|
||||
win32api.Sleep(1000) # Wait for word to close, else we
|
||||
# may get OA error.
|
||||
|
||||
def TestWord8OldStyle():
|
||||
try:
|
||||
import win32com.test.Generated4Test.msword8
|
||||
except ImportError:
|
||||
print "Can not do old style test"
|
||||
try:
|
||||
import win32com.test.Generated4Test.msword8
|
||||
except ImportError:
|
||||
print "Can not do old style test"
|
||||
|
||||
|
||||
def TextExcel(xl):
|
||||
xl.Visible = 0
|
||||
if xl.Visible: raise error, "Visible property is true."
|
||||
xl.Visible = 1
|
||||
if not xl.Visible: raise error, "Visible property not true."
|
||||
xl.Visible = 0
|
||||
if xl.Visible: raise error, "Visible property is true."
|
||||
xl.Visible = 1
|
||||
if not xl.Visible: raise error, "Visible property not true."
|
||||
|
||||
if int(xl.Version[0])>=8:
|
||||
xl.Workbooks.Add()
|
||||
else:
|
||||
xl.Workbooks().Add()
|
||||
if int(xl.Version[0])>=8:
|
||||
xl.Workbooks.Add()
|
||||
else:
|
||||
xl.Workbooks().Add()
|
||||
|
||||
|
||||
xl.Range("A1:C1").Value = (1,2,3)
|
||||
xl.Range("A2:C2").Value = ('x','y','z')
|
||||
xl.Range("A3:C3").Value = ('3','2','1')
|
||||
xl.Range("A1:C1").Value = (1,2,3)
|
||||
xl.Range("A2:C2").Value = ('x','y','z')
|
||||
xl.Range("A3:C3").Value = ('3','2','1')
|
||||
|
||||
for i in xrange(20):
|
||||
xl.Cells(i+1,i+1).Value = "Hi %d" % i
|
||||
for i in xrange(20):
|
||||
xl.Cells(i+1,i+1).Value = "Hi %d" % i
|
||||
|
||||
if xl.Range("A1").Value <> "Hi 0":
|
||||
raise error, "Single cell range failed"
|
||||
if xl.Range("A1").Value <> "Hi 0":
|
||||
raise error, "Single cell range failed"
|
||||
|
||||
if xl.Range("A1:B1").Value <> ((Unicode("Hi 0"),2),):
|
||||
raise error, "flat-horizontal cell range failed"
|
||||
if xl.Range("A1:B1").Value <> ((Unicode("Hi 0"),2),):
|
||||
raise error, "flat-horizontal cell range failed"
|
||||
|
||||
if xl.Range("A1:A2").Value <> ((Unicode("Hi 0"),),(Unicode("x"),)):
|
||||
raise error, "flat-vertical cell range failed"
|
||||
if xl.Range("A1:A2").Value <> ((Unicode("Hi 0"),),(Unicode("x"),)):
|
||||
raise error, "flat-vertical cell range failed"
|
||||
|
||||
if xl.Range("A1:C3").Value <> ((Unicode("Hi 0"),2,3),(Unicode("x"),Unicode("Hi 1"),Unicode("z")),(3,2,Unicode("Hi 2"))):
|
||||
raise error, "square cell range failed"
|
||||
if xl.Range("A1:C3").Value <> ((Unicode("Hi 0"),2,3),(Unicode("x"),Unicode("Hi 1"),Unicode("z")),(3,2,Unicode("Hi 2"))):
|
||||
raise error, "square cell range failed"
|
||||
|
||||
xl.Range("A1:C3").Value =((3,2,1),("x","y","z"),(1,2,3))
|
||||
xl.Range("A1:C3").Value =((3,2,1),("x","y","z"),(1,2,3))
|
||||
|
||||
if xl.Range("A1:C3").Value <> ((3,2,1),(Unicode("x"),Unicode("y"),Unicode("z")),(1,2,3)):
|
||||
raise error, "Range was not what I set it to!"
|
||||
if xl.Range("A1:C3").Value <> ((3,2,1),(Unicode("x"),Unicode("y"),Unicode("z")),(1,2,3)):
|
||||
raise error, "Range was not what I set it to!"
|
||||
|
||||
# test dates out with Excel
|
||||
xl.Cells(5,1).Value = "Excel time"
|
||||
xl.Cells(5,2).Formula = "=Now()"
|
||||
# test dates out with Excel
|
||||
xl.Cells(5,1).Value = "Excel time"
|
||||
xl.Cells(5,2).Formula = "=Now()"
|
||||
|
||||
import time
|
||||
xl.Cells(6,1).Value = "Python time"
|
||||
xl.Cells(6,2).Value = pythoncom.MakeTime(time.time())
|
||||
xl.Cells(6,2).NumberFormat = "d/mm/yy h:mm"
|
||||
xl.Columns("A:B").EntireColumn.AutoFit()
|
||||
import time
|
||||
xl.Cells(6,1).Value = "Python time"
|
||||
xl.Cells(6,2).Value = pythoncom.MakeTime(time.time())
|
||||
xl.Cells(6,2).NumberFormat = "d/mm/yy h:mm"
|
||||
xl.Columns("A:B").EntireColumn.AutoFit()
|
||||
|
||||
xl.Workbooks(1).Close(0)
|
||||
xl.Quit()
|
||||
xl.Workbooks(1).Close(0)
|
||||
xl.Quit()
|
||||
|
||||
def TestAll():
|
||||
try:
|
||||
TestWord()
|
||||
try:
|
||||
TestWord()
|
||||
|
||||
print "Starting Excel for Dynamic test..."
|
||||
xl = win32com.client.dynamic.Dispatch("Excel.Application")
|
||||
TextExcel(xl)
|
||||
print "Starting Excel for Dynamic test..."
|
||||
xl = win32com.client.dynamic.Dispatch("Excel.Application")
|
||||
TextExcel(xl)
|
||||
|
||||
try:
|
||||
print "Starting Excel 8 for generated excel8.py test..."
|
||||
try:
|
||||
mod = gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 0, 1, 2, bForDemand=1)
|
||||
except TypeError:
|
||||
mod = gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 0, 1, 2)
|
||||
xl = win32com.client.Dispatch("Excel.Application")
|
||||
TextExcel(xl)
|
||||
except ImportError:
|
||||
print "Could not import the generated Excel 97 wrapper"
|
||||
try:
|
||||
print "Starting Excel 8 for generated excel8.py test..."
|
||||
try:
|
||||
mod = gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 0, 1, 2, bForDemand=1)
|
||||
except TypeError:
|
||||
mod = gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 0, 1, 2)
|
||||
xl = win32com.client.Dispatch("Excel.Application")
|
||||
TextExcel(xl)
|
||||
except ImportError:
|
||||
print "Could not import the generated Excel 97 wrapper"
|
||||
|
||||
try:
|
||||
import xl5en32
|
||||
mod = gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 9, 1, 0)
|
||||
xl = win32com.client.Dispatch("Excel.Application.5")
|
||||
print "Starting Excel 95 for makepy test..."
|
||||
TextExcel(xl)
|
||||
except ImportError:
|
||||
print "Could not import the generated Excel 95 wrapper"
|
||||
try:
|
||||
import xl5en32
|
||||
mod = gencache.EnsureModule("{00020813-0000-0000-C000-000000000046}", 9, 1, 0)
|
||||
xl = win32com.client.Dispatch("Excel.Application.5")
|
||||
print "Starting Excel 95 for makepy test..."
|
||||
TextExcel(xl)
|
||||
except ImportError:
|
||||
print "Could not import the generated Excel 95 wrapper"
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print "*** Interrupted MSOffice test ***"
|
||||
except:
|
||||
traceback.print_exc()
|
||||
except KeyboardInterrupt:
|
||||
print "*** Interrupted MSOffice test ***"
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
||||
if __name__=='__main__':
|
||||
TestAll()
|
||||
CheckClean()
|
||||
pythoncom.CoUninitialize()
|
||||
|
||||
TestAll()
|
||||
CheckClean()
|
||||
pythoncom.CoUninitialize()
|
||||
|
||||
@@ -22,4 +22,3 @@ def hook(mod):
|
||||
if mod.imports[i][0] == 'strop':
|
||||
del mod.imports[i]
|
||||
return mod
|
||||
|
||||
|
||||
@@ -36,4 +36,3 @@ def hook(mod):
|
||||
if nm in removes:
|
||||
del mod.imports[i]
|
||||
return mod
|
||||
|
||||
|
||||
@@ -41,4 +41,3 @@ def hook(mod):
|
||||
if nm in removes :
|
||||
del mod.imports[i]
|
||||
return mod
|
||||
|
||||
|
||||
@@ -36,4 +36,3 @@ def hook(mod):
|
||||
import mf
|
||||
mod = mf.ExtensionModule(newname, pth)
|
||||
return mod
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
# courtesy of David C. Morrill (4/2/2002)
|
||||
import os
|
||||
if os.name == 'posix':
|
||||
hiddenimports = ['libvtkCommonPython','libvtkFilteringPython','libvtkIOPython','libvtkImagingPython','libvtkGraphicsPython','libvtkRenderingPython','libvtkHybridPython','libvtkParallelPython','libvtkPatentedPython']
|
||||
hiddenimports = ['libvtkCommonPython','libvtkFilteringPython','libvtkIOPython','libvtkImagingPython','libvtkGraphicsPython','libvtkRenderingPython','libvtkHybridPython','libvtkParallelPython','libvtkPatentedPython']
|
||||
else:
|
||||
hiddenimports = ['vtkCommonPython','vtkFilteringPython','vtkIOPython','vtkImagingPython','vtkGraphicsPython','vtkRenderingPython','vtkHybridPython','vtkParallelPython','vtkPatentedPython']
|
||||
|
||||
hiddenimports = ['vtkCommonPython','vtkFilteringPython','vtkIOPython','vtkImagingPython','vtkGraphicsPython','vtkRenderingPython','vtkHybridPython','vtkParallelPython','vtkPatentedPython']
|
||||
|
||||
@@ -70,5 +70,3 @@ hiddenimports = ['xml.dom.html.HTMLAnchorElement',
|
||||
'xml.dom.html.HTMLTitleElement',
|
||||
'xml.dom.html.HTMLUListElement',
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -31,5 +31,3 @@ attrs = [('HTML_4_STRICT_INLINE',0),
|
||||
('TranslateHtmlCdata',0),
|
||||
('SECURE_HTML_ELEMS',0),
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -17,4 +17,3 @@
|
||||
|
||||
# cElementTree has a hidden import (Python >=2.5 stdlib version)
|
||||
hiddenimports = ['xml.etree.ElementTree']
|
||||
|
||||
|
||||
@@ -153,4 +153,3 @@ def CopyIcons (dstpath, srcpath):
|
||||
win32api.UpdateResource (hdst, RT_ICON, iconname, data)
|
||||
win32api.FreeLibrary (hsrc)
|
||||
win32api.EndUpdateResource (hdst, 0)
|
||||
|
||||
|
||||
@@ -602,7 +602,7 @@ def _string_bootstrap():
|
||||
def join(sep, words):
|
||||
res = ''
|
||||
for w in words:
|
||||
res = res + (sep + w)
|
||||
res = res + (sep + w)
|
||||
return res[len(sep):]
|
||||
_string_join = join
|
||||
|
||||
@@ -613,19 +613,19 @@ def _string_bootstrap():
|
||||
res = []
|
||||
nsep = len(sep)
|
||||
if nsep == 0:
|
||||
return [s]
|
||||
return [s]
|
||||
ns = len(s)
|
||||
if maxsplit <= 0: maxsplit = ns
|
||||
i = j = 0
|
||||
count = 0
|
||||
while j+nsep <= ns:
|
||||
if s[j:j+nsep] == sep:
|
||||
count = count + 1
|
||||
res.append(s[i:j])
|
||||
i = j = j + nsep
|
||||
if count >= maxsplit: break
|
||||
else:
|
||||
j = j + 1
|
||||
if s[j:j+nsep] == sep:
|
||||
count = count + 1
|
||||
res.append(s[i:j])
|
||||
i = j = j + nsep
|
||||
if count >= maxsplit: break
|
||||
else:
|
||||
j = j + 1
|
||||
res.append(s[i:])
|
||||
return res
|
||||
_string_split = split
|
||||
|
||||
@@ -243,7 +243,7 @@ class RegistryImportDirector(ImportDirector):
|
||||
stuff = open(fnm, 'rb').read()
|
||||
co = loadco(stuff[8:])
|
||||
return PyModule(nm, fnm, co)
|
||||
return None
|
||||
return None
|
||||
|
||||
class PathImportDirector(ImportDirector):
|
||||
def __init__(self, pathlist=None, importers=None, ownertypes=None):
|
||||
|
||||
+12
-12
@@ -34,10 +34,10 @@ import makemakefile
|
||||
import pprint
|
||||
|
||||
try:
|
||||
from distutils import sysconfig
|
||||
from distutils import sysconfig
|
||||
except:
|
||||
print "ERROR: distutils with sysconfig required"
|
||||
sys.exit(1)
|
||||
print "ERROR: distutils with sysconfig required"
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
True
|
||||
@@ -98,15 +98,15 @@ def main():
|
||||
config_h_dir = exec_prefix
|
||||
makefile_in = os.path.join(exec_prefix, 'Modules', 'Makefile')
|
||||
else:
|
||||
# binlib = os.path.join (sysconfig.get_python_lib(True, True, exec_prefix), 'config')
|
||||
binlib = sysconfig.get_config_vars('LIBDIR')[0]
|
||||
# TODO: Is it possible to have more than one path returned? if so fix "includes" list
|
||||
incldir_list = sysconfig.get_config_vars('INCLUDEDIR')
|
||||
includes = []
|
||||
for dir in incldir_list:
|
||||
if dir != None:
|
||||
includes.append('-I' + dir)
|
||||
config_h_dir = os.path.join (sysconfig.get_python_inc(True,exec_prefix))
|
||||
# binlib = os.path.join (sysconfig.get_python_lib(True, True, exec_prefix), 'config')
|
||||
binlib = sysconfig.get_config_vars('LIBDIR')[0]
|
||||
# TODO: Is it possible to have more than one path returned? if so fix "includes" list
|
||||
incldir_list = sysconfig.get_config_vars('INCLUDEDIR')
|
||||
includes = []
|
||||
for dir in incldir_list:
|
||||
if dir != None:
|
||||
includes.append('-I' + dir)
|
||||
config_h_dir = os.path.join (sysconfig.get_python_inc(True,exec_prefix))
|
||||
includes.append('-I' + config_h_dir)
|
||||
makefile_in = sysconfig.get_makefile_filename()
|
||||
|
||||
|
||||
+48
-48
@@ -18,54 +18,54 @@
|
||||
_orig_open = open
|
||||
|
||||
class _BkFile:
|
||||
def __init__(self, file, mode, bufsize):
|
||||
import os
|
||||
self.__filename = file
|
||||
self.__backup = file + '~'
|
||||
try:
|
||||
os.unlink(self.__backup)
|
||||
except os.error:
|
||||
pass
|
||||
try:
|
||||
os.rename(file, self.__backup)
|
||||
except os.error:
|
||||
self.__backup = None
|
||||
self.__file = _orig_open(file, mode, bufsize)
|
||||
self.closed = self.__file.closed
|
||||
self.fileno = self.__file.fileno
|
||||
self.flush = self.__file.flush
|
||||
self.isatty = self.__file.isatty
|
||||
self.mode = self.__file.mode
|
||||
self.name = self.__file.name
|
||||
self.read = self.__file.read
|
||||
self.readinto = self.__file.readinto
|
||||
self.readline = self.__file.readline
|
||||
self.readlines = self.__file.readlines
|
||||
self.seek = self.__file.seek
|
||||
self.softspace = self.__file.softspace
|
||||
self.tell = self.__file.tell
|
||||
self.truncate = self.__file.truncate
|
||||
self.write = self.__file.write
|
||||
self.writelines = self.__file.writelines
|
||||
def __init__(self, file, mode, bufsize):
|
||||
import os
|
||||
self.__filename = file
|
||||
self.__backup = file + '~'
|
||||
try:
|
||||
os.unlink(self.__backup)
|
||||
except os.error:
|
||||
pass
|
||||
try:
|
||||
os.rename(file, self.__backup)
|
||||
except os.error:
|
||||
self.__backup = None
|
||||
self.__file = _orig_open(file, mode, bufsize)
|
||||
self.closed = self.__file.closed
|
||||
self.fileno = self.__file.fileno
|
||||
self.flush = self.__file.flush
|
||||
self.isatty = self.__file.isatty
|
||||
self.mode = self.__file.mode
|
||||
self.name = self.__file.name
|
||||
self.read = self.__file.read
|
||||
self.readinto = self.__file.readinto
|
||||
self.readline = self.__file.readline
|
||||
self.readlines = self.__file.readlines
|
||||
self.seek = self.__file.seek
|
||||
self.softspace = self.__file.softspace
|
||||
self.tell = self.__file.tell
|
||||
self.truncate = self.__file.truncate
|
||||
self.write = self.__file.write
|
||||
self.writelines = self.__file.writelines
|
||||
|
||||
def close(self):
|
||||
self.__file.close()
|
||||
if self.__backup is None:
|
||||
return
|
||||
try:
|
||||
from cmp import do_cmp
|
||||
except:
|
||||
from filecmp import cmp
|
||||
do_cmp = cmp
|
||||
# don't use cmp.cmp because of NFS bugs :-( and
|
||||
# anyway, the stat mtime values differ so do_cmp will
|
||||
# most likely be called anyway
|
||||
if do_cmp(self.__backup, self.__filename):
|
||||
import os
|
||||
os.unlink(self.__filename)
|
||||
os.rename(self.__backup, self.__filename)
|
||||
def close(self):
|
||||
self.__file.close()
|
||||
if self.__backup is None:
|
||||
return
|
||||
try:
|
||||
from cmp import do_cmp
|
||||
except:
|
||||
from filecmp import cmp
|
||||
do_cmp = cmp
|
||||
# don't use cmp.cmp because of NFS bugs :-( and
|
||||
# anyway, the stat mtime values differ so do_cmp will
|
||||
# most likely be called anyway
|
||||
if do_cmp(self.__backup, self.__filename):
|
||||
import os
|
||||
os.unlink(self.__filename)
|
||||
os.rename(self.__backup, self.__filename)
|
||||
|
||||
def open(file, mode = 'r', bufsize = -1):
|
||||
if 'w' not in mode:
|
||||
return _orig_open(file, mode, bufsize)
|
||||
return _BkFile(file, mode, bufsize)
|
||||
if 'w' not in mode:
|
||||
return _orig_open(file, mode, bufsize)
|
||||
return _BkFile(file, mode, bufsize)
|
||||
|
||||
@@ -44,5 +44,3 @@ def writerules(outfp, files, suffix, dflag, target):
|
||||
outfp.write("\n%s: %s\n" % (target, string.join(deps)))
|
||||
outfp.write("\t$(CC) %s -o %s $(LDLAST)\n" %
|
||||
(string.join(files), target))
|
||||
|
||||
|
||||
|
||||
@@ -48,4 +48,3 @@ prvtdir = os.path.dirname(tcldir)
|
||||
if os.path.basename(prvtdir) == '_MEI':
|
||||
empty(prvtdir)
|
||||
os.rmdir(prvtdir)
|
||||
|
||||
|
||||
@@ -36,4 +36,3 @@ win32com.__gen_path__ = genpydir
|
||||
win32com.__path__.insert(0, supportdir)
|
||||
# for older Pythons
|
||||
import copy_reg
|
||||
|
||||
|
||||
@@ -37,4 +37,3 @@ for fnm in tk.contents():
|
||||
os.makedirs(dirnm)
|
||||
open(outnm, 'wb').write(stuff)
|
||||
tk = None
|
||||
|
||||
|
||||
@@ -528,4 +528,3 @@ if __name__ == '__main__':
|
||||
else:
|
||||
print "Examining", sys.argv[1]
|
||||
decode(sys.argv[1])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user