~chuck-bell/mysql-utilities/mysql-utilities

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Mats Kindahl
  • Date: 2011-02-17 15:01:46 UTC
  • Revision ID: mats.kindahl@oracle.com-20110217150146-7m5n6cgt7l99nlv8
Tags: release-1.0.1dev1
Adding --skip-profile option to allow the installation
to skip installing a profile script to /etc/profie.d.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
from distutils.core import setup
12
12
 
13
13
from distutils.command.build_scripts import build_scripts as _build_scripts
 
14
from distutils.command.install import install as _install
14
15
from distutils.command.install_scripts import install_scripts as _install_scripts
15
16
from info import META_INFO, INSTALL
16
17
 
40
41
    description = (_install_scripts.description
41
42
                   + " and add path to /etc/profile.d")
42
43
 
 
44
    user_options = _install_scripts.user_options + [
 
45
        ("skip-profile", None, "Skip installing a profile script"),
 
46
        ]
 
47
 
 
48
    boolean_options = _install_scripts.boolean_options + ['skip-profile']
 
49
 
43
50
    profile_file = "/etc/profile.d/mysql-utilities.sh"
44
51
 
 
52
    def initialize_options(self):
 
53
        _install_scripts.initialize_options(self)
 
54
        self.skip_profile = None
 
55
 
 
56
    def finalize_options(self):
 
57
        _install_scripts.finalize_options(self)
 
58
        self.set_undefined_options('install',
 
59
                                   ('skip_profile', 'skip_profile'))
 
60
 
45
61
    def run(self):
 
62
        from distutils import log, dir_util
 
63
        _install_scripts.run(self)
46
64
        # We should probably use distutils.dist.execute here to allow
47
65
        # --dry-run to work properly.
48
 
        from distutils import log, dir_util
49
 
        if os.path.exists(os.path.dirname(self.profile_file)):
50
 
            outfile = self.profile_file
51
 
            if os.path.isdir(outfile) and not os.path.islink(outfile):
52
 
                dir_util.remove_tree(outfile)
53
 
            elif os.path.exists(outfile):
54
 
                log.info("Removing %s", outfile)
55
 
                os.unlink(outfile)
56
 
            script = PROFILE_SCRIPT % (self.install_dir,)
57
 
            log.info("Writing %s", outfile)
58
 
            open(outfile, "w+").write(script)
59
 
            _install_scripts.run(self)
60
 
        else:
61
 
            log.info("Not adding %s", self.profile_file)
 
66
        if not self.skip_profile:
 
67
            if os.path.exists(os.path.dirname(self.profile_file)):
 
68
                outfile = self.profile_file
 
69
                if os.path.isdir(outfile) and not os.path.islink(outfile):
 
70
                    dir_util.remove_tree(outfile)
 
71
                elif os.path.exists(outfile):
 
72
                    log.info("Removing %s", outfile)
 
73
                    os.unlink(outfile)
 
74
                script = PROFILE_SCRIPT % (self.install_dir,)
 
75
                log.info("Writing %s", outfile)
 
76
                open(outfile, "w+").write(script)
 
77
            else:
 
78
                log.info("Not adding %s%s", self.profile_file,
 
79
                         " (skipped)" if self.skip_profile else "")
62
80
 
63
81
    def get_outputs(self):
64
82
        outputs = _install_scripts.get_outputs(self)
65
 
        outputs.append(self.profile_file)
 
83
        if not self.skip_profile:
 
84
            outputs.append(self.profile_file)
66
85
        return outputs
67
86
 
68
87
class install_man(distutils.core.Command):
114
133
 
115
134
# See if we have Sphinx installed, otherwise, just ignore building
116
135
# documentation.
 
136
class install(_install):
 
137
    user_options = _install.user_options + [
 
138
        ("skip-profile", None, "Skip installing a profile script"),
 
139
        ]
 
140
 
 
141
    boolean_options = _install.boolean_options + ['skip-profile']
 
142
 
 
143
    def initialize_options(self):
 
144
        _install.initialize_options(self)
 
145
        self.skip_profile = False
 
146
 
 
147
    def finalize_options(self):
 
148
        _install.finalize_options(self)
 
149
 
 
150
COMMANDS['cmdclass'].update({
 
151
        'install': install,
 
152
        })
 
153
 
117
154
try:
118
155
    import sphinx.setup_command
119
 
    from distutils.command.install import install as _install
120
156
 
121
 
    class install(_install):
122
 
        sub_commands = _install.sub_commands + [
123
 
            ('install_man', lambda self: True),
124
 
            ]
 
157
    # Add install_man command if we have Sphinx
 
158
    install.sub_commands = _install.sub_commands + [
 
159
        ('install_man', lambda self: True),
 
160
        ]
125
161
 
126
162
    COMMANDS['cmdclass'].update({
127
 
            'install': install,
128
163
            'install_man': install_man,
129
164
            'build_sphinx': sphinx.setup_command.BuildDoc,
130
165
            'build_man': sphinx.setup_command.BuildDoc,
134
169
            'build_man': { 'builder': 'man' },
135
170
            })
136
171
except ImportError:
137
 
    # TODO: install pre-generated manual pages
138
 
    # No Sphinx installed
139
 
 
140
 
    from distutils.command.install import install
141
 
 
142
 
    COMMANDS['cmdclass'].update({
143
 
            'install': install,
144
 
    })
 
172
    pass
145
173
 
146
174
class build_scripts(_build_scripts):
147
175
    """Class for providing a customized version of build_scripts.