~mysql/mysql-utilities/1.5

« back to all changes in this revision

Viewing changes to support/distribution/commands/dist_osx.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
 
#
2
 
# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; version 2 of the License.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16
 
#
17
 
"""This Class extends DistUtils commands for create mac osx distribution
18
 
packages
19
 
"""
20
 
 
21
 
import os
22
 
import platform
23
 
import sys
24
 
 
25
 
from distutils import log
26
 
from distutils.command.bdist import bdist
27
 
from distutils.file_util import copy_file
28
 
from distutils.dir_util import copy_tree, remove_tree
29
 
 
30
 
 
31
 
class BuildDistOSX(bdist):
32
 
    """This class contains the command to built an osx distribution package
33
 
    """
34
 
    platf_n = '-osx'
35
 
    platf_v = '.'.join(platform.mac_ver()[0].split('.', 2)[0:2])
36
 
    description = 'create a mac osx distribution package'
37
 
    user_options = [
38
 
        ('keep-temp', 'k',
39
 
         "keep the pseudo-installation tree around after "
40
 
         "creating the distribution archive"),
41
 
        ('create-dmg', 'c',
42
 
         "create a dmg image from the resulting package file "
43
 
         "(default 'False')"),
44
 
        ('sign', 's',
45
 
         "signs the package file (default 'False')"),
46
 
        ('identity=', 'i',
47
 
         "identity or name of the certificate to use to sign the package file"
48
 
         "(default 'MySQL-Utilities')"),
49
 
        ('dist-dir=', 'd',
50
 
         "directory to put final built distributions in"),
51
 
        ('platform=', 'p',
52
 
         "name of the platform in resulting file "
53
 
         "(default '{0}')".format(platf_n)),
54
 
        ('platform-version=', 'v',
55
 
         "version of the platform in resulting file "
56
 
         "(default '{0}')".format(platf_v))
57
 
    ]
58
 
 
59
 
    boolean_options = ['keep-temp', 'create-dmg', 'sign']
60
 
 
61
 
    def initialize_options(self):
62
 
        """Initialize the options"""
63
 
        self.name = self.distribution.get_name()
64
 
        self.version = self.distribution.get_version()
65
 
        self.keep_temp = None
66
 
        self.create_dmg = False
67
 
        self.dist_dir = None
68
 
        self.started_dir = os.getcwd()
69
 
        self.platform = self.platf_n
70
 
        self.platform_version = self.platf_v
71
 
        self.debug = False
72
 
        self.osx_pkg_name = "{0}-{1}.pkg".format(self.name, self.version)
73
 
        self.dstroot = "dstroot"
74
 
        self.sign = False
75
 
        self.identity = "MySQL-Utilities"
76
 
 
77
 
    def finalize_options(self):
78
 
        """Finalize the options"""
79
 
        self.set_undefined_options('bdist',
80
 
                                   ('dist_dir', 'dist_dir'))
81
 
 
82
 
    def _prepare_pgk_base(self, template_name, root='', gpl=True):
83
 
        """Create and populate the src base directory
84
 
 
85
 
        osx_pkg_name[in] the name of the resulting package
86
 
        root[in]         the root path for the package contents
87
 
        gpl[in]          if false license and readme will correspond to the
88
 
                         commercial package instead of GPL files. default=True
89
 
        """
90
 
 
91
 
        # copy and create necessary files
92
 
        osx_dist_name = template_name.format(self.name, self.version)
93
 
        osx_pkg_name = "{0}.pkg".format(osx_dist_name)
94
 
        osx_pkg_contents = os.path.join(root, osx_pkg_name, 'Contents')
95
 
        osx_pkg_resrc = os.path.join(osx_pkg_contents, 'Resources')
96
 
        self.mkpath(osx_pkg_resrc)
97
 
        osx_path = os.path.join(root, self.dstroot)
98
 
 
99
 
        cwd = os.path.join(os.getcwd())
100
 
 
101
 
        copy_file_src_dst = [
102
 
            (os.path.join("support", "osx", "PkgInfo"),
103
 
             os.path.join(osx_pkg_contents, "PkgInfo")),
104
 
            (os.path.join("support", "osx", "background.jpg"),
105
 
             os.path.join(osx_pkg_resrc, "background.jpg")),
106
 
            (os.path.join("support", "osx", "Welcome.rtf"),
107
 
             os.path.join(osx_pkg_resrc, "Welcome.rtf"))
108
 
        ]
109
 
 
110
 
        # No special folder for GPL or commercial. Files inside the directory
111
 
        # will determine what it is.
112
 
        data_path = os.path.join(
113
 
            osx_path, 'usr', 'local',
114
 
            '{0}-{1}'.format(self.name, self.version)
115
 
        )
116
 
        self.mkpath(data_path)
117
 
 
118
 
        if gpl:
119
 
            copy_file_src_dst += [
120
 
                (os.path.join(cwd, "README.txt"),
121
 
                 os.path.join(osx_pkg_resrc, "ReadMe.txt")),
122
 
                (os.path.join(cwd, "LICENSE.txt"),
123
 
                 os.path.join(osx_pkg_resrc, "License.txt")),
124
 
                (os.path.join(cwd, "README.txt"),
125
 
                 os.path.join(data_path, "ReadMe.txt")),
126
 
                (os.path.join(cwd, "LICENSE.txt"),
127
 
                 os.path.join(data_path, "License.txt")),
128
 
            ]
129
 
        else:
130
 
            com_path = os.path.join('support', 'commercial_docs')
131
 
            copy_file_src_dst += [
132
 
                (os.path.join(cwd, com_path, "README_com.txt"),
133
 
                 os.path.join(osx_pkg_resrc, "ReadMe.txt")),
134
 
                (os.path.join(cwd, com_path, "LICENSE_com.txt"),
135
 
                 os.path.join(osx_pkg_resrc, "License.txt")),
136
 
                (os.path.join(cwd, com_path, "README_com.txt"),
137
 
                 os.path.join(data_path, "ReadMe.txt")),
138
 
                (os.path.join(cwd, com_path, "LICENSE_com.txt"),
139
 
                 os.path.join(data_path, "License.txt")),
140
 
            ]
141
 
 
142
 
        property_files = [
143
 
            (os.path.join("support", "osx", "Info.plist"),
144
 
             os.path.join(osx_pkg_contents, "Info.plist")),
145
 
            (os.path.join("support", "osx", "Description.plist"),
146
 
             os.path.join(osx_pkg_resrc, "Description.plist"))
147
 
        ]
148
 
 
149
 
        for pro_file, dest_file in property_files:
150
 
            with open(pro_file) as temp_f:
151
 
                lines = (ln.replace('\n', '') for ln in temp_f)
152
 
                major_version = self.version.split('.')[0]
153
 
                minor_version = self.version.split('.')[1]
154
 
                content = '\n'.join(lines).format(VERSION=self.version,
155
 
                                                  MAJORVERSION=major_version,
156
 
                                                  MINORVERSION=minor_version)
157
 
                with open(dest_file, 'w') as dest_f:
158
 
                    dest_f.write('{0}\n'.format(content))
159
 
 
160
 
        for src, dst in copy_file_src_dst:
161
 
            copy_file(src, dst)
162
 
 
163
 
    def _create_pkg(self, template_name, dmg=False, sign=False, root='',
164
 
                    identity=''):
165
 
        """Create the mac osx pkg and a dmg image if it is required
166
 
 
167
 
        dmg[in]      if true a dmg file will created for the package folder
168
 
        root[in]     the root path for the package contents
169
 
        """
170
 
 
171
 
        osx_dist_name = template_name.format(self.name, self.version)
172
 
        osx_pkg_name = "{0}.pkg".format(osx_dist_name)
173
 
        osx_pkg_contents = os.path.join(osx_pkg_name, 'Contents')
174
 
 
175
 
        if self.debug:
176
 
            log.info("current directory: {0}".format(os.getcwd()))
177
 
        os.chdir(root)
178
 
        log.info("Root directory: {0}".format(os.getcwd()))
179
 
 
180
 
        # create a bom(8) file to tell the installer which files need to be
181
 
        # installed
182
 
        log.info("creating Archive.bom file, that describe files to install")
183
 
        archive_bom_path = os.path.join(osx_pkg_contents, 'Archive.bom')
184
 
        self.spawn(['mkbom', self.dstroot, archive_bom_path])
185
 
 
186
 
        # Create an archive of the files to install
187
 
        log.info("creating Archive.pax with files to be installed")
188
 
        os.chdir(self.dstroot)
189
 
 
190
 
        pax_file = '../{NAME}/Contents/Archive.pax'.format(NAME=osx_pkg_name)
191
 
        self.spawn(['pax', '-w', '-x', 'cpio', '.', '-f', pax_file])
192
 
        os.chdir('../')
193
 
        if self.debug:
194
 
            log.info("current directory: {0}".format(os.getcwd()))
195
 
 
196
 
        # Sign the package
197
 
        # In Order to be possible the certificates needs to be installed
198
 
        if sign:
199
 
            log.info("Signing the package")
200
 
            osx_pkg_name_signed = '{0}_s.pkg'.format(osx_dist_name)
201
 
            self.spawn(['productsign', '--sign', identity,
202
 
                        osx_pkg_name,
203
 
                        osx_pkg_name_signed])
204
 
            self.spawn(['spctl', '-a', '-v', '--type', 'install',
205
 
                        osx_pkg_name_signed])
206
 
            osx_pkg_name = osx_pkg_name_signed
207
 
 
208
 
        # Create a .dmg image
209
 
        if dmg:
210
 
            log.info("Creating dmg file")
211
 
            self.spawn(['hdiutil', 'create', '-volname', osx_dist_name,
212
 
                        '-srcfolder', osx_pkg_name, '-ov', '-format',
213
 
                        'UDZO', '{0}.dmg'.format(osx_dist_name)])
214
 
 
215
 
        log.info("Current directory: {0}".format(os.getcwd()))
216
 
 
217
 
        for base, dirs, files in os.walk(os.getcwd()):
218
 
            for filename in files:
219
 
                if filename.endswith('.dmg'):
220
 
                    new_name = filename.replace(
221
 
                        '{0}'.format(self.version),
222
 
                        '{0}{1}{2}'.format(self.version, self.platform,
223
 
                                                 self.platform_version)
224
 
                    )
225
 
                    file_path = os.path.join(base, filename)
226
 
                    file_dest = os.path.join(self.started_dir,
227
 
                                             self.dist_dir, new_name)
228
 
                    copy_file(file_path, file_dest)
229
 
                    break
230
 
            for dir_name in dirs:
231
 
                print(dir_name)
232
 
                if dir_name.endswith('.pkg'):
233
 
                    new_name = dir_name.replace(
234
 
                        '{0}'.format(self.version),
235
 
                        '{0}{1}{2}'.format(self.version, self.platform,
236
 
                                                 self.platform_version)
237
 
                    )
238
 
                    dir_dest = os.path.join(self.started_dir,
239
 
                                            self.dist_dir, new_name)
240
 
                    copy_tree(dir_name, dir_dest)
241
 
                    break
242
 
            break
243
 
 
244
 
    def run(self):
245
 
        """Run the distutils command"""
246
 
        self.mkpath(self.dist_dir)
247
 
 
248
 
        self.debug = self.verbose
249
 
 
250
 
        build_path = 'build'
251
 
        root = os.path.join(build_path, 'osx')
252
 
        osx_path = os.path.join(root, self.dstroot)
253
 
        self.mkpath(osx_path)
254
 
 
255
 
        if self.debug:
256
 
            log.info("os.getcwd() {0}".format(os.getcwd()))
257
 
        install_cmd = self.reinitialize_command('install',
258
 
                                                reinit_subcommands=1)
259
 
 
260
 
        install_cmd.prefix = osx_path
261
 
        log.info("install_cmd.prefix {0}".format(install_cmd.prefix))
262
 
        if not self.debug:
263
 
            install_cmd.verbose = 0
264
 
        install_cmd.compile = False
265
 
        purelib_path = os.path.join('Library', 'Python',
266
 
                                    sys.version[0:3], 'site-packages')
267
 
        log.info("py_version {0}".format(purelib_path))
268
 
        install_cmd.install_purelib = purelib_path
269
 
        install_cmd.root = osx_path
270
 
        #install_cmd.install_dir = build_path
271
 
        log.info("running install cmd")
272
 
        self.run_command('install')
273
 
        log.info("install cmd finish")
274
 
 
275
 
        copy_tree(os.path.join(osx_path, osx_path, 'bin'),
276
 
                  os.path.join(osx_path, 'bin'))
277
 
 
278
 
        remove_tree(os.path.join(osx_path, 'build'))
279
 
 
280
 
        man_prefix = '/usr/local/share/man'
281
 
        install_man_cmd = self.reinitialize_command('install_man',
282
 
                                                    reinit_subcommands=1)
283
 
 
284
 
        install_man_cmd.root = osx_path
285
 
        install_man_cmd.prefix = man_prefix
286
 
        log.info("install_cmd.root {0}".format(install_man_cmd.root))
287
 
        log.info("install_cmd.prefix {0}".format(install_man_cmd.prefix))
288
 
        if not self.debug:
289
 
            install_man_cmd.verbose = 0
290
 
        log.info("running install_man cmd")
291
 
        self.run_command('install_man')
292
 
        log.info("install_man cmd finish")
293
 
 
294
 
        if self.debug:
295
 
            log.info("current directory: {0}".format(os.getcwd()))
296
 
 
297
 
        template_name = "{0}-{1}"
298
 
        self._prepare_pgk_base(template_name, root=root)
299
 
 
300
 
        if self.debug:
301
 
            log.info("current directory: {0}".format(os.getcwd()))
302
 
 
303
 
        self._create_pkg(template_name, dmg=self.create_dmg, root=root,
304
 
                         sign=self.sign, identity=self.identity)
305
 
 
306
 
        os.chdir(self.started_dir)
307
 
        if self.debug:
308
 
            log.info("current directory: {0}".format(os.getcwd()))
309
 
        if not self.keep_temp:
310
 
            remove_tree(build_path, dry_run=self.dry_run)
311
 
 
312
 
 
313
 
class BuildDistOSXcom(BuildDistOSX):
314
 
    """This class contains the command to built an osx distribution package
315
 
    """
316
 
    description = 'create a mac osx distribution package'
317
 
    user_options = [
318
 
        ('keep-temp', 'k',
319
 
         "keep the pseudo-installation tree around after "
320
 
         "creating the distribution archive"),
321
 
        ('create-dmg', 'c',
322
 
         "create a dmg image from the resulting package file "
323
 
         "(default 'False')"),
324
 
        ('sign', 's',
325
 
         "signs the package file (default 'False')"),
326
 
        ('identity=', 'i',
327
 
         "identity or name of the certificate to use to sign the package file"
328
 
         "(default 'MySQL-Utilities')"),
329
 
        ('dist-dir=', 'd',
330
 
         "directory to put final built distributions in"),
331
 
        ('platform=', 'p',
332
 
         "name of the platform in resulting file "
333
 
         "(default '{0}')".format(BuildDistOSX.platf_n)),
334
 
        ('platform-version=', 'v',
335
 
         "version of the platform in resulting file "
336
 
         "(default '{0}')".format(BuildDistOSX.platf_v))
337
 
    ]
338
 
 
339
 
    boolean_options = ['keep-temp', 'create-dmg', 'sign']
340
 
 
341
 
    def initialize_options(self):
342
 
        """Initialize the options"""
343
 
        self.name = self.distribution.get_name()
344
 
        self.version = self.distribution.get_version()
345
 
        self.keep_temp = None
346
 
        self.create_dmg = False
347
 
        self.dist_dir = None
348
 
        self.started_dir = os.getcwd()
349
 
        self.platform = self.platf_n
350
 
        self.platform_version = self.platf_v
351
 
        self.debug = False
352
 
        self.osx_pkg_name = "{0}-{1}.pkg".format(self.name, self.version)
353
 
        self.dstroot = "dstroot"
354
 
        self.sign = False
355
 
        self.identity = "MySQL-Utilities"
356
 
 
357
 
    def finalize_options(self):
358
 
        """Finalize the options"""
359
 
        self.set_undefined_options('bdist',
360
 
                                   ('dist_dir', 'dist_dir'))
361
 
 
362
 
    def run(self):
363
 
        """Run the distutils command"""
364
 
        log.info("self.name = {0}".format(self.name))
365
 
        self.mkpath(self.dist_dir)
366
 
 
367
 
        self.debug = self.verbose
368
 
 
369
 
        build_path = 'build'
370
 
        root = os.path.join(build_path, 'osx')
371
 
        osx_path = os.path.join(root, self.dstroot)
372
 
        self.mkpath(osx_path)
373
 
 
374
 
        if self.debug:
375
 
            log.info("current directory: {0}".format(os.getcwd()))
376
 
 
377
 
        log.info("Current directory: {0}".format(os.getcwd()))
378
 
        bdist = self.get_finalized_command('bdist_com')
379
 
        bdist.dist_dir = root
380
 
        bdist.prefix = osx_path
381
 
        log.info("install_cmd.prefix {0}".format(bdist.prefix))
382
 
        if not self.debug:
383
 
            bdist.verbose = 0
384
 
        bdist.compile = False
385
 
        purelib_path = os.path.join(osx_path, 'Library', 'Python',
386
 
                                    sys.version[0:3], 'site-packages')
387
 
        log.info("py_version {0}".format(purelib_path))
388
 
        bdist.bdist_dir = purelib_path
389
 
        bdist.man_root = osx_path
390
 
        bdist.man_prefix = os.path.join('usr', 'local', 'share', 'man')
391
 
        bdist.bin_install_dir = os.path.join(osx_path, 'bin')
392
 
        self.run_command('bdist_com')
393
 
        if self.debug:
394
 
            log.info("current directory: {0}".format(os.getcwd()))
395
 
        log.info("bdist_com cmd finish")
396
 
 
397
 
        if self.distribution.data_files:
398
 
            install_cmd = self.get_finalized_command('install_data')
399
 
            log.info("install_cmd.dist_dir {0}".format(root))
400
 
            install_cmd.install_dir = root
401
 
            log.info("install_cmd.root {0}".format(osx_path))
402
 
            install_cmd.root = osx_path
403
 
            log.info("install_cmd.prefix {0}".format(bdist.prefix))
404
 
 
405
 
            self.run_command('install_data')
406
 
            if self.debug:
407
 
                log.info("current directory: {0}".format(os.getcwd()))
408
 
            log.info("install_cmd cmd finish")
409
 
 
410
 
        # Copy necessary files to build osx package.
411
 
        if self.debug:
412
 
            log.info('dir(bdist) {0}'.format(dir(bdist)))
413
 
            log.info('bdist.dist_name {0}'.format(bdist.dist_name))
414
 
 
415
 
        template_name = "{0}-commercial-{1}"
416
 
        self._prepare_pgk_base(template_name, root=root, gpl=False)
417
 
 
418
 
        if self.debug:
419
 
            log.info("current directory: {0}".format(os.getcwd()))
420
 
 
421
 
        self._create_pkg(template_name, dmg=self.create_dmg, root=root,
422
 
                         sign=self.sign, identity=self.identity)
423
 
 
424
 
        os.chdir(self.started_dir)
425
 
        if self.debug:
426
 
            log.info("current directory: {0}".format(os.getcwd()))
427
 
        if not self.keep_temp:
428
 
            remove_tree(build_path, dry_run=self.dry_run)
 
1
#
 
2
# Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; version 2 of the License.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
16
#
 
17
"""This Class extends DistUtils commands for create mac osx distribution
 
18
packages
 
19
"""
 
20
 
 
21
import os
 
22
import platform
 
