Commit 4a6646be authored by S. Zeid's avatar S. Zeid

remove binary blobs, ancient versions of PyInstaller, unnecessary executable...

remove binary blobs, ancient versions of PyInstaller, unnecessary executable flags, and other such bullshit
parent a56a60fe
#! /usr/bin/env python
# Viewer for archives packaged by archive.py
# Copyright (C) 2005, Giovanni Bajo
# Based on previous work under copyright (c) 2002 McMillan Enterprises, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import archive
import carchive
import sys, string, tempfile, os
try:
import zlib
except ImportError:
zlib = archive.DummyZlib()
import pprint
stack = []
cleanup = []
def main():
global stack
name = sys.argv[1]
arch = getArchive(name)
stack.append((name, arch))
show(name, arch)
while 1:
toks = string.split(raw_input('? '), ' ', 1)
if not toks:
usage()
continue
if len(toks) == 1:
cmd = toks[0]
arg = ''
else:
cmd, arg = toks
cmd = string.upper(cmd)
if cmd == 'U':
if len(stack) > 1:
arch = stack[-1][1]
arch.lib.close()
del stack[-1]
nm, arch = stack[-1]
show(nm, arch)
elif cmd == 'O':
if not arg:
arg = raw_input('open name? ')
arg = string.strip(arg)
arch = getArchive(arg)
if arch is None:
print arg, "not found"
continue
stack.append((arg, arch))
show(arg, arch)
elif cmd == 'X':
if not arg:
arg = raw_input('extract name? ')
arg = string.strip(arg)
data = getData(arg, arch)
if data is None:
print "Not found"
continue
fnm = raw_input('to filename? ')
if not fnm:
print `data`
else:
open(fnm, 'wb').write(data)
elif cmd == 'Q':
break
else:
usage()
for (nm, arch) in stack:
arch.lib.close()
stack = []
for fnm in cleanup:
try:
os.remove(fnm)
except Exception, e:
print "couldn't delete", fnm, e.args
def usage():
print "U: go Up one level"
print "O <nm>: open embedded archive nm"
print "X <nm>: extract nm"
print "Q: quit"
def getArchive(nm):
if not stack:
if string.lower(nm[-4:]) == '.pyz':
return ZlibArchive(nm)
return carchive.CArchive(nm)
parent = stack[-1][1]
try:
return parent.openEmbedded(nm)
except KeyError, e:
return None
except (ValueError, RuntimeError):
ndx = parent.toc.find(nm)
dpos, dlen, ulen, flag, typcd, nm = parent.toc[ndx]
x, data = parent.extract(ndx)
tfnm = tempfile.mktemp()
cleanup.append(tfnm)
open(tfnm, 'wb').write(data)
if typcd == 'z':
return ZlibArchive(tfnm)
else:
return carchive.CArchive(tfnm)
def getData(nm, arch):
if type(arch.toc) is type({}):
(ispkg, pos, lngth) = arch.toc.get(nm, (0, None, 0))
if pos is None:
return None
arch.lib.seek(arch.start + pos)
return zlib.decompress(arch.lib.read(lngth))
ndx = arch.toc.find(nm)
dpos, dlen, ulen, flag, typcd, nm = arch.toc[ndx]
x, data = arch.extract(ndx)
return data
def show(nm, arch):
if type(arch.toc) == type({}):
print " Name: (ispkg, pos, len)"
toc = arch.toc
else:
print " pos, length, uncompressed, iscompressed, type, name"
toc = arch.toc.data
pprint.pprint(toc)
class ZlibArchive(archive.ZlibArchive):
def checkmagic(self):
""" Overridable.
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
if self.lib.read(len(self.MAGIC)) != self.MAGIC:
raise RuntimeError, "%s is not a valid %s archive file" \
% (self.path, self.__class__.__name__)
if self.lib.read(len(self.pymagic)) != self.pymagic:
print "Warning: pyz is from a different Python version"
self.lib.read(4)
if __name__ == '__main__':
main()
This diff is collapsed.
#! /usr/bin/env python
# Configure PyInstaller for the current Python installation.
# Copyright (C) 2005, Giovanni Bajo
# Based on previous work under copyright (c) 2002 McMillan Enterprises, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import os, sys, string, shutil
HOME = os.path.dirname(sys.argv[0])
iswin = sys.platform[:3] == 'win'
is24 = hasattr(sys, "version_info") and sys.version_info[:2] >= (2,4)
cygwin = sys.platform == 'cygwin'
configfile = os.path.join(HOME, 'config.dat')
try:
config = eval(open(configfile, 'r').read())
except IOError:
config = {'useELFEXE':1} # if not set by Make.py we can assume Windows
# Save Python version, to detect and avoid conflicts
config["pythonVersion"] = sys.version
import mf, bindepend
# EXE_dependencies
print "I: computing EXE_dependencies"
python = sys.executable
if not iswin:
while os.path.islink(python):
python = os.readlink(python)
if not os.path.isabs(python):
for dir in string.split(os.environ['PATH'], os.pathsep):
test = os.path.join(dir, python)
if os.path.exists(test):
python = test
break
toc = bindepend.Dependencies([('', python, '')])
if iswin and sys.version[:3] == '1.5':
import exceptions
toc.append((os.path.basename(exceptions.__file__), exceptions.__file__, 'BINARY'))
config['EXE_dependencies'] = toc[1:]
_useTK = """\
# Generated by Configure.py
# This file is public domain
import os, sys
try:
basedir = os.environ['_MEIPASS2']
except KeyError:
basedir = sys.path[0]
tcldir = os.path.join(basedir, '_MEI', 'tcl%s')
tkdir = os.path.join(basedir, '_MEI', 'tk%s')
os.environ["TCL_LIBRARY"] = tcldir
os.environ["TK_LIBRARY"] = tkdir
os.putenv("TCL_LIBRARY", tcldir)
os.putenv("TK_LIBRARY", tkdir)
"""
# TCL_root, TK_root and support/useTK.py
print "I: Finding TCL/TK..."
if not iswin:
saveexcludes = bindepend.excludes
bindepend.excludes = {}
import re
pattern = [r'libtcl(\d\.\d)?\.so', r'(?i)tcl(\d\d)\.dll'][iswin]
a = mf.ImportTracker()
a.analyze_r('Tkinter')
binaries = []
for modnm, mod in a.modules.items():
if isinstance(mod, mf.ExtensionModule):
binaries.append((mod.__name__, mod.__file__, 'EXTENSION'))
binaries.extend(bindepend.Dependencies(binaries))
binaries.extend(bindepend.Dependencies([('', sys.executable, '')]))
for nm, fnm, typ in binaries:
mo = re.match(pattern, nm)
if mo:
ver = mo.group(1)
tclbindir = os.path.dirname(fnm)
if iswin:
ver = ver[0] + '.' + ver[1:]
elif ver is None:
# we found "libtcl.so.0" so we need to get the version from the lib directory
for name in os.listdir(tclbindir):
mo = re.match(r'tcl(\d.\d)', name)
if mo:
ver = mo.group(1)
print "I: found TCL/TK version %s" % ver
open(os.path.join(HOME, 'support/useTK.py'), 'w').write(_useTK % (ver, ver))
tclnm = 'tcl%s' % ver
tknm = 'tk%s' % ver
# Linux: /usr/lib with the .tcl files in /usr/lib/tcl8.3 and /usr/lib/tk8.3
# Windows: Python21/DLLs with the .tcl files in Python21/tcl/tcl8.3 and Python21/tcl/tk8.3
# or D:/Programs/Tcl/bin with the .tcl files in D:/Programs/Tcl/lib/tcl8.0 and D:/Programs/Tcl/lib/tk8.0
if iswin:
for attempt in ['../tcl', '../lib']:
if os.path.exists(os.path.join(tclbindir, attempt, tclnm)):
config['TCL_root'] = os.path.join(tclbindir, attempt, tclnm)
config['TK_root'] = os.path.join(tclbindir, attempt, tknm)
break
else:
config['TCL_root'] = os.path.join(tclbindir, tclnm)
config['TK_root'] = os.path.join(tclbindir, tknm)
break
else:
print "I: could not find TCL/TK"
if not iswin:
bindepend.excludes = saveexcludes
#useZLIB
print "I: testing for Zlib..."
try:
import zlib
except ImportError:
config['useZLIB'] = 0
print 'I: ... Zlib unavailable'
else:
config['useZLIB'] = 1
print 'I: ... Zlib available'
#hasRsrcUpdate
if iswin:
# only available on windows
print "I: Testing for ability to set icons, version resources..."
try:
import win32api, icon, versionInfo
except ImportError, detail:
config['hasRsrcUpdate'] = 0
print 'I: ... resource update unavailable -', detail
else:
test_exe = os.path.join(HOME, r'support\loader\run_7rw.exe')
if not os.path.exists( test_exe ):
config['hasRsrcUpdate'] = 0
print 'E: ... resource update unavailable - %s not found' % test_exe
else:
# The test_exe may be read-only
# make a writable copy and test using that
rw_test_exe = os.path.join( os.environ['TEMP'], 'me_test_exe.tmp' )
shutil.copyfile( test_exe, rw_test_exe )
try:
hexe = win32api.BeginUpdateResource(rw_test_exe,0)
except:
config['hasRsrcUpdate'] = 0
print 'I: ... resource update unavailable - win32api.BeginUpdateResource failed'
else:
win32api.EndUpdateResource(hexe, 1)
config['hasRsrcUpdate'] = 1
print 'I: ... resource update available'
os.remove(rw_test_exe)
else:
config['hasRsrcUpdate'] = 0
_useUnicode = """\
# Generated by Configure.py
# This file is public domain
import %s
"""
_useUnicodeFN = os.path.join(HOME, 'support', 'useUnicode.py')
#hasUnicode
print 'I: Testing for Unicode support...'
try:
import codecs
config['hasUnicode'] = 1
try:
import encodings
except ImportError:
module = "codecs"
else:
module = "encodings"
open(_useUnicodeFN, 'w').write(_useUnicode % module)
print 'I: ... Unicode available'
except ImportError:
try:
os.remove(_useUnicodeFN)
except OSError:
pass
config['hasUnicode'] = 0
print 'I: ... Unicode NOT available'
#hasUPX
print 'I: testing for UPX...'
hasUPX = 0
try:
vers = os.popen("upx -V").readlines()
if not vers:
hasUPX = 0
else:
v = string.split(vers[0])[1]
hasUPX = tuple(map(int, string.split(v, ".")))
if iswin and is24 and hasUPX < (1,92):
print 'E: UPX is too old! Python 2.4 under Windows requires UPX 1.92+'
hasUPX = 0
print 'I: ...UPX %s' % (('unavailable','available')[hasUPX != 0])
except Exception, e:
print 'I: ...exception result in testing for UPX'
print e, e.args
config['hasUPX'] = hasUPX
# now write out config, so Build can load
outf = open(configfile, 'w')
import pprint
pprint.pprint(config, outf)
outf.close()
import Build
# PYZ_dependencies
print "I: computing PYZ dependencies..."
a = mf.ImportTracker([os.path.join(HOME, 'support')])
a.analyze_r('archive')
mod = a.modules['archive']
toc = Build.TOC([(mod.__name__, mod.__file__, 'PYMODULE')])
for i in range(len(toc)):
nm, fnm, typ = toc[i]
mod = a.modules[nm]
tmp = []
for importednm, isdelayed, isconditional in mod.imports:
if not isconditional:
realnms = a.analyze_one(importednm, nm)
for realnm in realnms:
imported = a.modules[realnm]
if not isinstance(imported, mf.BuiltinModule):
tmp.append((imported.__name__, imported.__file__, imported.typ))
toc.extend(tmp)
toc.reverse()
config['PYZ_dependencies'] = toc.data
outf = open(configfile, 'w')
import pprint
pprint.pprint(config, outf)
outf.close()
#! /usr/bin/env python
# Copyright (C) 2005, Giovanni Bajo
# Based on previous work under copyright (c) 2002 McMillan Enterprises, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import versionInfo
import sys
if len(sys.argv) < 2:
print "Usage: >python GrabVersion.py <exe>"
print " where: <exe> is the fullpathname of a Windows executable."
print " The printed output may be saved to a file, editted and "
print " used as the input for a verion resource on any of the "
print " executable targets in an Installer config file."
print " Note that only NT / Win2K can set version resources."
else:
vs = versionInfo.decode(sys.argv[1])
print vs
# Copyright (C) 2005, Giovanni Bajo
# Based on previous work under copyright (c) 2002 McMillan Enterprises, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import string, os, sys, win32api, Makespec
modspec = """\
%(mod)s.%(klass)s._reg_class_spec_ = "%(mod)s.%(klass)s"
if (not hasattr(%(mod)s.%(klass)s, '_reg_clsctx_') or
%(mod)s.%(klass)s._reg_clsctx_ & pythoncom.CLSCTX_INPROC):
%(mod)s.%(klass)s._reg_options_ = {'InprocServer32':
os.path.abspath(
os.path.join(
os.path.dirname(sys.executable), "%(dllname)s"))}
""" #mod, klass, dllname
tmplt = """\
import sys
import string
import os
inprocess = getattr(sys, 'frozen', None)
%(modimports)s
register = 0
for i in range(1, len(sys.argv)):
arg = sys.argv[i]
if string.find(arg, "reg") > -1:
register = 1
if arg == '/unreg':
sys.argv[i] = '--unregister'
if register:
import pythoncom
pythoncom.frozen = 1
%(modspecs)s
from win32com.server import register
register.UseCommandLine(%(regspecs)s, %(flags)s)
else:
#older Python's need to force this import before pythoncom does it
import win32com.server.policy
if inprocess == 'dll':
pass
else:
import win32com.server.localserver
win32com.server.localserver.main()
""" #modimports, modspecs regspecs, flags
def create(scripts, debug, verbosity, workdir, ascii=0):
infos = [] # (path, module, klasses)
for script in scripts:
infos.append(analscriptname(script))
outfnm = 'drive%s.py' % infos[0][1]
dllname = 'drive%s.dll' % infos[0][1]
if not os.path.exists(workdir):
os.makedirs(workdir)
outfnm = os.path.join(workdir, outfnm)
outf = open(outfnm, 'w')
modspecs = []
regspecs = []
modimports = []
flags = 'debug=0, quiet=%s' % (verbosity==0)
paths = []
for path, module, klasses in infos:
if path:
paths.append(path)
for klass in klasses:
d = { 'mod':module, 'klass':klass, 'dllname':dllname }
modspecs.append(modspec % d)
regspecs.append('%(mod)s.%(klass)s' % d)
modimports.append("import %(mod)s" % d)
for i in range(len(paths)):
path = paths[i]
paths[i] = win32api.GetShortPathName(os.path.normpath(path))
modspecs = string.join(modspecs, '\n')
modimports = string.join(modimports, '\n')
regspecs = string.join(regspecs, ', ')
d = { 'modspecs':modspecs,
'regspecs':regspecs,
'modimports':modimports,
'flags':flags }
outf.write( tmplt % d )
outf.close()
print "**********************************"
print "Driver script %s created" % outfnm
specfnm = Makespec.main([outfnm], console=debug, debug=debug,
workdir=workdir, pathex=paths, comserver=1, ascii=ascii)
print "Spec file %s created" % specfnm
def analscriptname(script):
# return (path, module, klasses)
path, basename = os.path.split(script)
module = os.path.splitext(basename)[0]
while ispkgdir(path):
path, basename = os.path.split(path)
module = '%s.%s' % (basename, module)
try:
__import__(module)
except ImportError:
oldpath = sys.path[:]
sys.path.insert(0, path)
try:
__import__(module)
finally:
sys.path = oldpath
else:
path = None
m = sys.modules[module]
klasses = []
for nm, thing in m.__dict__.items():
if hasattr(thing, '_reg_clsid_'):
klasses.append(nm)
return (path, module, klasses)
def ispkgdir(path):
try:
open(os.path.join(path, '__init__.py'), 'r')
except IOError:
try:
open(os.path.join(path, '__init__.pyc'), 'rb')
except IOError:
return 0
return 1
usage = """\
Usage: python %s [options] <scriptname>.py [<scriptname>.py ...]
--debug -> use debug console build and register COM servers with debug
--verbose -> use verbose flag in COM server registration
--out dir -> generate script and spec file in dir
The next step is to run Build.py against the generated spec file.
See doc/Tutorial.html for details.
"""
if __name__ == '__main__':
#scripts, debug, verbosity, workdir
debug = verbosity = ascii = 0
workdir = '.'
import getopt
opts, args = getopt.getopt(sys.argv[1:], '', ['debug', 'verbose', 'ascii', 'out='])
for opt, val in opts:
if opt == '--debug':
debug = 1
elif opt == '--verbose':
verbosity = 1
elif opt == '--out':
workdir = val
elif opt == '--ascii':
ascii = 1
else:
print usage % sys.argv[0]
sys.exit(1)
if not args:
print usage % sys.argv[0]
else:
create(args, debug, verbosity, workdir, ascii)
# Copyright (C) 2005, Giovanni Bajo
# Based on previous work under copyright (c) 2002 McMillan Enterprises, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
import string, os, sys, win32api, Makespec
tmplt = """\
import sys