~mysql/mysql-utilities/1.5

« back to all changes in this revision

Viewing changes to support/distribution/commands/dist_msi.py

  • Committer: Israel Gomez
  • Date: 2014-07-25 15:49:36 UTC
  • Revision ID: israel.gomez@oracle.com-20140725154936-qq2v9ndmdsle4lec
Tags: release-1.5.1rc1
BUG#19262669 : fixes to Package mechanisms regarding release-1.5.1rc

The release-1.5.1rc will be a standalone release, meaning it Utilities will
no longer be a subproduct of Workbench. As a result we need to fix some of
the Package mechanism.

This patch fixes the Package mechanism to remove the references to Workbench,
in addition adds the functionality to package additional info files from
Fabric proyect.

This patch also fixes the shortcuts to the online documentation installed by
the Windows MSI package.

v3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
2
 
# Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
 
2
# Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
30
30
from distutils.errors import DistutilsError
31
31
from distutils.dir_util import remove_tree
32
32
from distutils.sysconfig import get_python_version
33
 
from distutils.command.bdist_dumb import bdist_dumb
34
 
from distutils.command.install_data import install_data
35
33
from distutils.command.bdist import bdist
36
34
from distutils.util import get_platform
37
 
from distutils.file_util import copy_file
38
35
 
39
 
from mysql.utilities import RELEASE_STRING, COPYRIGHT
 
36
from mysql.utilities import COPYRIGHT
40
37
from support import wix
41
38
from support.distribution.msi_descriptor_parser import (add_exe_utils,
42
 
                                                        add_features)
 
39
                                                        add_features,
 
40
                                                        add_online_help_utils)
43
41
 
44
42
 
45
43
WIX_INSTALL = r"C:\Program Files (x86)\Windows Installer XML v3.5"
119
117
 
120
118
        Returns a string
121
119
        """
122
 
        raise NotImplemented
 
120
        raise NotImplementedError
123
121
 
124
122
    def _create_msi(self, dry_run=0):
125
123
        """Create the Windows Installer using WiX
126
 
        
 
124
 
127
125
        Creates the Windows Installer using WiX and returns the name of
128
126
        the created MSI file.
129
 
        
 
127
 
130
128
        Raises DistutilsError on errors.
131
 
        
 
129
 
132
130
        Returns a string