23
import sys
 
24
 
 
25
from distutils import log
 
26
from distutils.command.bdist import bdist
 
27
from distutils.file_util import copy_file
 
28
from distutils.dir_util import copy_tree, remove_tree
 
29
 
 
30
 
 
31
class BuildDistOSX(bdist):
 
32
    """This class contains the command to built an osx distribution package
 
33
    """
 
34
    platf_n = '-osx'
 
35
    platf_v = '.'.join(platform.mac_ver()[0].split('.', 2)[0:2])
 
36
    description = 'create a mac osx distribution package'
 
37
    user_options = [
 
38
        ('keep-temp', 'k',
 
39
         "keep the pseudo-installation tree around after "
 
40
         "creating the distribution archive"),
 
41
        ('create-dmg', 'c',
 
42
         "create a dmg image from the resulting package file "
 
43
         "(default 'False')"),
 
44
        ('sign', 's',
 
45
         "signs the package file (default 'False')"),
 
46
        ('identity=', 'i',
 
47
         "identity or name of the certificate to use to sign the package file"
 
48
         "(default 'MySQL-Utilities')"),
 
49
        ('dist-dir=', 'd',
 
50
         "directory to put final built distributions in"),
 
51
        ('platform=', 'p',
 
52
         "name of the platform in resulting file "
 
53
         "(default '{0}')".format(platf_n)),
 
54
        ('platform-version=', 'v',
 
55
         "version of the platform in resulting file "
 
56
         "(default '{0}')".format(platf_v))
 
57
    ]
 
58
 
 
59
    boolean_options = ['keep-temp', 'create-dmg', 'sign']
 
60
 
 
61
    def initialize_options(self):
 
62
        """Initialize the options"""
 
63
        self.name = self.distribution.get_name()
 
64
        self.version = self.distribution.get_version()
 
65
        self.keep_temp = None
 
66
        self.create_dmg = False
 
67
        self.dist_dir = None
 
68
        self.started_dir = os.getcwd()
 
69
        self.platform = self.platf_n
 
70
        self.platform_version = self.platf_v
 
71
        self.debug = False
 
72
        self.osx_pkg_name = "{0}-{1}.pkg".format(self.name, self.version)
 
73
        self.dstroot = "dstroot"
 
74
        self.sign = False
 
75
        self.identity = "MySQL-Utilities"
 
76
 
 
77
    def finalize_options(self):
 
78
        """Finalize the options"""
 
79
        self.set_undefined_options('bdist',
 
80
                                   ('dist_dir', 'dist_dir'))
 
81
 
 
82
    def _prepare_pgk_base(self, template_name, root='', gpl=True):
 
83
        """Create and populate the src base directory
 
84
 
 
85
        osx_pkg_name[in] the name of the resulting package
 
86
        root[in]         the root path for the package contents
 
87
        gpl[in]          if false license and readme will correspond to the
 
88
                         commercial package instead of GPL files. default=True
 
89
        """
 
90
 
 
91
        # copy and create necessary files
 
92
        osx_dist_name = template_name.format(self.name, self.version)
 
93
        osx_pkg_name = "{0}.pkg".format(osx_dist_name)
 
94
        osx_pkg_contents = os.path.join(root, osx_pkg_name, 'Contents')
 
95
        osx_pkg_resrc = os.path.join(osx_pkg_contents, 'Resources')
 
96
        self.mkpath(osx_pkg_resrc)
 
97
        osx_path = os.path.join(root, self.dstroot)
 
98
 
 
99
        cwd = os.path.join(os.getcwd())
 
100
 
 
101
        copy_file_src_dst = [
 
102
            (os.path.join("support", "osx", "PkgInfo"),
 
103
             os.path.join(osx_pkg_contents, "PkgInfo")),
 
104
            (os.path.join("support", "osx", "background.jpg"),
 
105
             os.path.join(osx_pkg_resrc, "background.jpg")),
 
106
            (os.path.join("support", "osx", "Welcome.rtf"),
 
107
             os.path.join(osx_pkg_resrc, "Welcome.rtf"))
 
108
        ]
 
109
 
 
110
        # No special folder for GPL or commercial. Files inside the directory
 
111
        # will determine what it is.
 
112
        data_path = os.path.join(
 
113
            osx_path, 'usr', 'local',
 
114
            '{0}-{1}'.format(self.name, self.version)
 
115
        )
 
116
        self.mkpath(data_path)
 
117
 
 
118
        if gpl:
 
119
            copy_file_src_dst += [
 
120
                (os.path.join(cwd, "README.txt"),
 
121
                 os.path.join(osx_pkg_resrc, "ReadMe.txt")),
 
122
                (os.path.join(cwd, "LICENSE.txt"),
 
123
                 os.path.join(osx_pkg_resrc, "License.txt")),
 
124
                (os.path.join(cwd, "README.txt"),
 
125
                 os.path.join(data_path, "ReadMe_Utilities.txt")),
 
126
                (os.path.join(cwd, "CHANGES.txt"),
 
127
                 os.path.join(data_path, "CHANGES_Utilities.txt")),
 
128
                (os.path.join(cwd, "LICENSE.txt"),
 
129
                 os.path.join(data_path, "License.txt")),
 
130
                (os.path.join(cwd, "README_fabric.txt"),
 
131
                 os.path.join(data_path, "ReadMe_fabric.txt")),
 
132
                (os.path.join(cwd, "CHANGES_fabric.txt"),
 
133
                 os.path.join(data_path, "CHANGES_fabric.txt"))
 
134
            ]
 
