second try
[vsorcdistro/.git] / ryu / .eggs / pbr-5.3.1-py2.7.egg / pbr / hooks / commands.py
1 # Copyright 2013 Hewlett-Packard Development Company, L.P.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 import os
17
18 from setuptools.command import easy_install
19
20 from pbr.hooks import base
21 from pbr import options
22 from pbr import packaging
23
24
25 class CommandsConfig(base.BaseConfig):
26
27     section = 'global'
28
29     def __init__(self, config):
30         super(CommandsConfig, self).__init__(config)
31         self.commands = self.config.get('commands', "")
32
33     def save(self):
34         self.config['commands'] = self.commands
35         super(CommandsConfig, self).save()
36
37     def add_command(self, command):
38         self.commands = "%s\n%s" % (self.commands, command)
39
40     def hook(self):
41         self.add_command('pbr.packaging.LocalEggInfo')
42         self.add_command('pbr.packaging.LocalSDist')
43         self.add_command('pbr.packaging.LocalInstallScripts')
44         self.add_command('pbr.packaging.LocalDevelop')
45         self.add_command('pbr.packaging.LocalRPMVersion')
46         self.add_command('pbr.packaging.LocalDebVersion')
47         if os.name != 'nt':
48             easy_install.get_script_args = packaging.override_get_script_args
49
50         if packaging.have_sphinx():
51             self.add_command('pbr.builddoc.LocalBuildDoc')
52
53         if os.path.exists('.testr.conf') and packaging.have_testr():
54             # There is a .testr.conf file. We want to use it.
55             self.add_command('pbr.packaging.TestrTest')
56         elif self.config.get('nosetests', False) and packaging.have_nose():
57             # We seem to still have nose configured
58             self.add_command('pbr.packaging.NoseTest')
59
60         use_egg = options.get_boolean_option(
61             self.pbr_config, 'use-egg', 'PBR_USE_EGG')
62         # We always want non-egg install unless explicitly requested
63         if 'manpages' in self.pbr_config or not use_egg:
64             self.add_command('pbr.packaging.LocalInstall')
65         else:
66             self.add_command('pbr.packaging.InstallWithGit')