[Pymoul-svn] SF.net SVN: pymoul: [62] pymoul/trunk
Status: Alpha
Brought to you by:
tiran
From: <ti...@us...> - 2007-01-23 22:52:09
|
Revision: 62 http://pymoul.svn.sourceforge.net/pymoul/?rev=62&view=rev Author: tiran Date: 2007-01-23 14:52:09 -0800 (Tue, 23 Jan 2007) Log Message: ----------- Cleaned up distutils_upx code Added support for InnoSetup installer Modified Paths: -------------- pymoul/trunk/INSTALL.txt pymoul/trunk/Makefile pymoul/trunk/distutils_upx.py pymoul/trunk/setup_win32.py Modified: pymoul/trunk/INSTALL.txt =================================================================== --- pymoul/trunk/INSTALL.txt 2007-01-23 17:51:37 UTC (rev 61) +++ pymoul/trunk/INSTALL.txt 2007-01-23 22:52:09 UTC (rev 62) @@ -20,6 +20,7 @@ ----- * UPX http://upx.sourceforge.net/#download + * InnoSetup http://www.jrsoftware.org/ ==================== Windows Installation Modified: pymoul/trunk/Makefile =================================================================== --- pymoul/trunk/Makefile 2007-01-23 17:51:37 UTC (rev 61) +++ pymoul/trunk/Makefile 2007-01-23 22:52:09 UTC (rev 62) @@ -41,6 +41,8 @@ egg: bdist_egg +doc: doc_html + clean: find . \( -name '*.o' -o -name '*.c' -o -name '*.so' -o -name '*.py[cod]' -o -name '*.dll' \) -exec rm -f {} \; rm -rf build Modified: pymoul/trunk/distutils_upx.py =================================================================== --- pymoul/trunk/distutils_upx.py 2007-01-23 17:51:37 UTC (rev 61) +++ pymoul/trunk/distutils_upx.py 2007-01-23 22:52:09 UTC (rev 62) @@ -13,22 +13,6 @@ from stat import ST_SIZE from fnmatch import fnmatch -def _call(cmd, silent=False, *args, **kwargs): - """Call silently - redirect stdout to dump - """ - data = None - if silent: - stdout = TemporaryFile() - else: - stdout = None - try: - retcode = subcall(cmd, stdout=stdout, *args, **kwargs) - finally: - if stdout: - data = stdout.read() - stdout.close() - return retcode, data - class UpxCommand: """Upx packer mixin class for distutils @@ -52,7 +36,7 @@ def initialize_options(self): result = self._otherclass().initialize_options(self) self.upx = True - self.upx_args = '--no-color --best' + self.upx_args = '--no-color' self.upx_path = 'upx' self.upx_extensions = [ 'pyd', 'dll', 'exe', # Windows @@ -60,6 +44,10 @@ 'dylib', # Mac OS X ] self.upx_ignore = [] + + self.app_name = '' + self.innosetup = False + return result def finalize_options(self): @@ -69,7 +57,6 @@ return result def copy_file(self, *args, **kwargs): - # Override to UPX copied binaries. result = self._otherclass().copy_file(self, *args, **kwargs) self.upx_packlist.append(result) return result @@ -77,9 +64,16 @@ def run(self, *args, **kwargs): result = self._otherclass().run(self, *args, **kwargs) self._upxPack() + self._createInnoSetup() return result def _upxPack(self): + """Pack files + + At last pack the files. I had some hard to debug errors as I tried to + pack the files inside the copy_file() method. Some dll and exe files + were broken. Perhaps some file handlers weren't closed? + """ if not self.has_upx or not self.upx: return @@ -116,7 +110,7 @@ def _upxPackFile(self, fname): """Pack a file """ - retcode, stdout = _call('%s %s "%s"' % (self.upx_path, self.upx_args, fname), silent=False) + retcode = subcall('%s %s "%s"' % (self.upx_path, self.upx_args, fname)) if retcode == 0: # OK, file packed pass elif retcode == 2: # OK, file already packed @@ -127,8 +121,13 @@ def _upxAvailable(self): """Search for UPX in search path """ + stdout = TemporaryFile() try: - retcode, stdout = _call("%s --version" % self.upx_path, silent=True) + try: + retcode = subcall("%s --version" % self.upx_path, stdout=stdout) + finally: + if stdout: + stdout.close() except OSError: log.debug('UPX not found') return False @@ -151,7 +150,99 @@ return c raise ValueError(cls) + def _createInnoSetup(self): + if not self.innosetup: + return + script = InnoScript(self.app_name, + self.lib_dir, + self.dist_dir, + self.windows_exe_files, + self.lib_files) + print "*** creating the inno setup script***" + script.create() + print "*** compiling the inno setup script***" + try: + script.compile() + except RuntimeError, msg: + print "Failed to create installer:\n%s" % msg + # Note: By default the final setup.exe will be in an Output subdirectory. + +class InnoScript: + """Based on py2exe/samples/extending/setup.py + + Requires http://www.jrsoftware.org + """ + def __init__(self, + name, + lib_dir, + dist_dir, + windows_exe_files = [], + lib_files = [], + version = "1.0"): + self.lib_dir = lib_dir + self.dist_dir = dist_dir + if not self.dist_dir[-1] in "\\/": + self.dist_dir += "\\" + self.name = name + self.version = version + self.windows_exe_files = [self.chop(p) for p in windows_exe_files] + self.lib_files = [self.chop(p) for p in lib_files] + + def chop(self, pathname): + assert pathname.startswith(self.dist_dir) + return pathname[len(self.dist_dir):] + + def create(self, pathname="dist\\test_wx.iss"): + self.pathname = pathname + ofi = self.file = open(pathname, "w") + print >> ofi, "; WARNING: This script has been created by py2exe. Changes to this script" + print >> ofi, "; will be overwritten the next time py2exe is run!" + print >> ofi, r"[Setup]" + print >> ofi, r"AppName=%s" % self.name + print >> ofi, r"AppVerName=%s %s" % (self.name, self.version) + print >> ofi, r"DefaultDirName={pf}\%s" % self.name + print >> ofi, r"DefaultGroupName=%s" % self.name + print >> ofi + + print >> ofi, r"[Files]" + for path in self.windows_exe_files + self.lib_files: + print >> ofi, r'Source: "%s"; DestDir: "{app}\%s"; Flags: ignoreversion' % (path, os.path.dirname(path)) + print >> ofi + + print >> ofi, r"[Icons]" + for path in self.windows_exe_files: + print >> ofi, r'Name: "{group}\%s"; Filename: "{app}\%s"' % \ + (self.name, path) + print >> ofi, 'Name: "{group}\Uninstall %s"; Filename: "{uninstallexe}"' % self.name + + def compile(self): + try: + import ctypes + except ImportError: + try: + import win32api + except ImportError: + import os + os.startfile(self.pathname) + else: + #print "Ok, using win32api." + win32api.ShellExecute(0, "compile", + self.pathname, + None, + None, + 0) + else: + #print "Cool, you have ctypes installed." + res = ctypes.windll.shell32.ShellExecuteA(0, "compile", + self.pathname, + None, + None, + 0) + if res < 32: + raise RuntimeError("ShellExecute failed, error %d" % res) + + try: from py2exe.build_exe import py2exe except ImportError: @@ -159,4 +250,3 @@ else: class UpxPy2exe(UpxCommand, py2exe): pass - Modified: pymoul/trunk/setup_win32.py =================================================================== --- pymoul/trunk/setup_win32.py 2007-01-23 17:51:37 UTC (rev 61) +++ pymoul/trunk/setup_win32.py 2007-01-23 22:52:09 UTC (rev 62) @@ -69,6 +69,12 @@ pexe['compressed'] = 100 # compress zip file pexe['optimize'] = 0 # 0,1,2 pexe['includes'] = ['sip', 'PyQt4', 'encodings', 'encodings.*'] + # UPX + pexe['upx'] = True + pexe['upx_args'] = '--mono --best' + # InnoSetup + pexe['innosetup'] = True + pexe['app_name'] = 'pyMoul' # not required at the moment pexe['includes'].extend(findPyTz()) kw['zipfile'] = 'library.zip' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |