1
# -*- coding: utf-8 -*-
3
# Copyright (C) 2008 Guillermo Gonzalez <guillo.gonzo@gmail.com>
4
# Copyright (C) 2007 Lukáš Lalinský <lalinsky@gmail.com>
5
# Copyright (C) 2007 Alexander Belchenko <bialix@ukr.net>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License
9
# as published by the Free Software Foundation; either version 2
10
# of the License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
"""bdist_nsis command for setup.py (create windows installer with NSIS)"""
23
from distutils.command.bdist import bdist
24
from distutils.core import Command
25
from distutils.errors import DistutilsPlatformError
26
from distutils import log
32
class bdist_nsis(Command):
34
description = "create an executable installer for MS Windows with NSIS"
37
('nsi-script', None, "NSIS script to compile"),
39
"skip rebuilding everything (for testing/debugging)"),
40
('nsis-compiler', None, "full path to NSIS compiler executable"),
41
('dry-run', 'n', "copy libs (if required) but don't run makensis"),
43
"copy all additional libs from Python 2.5 site-packages"),
52
def initialize_options(self):
53
self.nsi_script = None
54
self.skip_build = False
55
self.nsis_compiler = None
59
def finalize_options(self):
60
if not self.nsi_script:
61
name = self.distribution.get_name() or ''
63
script_name = 'installer/%s-setup.nsi' % name
65
script_name = 'installer/setup.nsi'
66
print 'NOTE: will use %s script' % script_name
67
self.nsi_script = script_name
68
if not self.nsis_compiler:
70
if sys.platform == 'win32':
71
# read path from registry
75
hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
78
nsis_dir = _winreg.QueryValue(hkey, '')
80
_winreg.CloseKey(hkey)
81
except (EnvironmentError, WindowsError):
84
self.nsis_compiler = os.path.join(nsis_dir, 'makensis.exe')
86
self.nsis_compiler = 'makensis.exe'
88
self.nsis_compiler = 'makensis'
90
def _copy_python_package(self, pkg):
91
sitedir = os.path.join(os.path.dirname(os.__file__),
93
prefix = len(sitedir) + 1
94
for root, dirs, files in os.walk(pkg):
96
ext = os.path.splitext(i)[1]
97
if ext in ('.py', '.pyd'):
98
src = os.path.join(root, i)
99
dst = os.path.join('installer', '_lib', root[prefix:], i)
100
dstdir = os.path.dirname(dst)
101
if not os.path.isdir(dstdir):
102
log.info('Creating directory %s', dstdir)
104
log.info('Copying %s -> %s', src, dst)
105
shutil.copyfile(src, dst)
108
if not self.skip_build:
109
self.run_command('build')
111
print 'Run NSIS compiler'
112
self.spawn([self.nsis_compiler, self.nsi_script])
115
# plug-in our bdist builder to distutils collection
116
bdist.format_commands.append('nsis')
117
bdist.format_command['nsis'] = ('bdist_nsis', 'Windows NSIS-based installer')