135
        else:
 
136
            com_path = os.path.join('support', 'commercial_docs')
 
137
            copy_file_src_dst += [
 
138
                (os.path.join(cwd, com_path, "README_com.txt"),
 
139
                 os.path.join(osx_pkg_resrc, "ReadMe.txt")),
 
140
                (os.path.join(cwd, com_path, "LICENSE_com.txt"),
 
141
                 os.path.join(osx_pkg_resrc, "License.txt")),
 
142
                (os.path.join(cwd, com_path, "README_com.txt"),
 
143
                 os.path.join(data_path, "ReadMe.txt")),
 
144
                (os.path.join(cwd, com_path, "LICENSE_com.txt"),
 
145
                 os.path.join(data_path, "License.txt")),
 
146
            ]
 
147
 
 
148
        property_files = [
 
149
            (os.path.join("support", "osx", "Info.plist"),
 
150
             os.path.join(osx_pkg_contents, "Info.plist")),
 
151
            (os.path.join("support", "osx", "Description.plist"),
 
152
             os.path.join(osx_pkg_resrc, "Description.plist"))
 
153
        ]
 
154
 
 
155
        for pro_file, dest_file in property_files:
 
156
            with open(pro_file) as temp_f:
 
157
                lines = (ln.replace('\n', '') for ln in temp_f)
 
158
                major_version = self.version.split('.')[0]
 
159
                minor_version = self.version.split('.')[1]
 
160
                content = '\n'.join(lines).format(VERSION=self.version,
 
161
                                                  MAJORVERSION=major_version,
 
162
                                                  MINORVERSION=minor_version)
 
163
                with open(dest_file, 'w') as dest_f:
 
164
                    dest_f.write('{0}\n'.format(content))
 
165
 
 
166
        for src, dst in copy_file_src_dst:
 
167
            if os.path.exists(src):
 
168
                copy_file(src, dst)
 
169
            else:
 
170
                log.info("File not found: {0}".format(src))
 
171
 
 
172
    def _create_pkg(self, template_name, dmg=False, sign=False, root='',
 
173
                    identity=''):
 
174
        """Create the mac osx pkg and a dmg image if it is required
 
175
 
 
176
        dmg[in]      if true a dmg file will created for the package folder
 
177
        root[in]     the root path for the package contents
 
178
        """
 
179
 
 
180
        osx_dist_name = template_name.format(self.name, self.version)
 
181
        osx_pkg_name = "{0}.pkg".format(osx_dist_name)
 
182
        osx_pkg_contents = os.path.join(osx_pkg_name, 'Contents')
 
183
 
 
184
        if self.debug:
 
185
            log.info("current directory: {0}".format(os.getcwd()))
 
186
        os.chdir(root)
 
187
        log.info("Root directory: {0}".format(os.getcwd()))
 
188
 
 
189
        # create a bom(8) file to tell the installer which files need to be
 
190
        # installed
 
191
        log.info("creating Archive.bom file, that describe files to install")
 
192
        archive_bom_path = os.path.join(osx_pkg_contents, 'Archive.bom')
 
193
        self.spawn(['mkbom', self.dstroot, archive_bom_path])
 
194
 
 
195
        # Create an archive of the files to install
 
196
        log.info("creating Archive.pax with files to be installed")
 
197
        os.chdir(self.dstroot)
 
198
 
 
199
        pax_file = '../{NAME}/Contents/Archive.pax'.format(NAME=osx_pkg_name)
 
200
        self.spawn(['pax', '-w', '-x', 'cpio', '.', '-f', pax_file])
 
201
        os.chdir('../')
 
202
        if self.debug:
 
203
            log.info("current directory: {0}".format(os.getcwd()))
 
204
 
 
205
        # Sign the package
 
206
        # In Order to be possible the certificates needs to be installed
 
207
        if sign:
 
208
            log.info("Signing the package")
 
209
            osx_pkg_name_signed = '{0}_s.pkg'.format(osx_dist_name)
 
210
            self.spawn(['productsign', '--sign', identity,
 
211
                        osx_pkg_name,
 
212
                        osx_pkg_name_signed])
 
213
            self.spawn(['spctl', '-a', '-v', '--type', 'install',
 
214
                        osx_pkg_name_signed])
 
215
            osx_pkg_name = osx_pkg_name_signed
 
216
 
 
217
        # Create a .dmg image
 
218
        if dmg:
 
219
            log.info("Creating dmg file")
 