133
131
        """
134
132
        # load the upgrade codes
135
133
        fp = open('support/MSWindows/upgrade_codes.json')
136
134
        upgrade_codes = json.load(fp)
137
135
        fp.close()
138
 
        
 
136
 
139
137
        # Version of the application being packaged
140
138
        appver = self.distribution.metadata.version
141
139
        match = re.match(r"(\d+)\.(\d+).(\d+).*", appver)
146
144
        # Python version
147
145
        pyver = self.python_version
148
146
        pymajor, pyminor = pyver.split('.')[0:2]
149
 
        
 
147
 
150
148
        # Check whether we have an upgrade code
151
149
        try:
152
150
            upgrade_code = upgrade_codes[appver[0:3]][pyver]
157
155
        log.info("upgrade code for v{appver},"
158
156
                 " Python v{pyver}: {upgrade}".format(
159
157
                    appver=appver, pyver=pyver, upgrade=upgrade_code))
160
 
        
 
158
 
161
159
        # wixobj's basename is the name of the installer
162
160
        wixobj = self._get_wixobj_name()
163
161
        msi = os.path.abspath(
167
165
                        msi_out=msi,
168
166
                        base_path=self.dist_dir,
169
167
                        install=self.wix_install)
170
 
        
 
168
 
171
169
        # WiX preprocessor variables
172
170
        if self.dist_type == 'com':
173
171
            liscense_file = 'License_com.rtf'
175
173
            liscense_file = 'License.rtf'
176
174
        params = {
177
175
            'ProductName': self.product_name,
178
 
            'ReleaseString': RELEASE_STRING,
 
176
            'DocVersion': '.'.join([major, minor]),
179
177
            'Copyright': COPYRIGHT,
180
178
            'Version': '.'.join([major, minor, patch]),
181
179
            'FullVersion': appver,
194
192
            'LicenseRtf': os.path.abspath(
195
193
                os.path.join('support', 'MSWindows', liscense_file)),
196
194
        }
197
 
        
 
195
 
198
196
        wixer.set_parameters(params)
199
 
        
 
197
 
200
198
        if not dry_run:
201
199
            try:
202
200
                wixer.compile(ui=True)
209
207
            os.unlink(msi.replace('.msi', '.wixobj'))
210
208
            os.unlink(msi.replace('.msi', '.wixpdb'))
211
209
            remove_tree(self.bdist_base)
212
 
        
 
210
 
213
211
        return msi
214
212
 
215
213
    def _prepare_distribution(self):
227
225
 
228
226
        wix.check_wix_install(wix_install_path=self.wix_install,
229
227
                              dry_run=self.dry_run)
230
 
        
 
228
 
231
229
        self._prepare_distribution()
232
 
        
 
230
 
233
231
        # create the Windows Installer
234
232
        msi_file = self._create_msi(dry_run=self.dry_run)
235
233
        log.info("created MSI as %s" % msi_file)
246
244
 
247
245
    python_version = get_python_version()
248
246
    wxs = 'support/MSWindows/mysql_utilities.xml'
249
 
    fix_txtfiles = ['README.txt', 'LICENSE.txt']
 
247
    fix_txtfiles = [
 
248
        ('README.txt', 'README_Utilities.txt'),
 
249
        ('README_Fabric.txt', 'README_Fabric.txt'),
 
250
        ('LICENSE.txt', 'LICENSE.txt'),
 
251
        ('CHANGES.txt', 'CHANGES_Utilities.txt'),
 
252
        ('CHANGES_Fabric.txt', 'CHANGES_Fabric.txt')
 
253
    ]
250
254
 
251
255
    def initialize_options(self):
252
256
        """Initialize the options"""
263
267
        base_xml_path = "support/MSWindows/mysql_utilities.xml"
264
268
        result_xml_path = 'support/MSWindows/mysql_utilities_fab-doc.xml'
265
269
        add_exe_utils(base_xml_path, result_xml_path,
266
 
                      self.distribution.scripts ,log=log)
 
270
                      self.distribution.scripts, log=log)
 
271
        add_online_help_utils(result_xml_path, result_xml_path,
 
272
                              self.distribution.scripts, log=log)
267
273
 
268
274
        pck_fabric, add_doczip = self.are_fabric_doctrine_present()
269
275
        if pck_fabric or add_doczip:
273
279
                         add_doczip=add_doczip,
274
280
                         log=log)
275
281
            for root, _dirs, files in os.walk('support/MSWindows/'):
276
 
                log.info('Checking for new msi descriptor at: {0}'.format(root))
 
282
                log.info('Checking for new msi descriptor at: {0}'
 
283
                         ''.format(root))
277
284
                for afile in files:
278
285
                    log.info('file: {0}'.format(afile))
279
286
                if 'mysql_utilities_fab-doc.xml' in files:
293
300
            platform = '-' + self.plat_name
294
301
 
295
302
        return ("mysql-utilities-{app_version}{sub_version}{tag}"
296
 
                "{platform}.wixobj").format(app_version=appver, 
 
303
                "{platform}.wixobj").format(app_version=appver,
297
304
                                            sub_version=self.sub_version,
298
305
                                            python_version=pyver,
299
306
                                            tag=self.tag,
308
315
        log.info("installing to %s" % self.bdist_base)
309
316
        self.run_command('install_data')
310
317
        log.info('install_data finish')
311
 
        
 
318
 
312
319
        buildexe = self.get_finalized_command('build_exe')
313
 
        buildexe.build_exe = self.bdist_base 
 
320
        buildexe.build_exe = self.bdist_base
314
321
        buildexe.run()
315
322
 
316
323
        # copy text files and correct newlines
317
 
        for txtfile in self.fix_txtfiles:
318
 
            log.info("creating and fixing text file %s", txtfile)
319
 
            builttxt = os.path.join(self.bdist_base, txtfile)
320
 
            open(builttxt, 'w').write(open(txtfile).read())
 
324
        for txtfile, new_txtfile in self.fix_txtfiles:
 
325
            if os.path.exists(txtfile):
 
326
                log.info("creating and fixing text file {0}"
 
327
                         "".format(new_txtfile))
 
328
                builttxt = os.path.join(self.bdist_base, new_txtfile)
 
329
                open(builttxt, 'w').write(open(txtfile).read())
 
330
            else:
 
331
                log.info("File {0} not found, skipping."
 
332
                         "".format(txtfile))
321
333
 
322
334
 
323
335
class BuiltCommercialMSI(_MSIDist):
346
358
    boolean_options = [
347
359
        'keep-temp', 'include-sources'
348
360
    ]
349
 
    
350
 
    def initialize_options (self):
 
361
 
 
362
    def initialize_options(self):
351
363
        """Initialize the options"""
352
364
        self.sub_version = ""
353
365
        self.bdist_base = None
358
370
        self.include_sources = False
359
371
        self.wix_install = wix.WIX_INSTALL_PATH
360
372
        self.python_version = get_python_version()
361
 
        self.dist_type =''#'com'
 
373
        self.dist_type = ''
362
374
        self.sub_version = ''
363
 
    
 
375
 
364
376
    def finalize_options(self):
365
377
        """Finalize the options"""
366
378
        self.set_undefined_options('bdist',
370
382
        base_xml_path = "support/MSWindows/mysql_utilities_com.xml"
371
383
        result_xml_path = 'support/MSWindows/mysql_utilities_fab-doc_com.xml'
372
384
        add_exe_utils(base_xml_path, result_xml_path,
373
 
                      self.distribution.scripts ,log=log)
 
385
                      self.distribution.scripts, log=log)
 
386
        add_online_help_utils(result_xml_path, result_xml_path,
 
387
                              self.distribution.scripts, log=log)
374
388
 
375
389
        pck_fabric, add_doczip = self.are_fabric_doctrine_present()
376
390
        if pck_fabric or add_doczip:
380
394
                         add_doczip=add_doczip,
381
395
                         log=log)
382
396
            for root, _dirs, files in os.walk('support/MSWindows/'):
383
 
                log.info('Checking for new msi descriptor at: {0}'.format(root))
 
397
                log.info('Checking for new msi descriptor at: {0}'
 
398
                         ''.format(root))
384
399
                for afile in files:
385
400
                    log.info('file: {0}'.format(afile))
386
401
                if 'mysql_utilities_fab-doc_com.xml' in files:
387
402
                    log.info('new msi descriptor found')
388
403
                else:
389
404
                    log.info('new msi descriptor not found')
390
 
            self.wxs = result_xml_path
391
 
        else:
392
 
            self.wxs = 'support/MSWindows/mysql_utilities_com.xml'
 
405
        self.wxs = result_xml_path
393
406
 
394
 
        self.fix_txtfiles = ['README_com.txt', 'LICENSE_com.txt']
 
407
        self.fix_txtfiles = [('README_com.txt', 'README_com.txt'),
 
408
                             ('LICENSE_com.txt', 'LICENSE_com.txt')]
395
409
        if self.tag:
396
410
            self.tag = "-{0}".format(self.tag)
397
411
 
406
420
        if self.plat_name:
407
421
            platform = '-' + self.plat_name
408
422
 
409
 
 
410
423
        return ("mysql-utilities-commercial-{app_version}{sub_version}{tag}"
411
424
                "{platform}.wixobj").format(app_version=appver,
412
425
                                            sub_version=self.sub_version,
423
436
 
424
437
        log.info("building exes at {0}".format(cmdbdist.bdist_dir))
425
438
        buildexe = self.get_finalized_command('build_exe')
426
 
        buildexe.build_exe = cmdbdist.bdist_dir 
 
439
        buildexe.build_exe = cmdbdist.bdist_dir
427
440
        buildexe.run()
428
441
        docfiles = [
429
442
            (os.path.join(cmdbdist.dist_target, 'LICENSE_com.txt'),
436
449
        self.bdist_base = cmdbdist.bdist_dir
437
450
        # This sets name for various items as install directory.
438
451
        self.product_name = 'MySQL Utilities commercial'
439