- 论坛徽章:
- 0
|
我修改过的setup.py
需要先安装InnoSetup
isetup-5.1.6.exe
http://www.jrsoftware.org/isdl.php
ChineseSimp-11-5.1.0.isl
http://www.jrsoftware.org/files/istrans/
最好也有安装python的ctypes模块
http://starship.python.net/crew/theller/ctypes/
假设GTK已经安装在C:\GTK
Gtk+/Win32 Runtime Environment Installer 2.8.10-rc1 (.exe, 5.21M)
http://gladewin32.sourceforge.net/modules/wfdownloads/visit.php?lid=97
- # setup.py
- # -*- coding: cp936 -*-
- # Author: wolfg
- # A setup script showing how to extend py2exe.
- #
- # In this case, the py2exe command is subclassed to create an installation
- # script for InnoSetup, which can be compiled with the InnoSetup compiler
- # to a single file windows installer.
- #
- # By default, the installer will be created as dist\Output\setup.exe.
- from distutils.core import setup
- import py2exe
- import sys
- import glob
- ################################################################
- # arguments for the setup() call
- livinginzhuhai = dict(
- script = "go.py",
- #other_resources = [],
- #icon_resources = [(1, "check.ico")],
- dest_base = r"bin\go")
- zipfile = r"lib\shardlib"
- options = {"py2exe":
- {
- "compressed": 1,
- "optimize": 2,
- "packages": "encodings",
- "includes": "cairo, pango, pangocairo, atk, gobject",
- }
- }
- ################################################################
- import os
- GTKDIR = 'C:\\gtk\\'
- os.environ['PATH'] += ";%s/lib;%s/bin" % (GTKDIR, GTKDIR)
- GTK_RUNTIME_FILES = glob.glob(GTKDIR + 'etc\\*\\*')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\*.a')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\*.alias')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\*.lib')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\glib-2.0\\include\\*.*')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\gtk-2.0\\2.4.0\\*\\*.*')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\gtk-2.0\\include\\*.*')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\gtkglext-1.0\\include\\*.*')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\libglade\\2.0\\include\\*.*')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\pango\\1.4.0\\modules\\*.*')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'lib\\pkgconfig\\*.*')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\aclocal\\*')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\xml\\libglade\\*')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\pixmaps\\*.png')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\pixmaps\\glade-2\\*.png')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\locale\\zh_CN\\*\\*')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\themes\\Default\\*\\*')
- GTK_RUNTIME_FILES += glob.glob(GTKDIR + 'share\\themes\\MS-Windows\\*\\*')
- class InnoScript:
- def __init__(self,
- name,
- install_dir,
- lib_dir,
- dist_dir,
- windows_exe_files = [],
- lib_files = [],
- version = "1.0",
- output_basename = "Setup"):
- self.lib_dir = lib_dir
- self.dist_dir = dist_dir
- if not self.dist_dir[-1] in "\\/":
- self.dist_dir += "\\"
- self.name = name
- self.install_dir = install_dir
- self.version = version
- self.output_basename = output_basename
- 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\\livinginzhuhai.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.install_dir
- print >> ofi, r"DefaultGroupName=%s" % self.name
- print >> ofi, r"Compression=lzma"
- print >> ofi, r"SolidCompression=yes"
- print >> ofi, r"OutputBaseFilename=%s" % self.output_basename
- 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))
-
- for src, dest in [(p, p[len(GTKDIR):]) for p in GTK_RUNTIME_FILES]:
- print >> ofi, r'Source: "%s"; DestDir: "{app}\%s"; Flags: ignoreversion' % (src, os.path.dirname(dest))
- print >> ofi
-
- print >> ofi, r"[Tasks]"
- print >> ofi, r'Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked'
- print >> ofi
-
- print >> ofi, r"[Icons]"
- for path in self.windows_exe_files:
- print >> ofi, r'Name: "{group}\%s"; Filename: "{app}\%s"; WorkingDir: "{app}\%s"' % \
- (self.name, path, os.path.dirname(path))
- print >> ofi, r'Name: "{group}\Uninstall %s"; Filename: "{uninstallexe}"' % self.name
- print >> ofi, r'Name: "{userdesktop}\%s"; Filename: "{app}\bin\go.exe"; Tasks: desktopicon; WorkingDir: "{app}\bin"' % self.name
- print >> ofi
-
- print >> ofi, r"[Run]"
- print >> ofi, r'Filename: "{app}\bin\go.exe"; Description: "%s"; Flags: postinstall shellexec skipifsilent' % (u'开始“珠海浮生记”').encode('cp936')
- print >> ofi
-
- print >> ofi, r"[Languages]"
- print >> ofi, r'Name: "cn"; MessagesFile: "C:\Program Files\Inno Setup 5\Languages\ChineseSimp.isl"'
- print >> ofi
-
- 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
- ################################################################
- from py2exe.build_exe import py2exe
- class build_installer(py2exe):
- # This class first builds the exe file(s), then creates a Windows installer.
- # You need InnoSetup for it.
- def run(self):
- # First, let py2exe do it's work.
- py2exe.run(self)
- lib_dir = self.lib_dir
- dist_dir = self.dist_dir
-
- # create the Installer, using the files py2exe has created.
- script = InnoScript(u"珠海浮生记".encode('cp936'),
- u"珠海浮生记".encode('cp936'),
- lib_dir,
- dist_dir,
- self.windows_exe_files,
- self.lib_files,
- '1.0',
- output_basename="Setup"
- )
- print "*** creating the inno setup script***"
- script.create()
- print "*** compiling the inno setup script***"
- script.compile()
- # Note: By default the final setup.exe will be in an Output subdirectory.
- ################################################################
- setup(
- options = options,
- # The lib directory contains everything except the executables and the python dll.
- zipfile = zipfile,
- windows = [livinginzhuhai],
- # use out build_installer class as extended py2exe build command
- cmdclass = {"py2exe": build_installer},
- data_files=[("bin", ["zhfsj.glade", ])]
- )
复制代码
[ 本帖最后由 wolfg 于 2006-2-14 16:05 编辑 ] |
|