220
            self.spawn(['hdiutil', 'create', '-volname', osx_dist_name,
 
221
                        '-srcfolder', osx_pkg_name, '-ov', '-format',
 
222
                        'UDZO', '{0}.dmg'.format(osx_dist_name)])
 
223
 
 
224
        log.info("Current directory: {0}".format(os.getcwd()))
 
225
 
 
226
        for base, dirs, files in os.walk(os.getcwd()):
 
227
            for filename in files:
 
228
                if filename.endswith('.dmg'):
 
229
                    new_name = filename.replace(
 
230
                        '{0}'.format(self.version),
 
231
                        '{0}{1}{2}'.format(self.version, self.platform,
 
232
                                                 self.platform_version)
 
233
                    )
 
234
                    file_path = os.path.join(base, filename)
 
235
                    file_dest = os.path.join(self.started_dir,
 
236
                                             self.dist_dir, new_name)
 
237
                    copy_file(file_path, file_dest)
 
238
                    break
 
239
            for dir_name in dirs:
 
240
                print(dir_name)
 
241
                if dir_name.endswith('.pkg'):
 
242
                    new_name = dir_name.replace(
 
243
                        '{0}'.format(self.version),
 
244
                        '{0}{1}{2}'.format(self.version, self.platform,
 
245
                                                 self.platform_version)
 
246
                    )
 
247
                    dir_dest = os.path.join(self.started_dir,
 
248
                                            self.dist_dir, new_name)
 
249
                    copy_tree(dir_name, dir_dest)
 
250
                    break
 
251
            break
 
252
 
 
253
    def run(self):
 
254
        """Run the distutils command"""
 
255
        self.mkpath(self.dist_dir)
 
256
 
 
257
        self.debug = self.verbose
 
258
 
 
259
        build_path = 'build'
 
260
        root = os.path.join(build_path, 'osx')
 
261
        osx_path = os.path.join(root, self.dstroot)
 
262
        self.mkpath(osx_path)
 
263
 
 
264
        if self.debug:
 
265
            log.info("os.getcwd() {0}".format(os.getcwd()))
 
266
        install_cmd = self.reinitialize_command('install',
 
267
                                                reinit_subcommands=1)
 
268
 
 
269
        install_cmd.prefix = osx_path
 
270
        log.info("install_cmd.prefix {0}".format(install_cmd.prefix))
 
271
        if not self.debug:
 
272
            install_cmd.verbose = 0
 
273
        install_cmd.compile = False
 
274
        purelib_path = os.path.join('Library', 'Python',
 
275
                                    sys.version[0:3], 'site-packages')
 
276
        log.info("py_version {0}".format(purelib_path))
 
277
        install_cmd.install_purelib = purelib_path
 
278
        install_cmd.root = osx_path
 
279
        #install_cmd.install_dir = build_path
 
280
        log.info("running install cmd")
 
281
        self.run_command('install')
 
282
        log.info("install cmd finish")
 
283
 
 
284
        copy_tree(os.path.join(osx_path, osx_path, 'bin'),
 
285
                  os.path.join(osx_path, 'bin'))
 
286
 
 
287
        remove_tree(os.path.join(osx_path, 'build'))
 
288
 
 
289
        man_prefix = '/usr/local/share/man'
 
290
        install_man_cmd = self.reinitialize_command('install_man',
 
291
                                                    reinit_subcommands=1)
 
292
 
 
293
        install_man_cmd.root = osx_path
 
294
        install_man_cmd.prefix = man_prefix
 
295
        log.info("install_cmd.root {0}".format(install_man_cmd.root))
 
296
        log.info("install_cmd.prefix {0}".format(install_man_cmd.prefix))
 
297
        if not self.debug:
 
298
            install_man_cmd.verbose = 0
 
299
        log.info("running install_man cmd")
 
300
        self.run_command('install_man')
 
301
        log.info("install_man cmd finish")
 
302
 
 
303
        if self.debug:
 
304
            log.info("current directory: {0}".format(os.getcwd()))
 
305
 
 
306
        template_name = "{0}-{1}"
 
307
        self._prepare_pgk_base(template_name, root=root)
 
308
 
 
309
        if self.debug:
 
310
            log.info("current directory: {0}".format(os.getcwd()))
 
311
 
 
312
        self._create_pkg(template_name, dmg=self.create_dmg, root=root,
 
313
                         sign=self.sign, identity=self.identity)
 
314
 
 
315
        os.chdir(self.started_dir)
 
316
        if self.debug:
 
317
            log.info("current directory: {0}".format(os.getcwd()))
 
318
        if not self.keep_temp:
 
319
            remove_tree(build_path, dry_run=self.dry_run)
 
320
 
 
321
 
 
322
class BuildDistOSXcom(BuildDistOSX):
 
323
    """This class contains the command to built an osx distribution package
 
324
    """
 
325
    description = 'create a mac osx distribution package'
 
