~ubuntu-branches/debian/stretch/bzr-xmloutput/stretch

« back to all changes in this revision

Viewing changes to extras/bdist_nsis.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2009-01-20 05:18:35 UTC
  • Revision ID: james.westby@ubuntu.com-20090120051835-r8ppbnuij6m2symv
Tags: upstream-0.8.1+bzr116
Import upstream version 0.8.1+bzr116

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
#
 
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>
 
6
#
 
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.
 
11
#
 
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.
 
16
#
 
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.
 
20
 
 
21
"""bdist_nsis command for setup.py (create windows installer with NSIS)"""
 
22
 
 
23
from distutils.command.bdist import bdist
 
24
from distutils.core import Command
 
25
from distutils.errors import DistutilsPlatformError
 
26
from distutils import log
 
27
import os
 
28
import shutil
 
29
import sys
 
30
 
 
31
 
 
32
class bdist_nsis(Command):
 
33
 
 
34
    description = "create an executable installer for MS Windows with NSIS"
 
35
 
 
36
    user_options = [
 
37
        ('nsi-script', None, "NSIS script to compile"),
 
38
        ('skip-build', None,
 
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"),
 
42
        ('copy-all', 'A',
 
43
            "copy all additional libs from Python 2.5 site-packages"),
 
44
        ]
 
45
 
 
46
    boolean_options = [
 
47
        'skip-build',
 
48
        'copy-all',
 
49
        'dry-run',
 
50
        ]
 
51
 
 
52
    def initialize_options(self):
 
53
        self.nsi_script = None
 
54
        self.skip_build = False
 
55
        self.nsis_compiler = None
 
56
        self.copy_all = False
 
57
        self.dry_run = False
 
58
 
 
59
    def finalize_options(self):
 
60
        if not self.nsi_script:
 
61
            name = self.distribution.get_name() or ''
 
62
            if name:
 
63
                script_name = 'installer/%s-setup.nsi' % name
 
64
            else:
 
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:
 
69
            # auto-detect NSIS
 
70
            if sys.platform == 'win32':
 
71
                # read path from registry
 
72
                import _winreg
 
73
                nsis_dir = None
 
74
                try:
 
75
                    hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,
 
76
                        'SOFTWARE\\NSIS')
 
77
                    try:
 
78
                        nsis_dir = _winreg.QueryValue(hkey, '')
 
79
                    finally:
 
80
                        _winreg.CloseKey(hkey)
 
81
                except (EnvironmentError, WindowsError):
 
82
                    pass
 
83
                if nsis_dir:
 
84
                    self.nsis_compiler = os.path.join(nsis_dir, 'makensis.exe')
 
85
                else:
 
86
                    self.nsis_compiler = 'makensis.exe'
 
87
            else:
 
88
                self.nsis_compiler = 'makensis'
 
89
 
 
90
    def _copy_python_package(self, pkg):
 
91
        sitedir = os.path.join(os.path.dirname(os.__file__),
 
92
                               'site-packages')
 
93
        prefix = len(sitedir) + 1
 
94
        for root, dirs, files in os.walk(pkg):
 
95
            for i in files:
 
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)
 
103
                        os.mkdir(dstdir)
 
104
                    log.info('Copying %s -> %s', src, dst)
 
105
                    shutil.copyfile(src, dst)
 
106
 
 
107
    def run(self):
 
108
        if not self.skip_build:
 
109
            self.run_command('build')
 
110
        if not self.dry_run:
 
111
            print 'Run NSIS compiler'
 
112
            self.spawn([self.nsis_compiler, self.nsi_script])
 
113
 
 
114
 
 
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')