326
    user_options = [
 
327
        ('keep-temp', 'k',
 
328
         "keep the pseudo-installation tree around after "
 
329
         "creating the distribution archive"),
 
330
        ('create-dmg', 'c',
 
331
         "create a dmg image from the resulting package file "
 
332
         "(default 'False')"),
 
333
        ('sign', 's',
 
334
         "signs the package file (default 'False')"),
 
335
        ('identity=', 'i',
 
336
         "identity or name of the certificate to use to sign the package file"
 
337
         "(default 'MySQL-Utilities')"),
 
338
        ('dist-dir=', 'd',
 
339
         "directory to put final built distributions in"),
 
340
        ('platform=', 'p',
 
341
         "name of the platform in resulting file "
 
342
         "(default '{0}')".format(BuildDistOSX.platf_n)),
 
343
        ('platform-version=', 'v',
 
344
         "version of the platform in resulting file "
 
345
         "(default '{0}')".format(BuildDistOSX.platf_v))
 
346
    ]
 
347
 
 
348
    boolean_options = ['keep-temp', 'create-dmg', 'sign']
 
349
 
 
350
    def initialize_options(self):
 
351
        """Initialize the options"""
 
352
        self.name = self.distribution.get_name()
 
353
        self.version = self.distribution.get_version()
 
354
        self.keep_temp = None
 
355
        self.create_dmg = False
 
356
        self.dist_dir = None
 
357
        self.started_dir = os.getcwd()
 
358
        self.platform = self.platf_n
 
359
        self.platform_version = self.platf_v
 
360
        self.debug = False
 
361
        self.osx_pkg_name = "{0}-{1}.pkg".format(self.name, self.version)
 
362
        self.dstroot = "dstroot"
 
363
        self.sign = False
 
364
        self.identity = "MySQL-Utilities"
 
365
 
 
366
    def finalize_options(self):
 
367
        """Finalize the options"""
 
368
        self.set_undefined_options('bdist',
 
369
                                   ('dist_dir', 'dist_dir'))
 
370
 
 
371
    def run(self):
 
372
        """Run the distutils command"""
 
373
        log.info("self.name = {0}".format(self.name))
 
374
        self.mkpath(self.dist_dir)
 
375
 
 
376
        self.debug = self.verbose
 
377
 
 
378
        build_path = 'build'
 
379
        root = os.path.join(build_path, 'osx')
 
380
        osx_path = os.path.join(root, self.dstroot)
 
381
        self.mkpath(osx_path)
 
382
 
 
383
        if self.debug:
 
384
            log.info("current directory: {0}".format(os.getcwd()))
 
385
 
 
386
        log.info("Current directory: {0}".format(os.getcwd()))
 
387
        bdist = self.get_finalized_command('bdist_com')
 
388
        bdist.dist_dir = root
 
389
        bdist.prefix = osx_path
 
390
        log.info("install_cmd.prefix {0}".format(bdist.prefix))
 
391
        if not self.debug:
 
392
            bdist.verbose = 0
 
393
        bdist.compile = False
 
394
        purelib_path = os.path.join(osx_path, 'Library', 'Python',
 
395
                                    sys.version[0:3], 'site-packages')
 
396
        log.info("py_version {0}".format(purelib_path))
 
397
        bdist.bdist_dir = purelib_path
 
398
        bdist.man_root = osx_path
 
399
        bdist.man_prefix = os.path.join('usr', 'local', 'share', 'man')
 
400
        bdist.bin_install_dir = os.path.join(osx_path, 'bin')
 
401
        self.run_command('bdist_com')
 
402
        if self.debug:
 
403
            log.info("current directory: {0}".format(os.getcwd()))
 
404
        log.info("bdist_com cmd finish")
 
405
 
 
406
        if self.distribution.data_files:
 
407
            install_cmd = self.get_finalized_command('install_data')
 
408
            log.info("install_cmd.dist_dir {0}".format(root))
 
409
            install_cmd.install_dir = root
 
410
            log.info("install_cmd.root {0}".format(osx_path))
 
411
            install_cmd.root = osx_path
 
412
            log.info("install_cmd.prefix {0}".format(bdist.prefix))
 
413
 
 
414
            self.run_command('install_data')
 
415
            if self.debug:
 
416
                log.info("current directory: {0}".format(os.getcwd()))
 
417
            log.info("install_cmd cmd finish")
 
418
 
 
419
        # Copy necessary files to build osx package.
 
420
        if self.debug:
 
421
            log.info('dir(bdist) {0}'.format(dir(bdist)))
 
422
            log.info('bdist.dist_name {0}'.format(bdist.dist_name))
 
423
 
 
424
        template_name = "{0}-commercial-{1}"
 
425
        self._prepare_pgk_base(template_name, root=root, gpl=False)
 
426
 
 
427
        if self.debug:
 
428
            log.info("current directory: {0}".format(os.getcwd()))
 
429
 
 
430
        self._create_pkg(template_name, dmg=self.create_dmg, root=root,
 
431
                         sign=self.sign, identity=self.identity)
 
432
 
 
433
        os.chdir(self.started_dir)
 
434
        if self.debug:
 
435
            log.info("current directory: {0}".format(os.getcwd()))
 
436
        if not self.keep_temp:
 
437
            remove_tree(build_path, dry_run=self.dry_run)