~ubuntu-branches/ubuntu/trusty/python-keystoneclient/trusty-proposed

« back to all changes in this revision

Viewing changes to tools/install_venv_common.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2013-05-29 13:07:56 UTC
  • mfrom: (1.1.19)
  • Revision ID: package-import@ubuntu.com-20130529130756-3h7dh05a39n9uvq5
Tags: 1:0.2.4-0ubuntu1
* New upstream release. 
* debian/control: Add python-d2to1 and python-pbr
* debian/control: Add testrepository, dropped python-nose
* debian/control: Add python-six

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
2
 
3
 
# Copyright 2013 OpenStack, LLC
 
3
# Copyright 2013 OpenStack Foundation
4
4
# Copyright 2013 IBM Corp.
5
5
#
6
6
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
18
18
"""Provides methods needed by installation script for OpenStack development
19
19
virtual environments.
20
20
 
 
21
Since this script is used to bootstrap a virtualenv from the system's Python
 
22
environment, it should be kept strictly compatible with Python 2.6.
 
23
 
21
24
Synced in from openstack-common
22
25
"""
23
26
 
 
27
from __future__ import print_function
 
28
 
 
29
import optparse
24
30
import os
25
31
import subprocess
26
32
import sys
27
33
 
28
34
 
29
 
possible_topdir = os.getcwd()
30
 
if os.path.exists(os.path.join(possible_topdir, "keystoneclient",
31
 
                               "__init__.py")):
32
 
    sys.path.insert(0, possible_topdir)
33
 
 
34
 
 
35
 
from oslo.config import cfg
36
 
 
37
 
 
38
35
class InstallVenv(object):
39
36
 
40
37
    def __init__(self, root, venv, pip_requires, test_requires, py_version,
47
44
        self.project = project
48
45
 
49
46
    def die(self, message, *args):
50
 
        print >> sys.stderr, message % args
 
47
        print(message % args, file=sys.stderr)
51
48
        sys.exit(1)
52
49
 
53
50
    def check_python_version(self):
58
55
                              check_exit_code=True):
59
56
        """Runs a command in an out-of-process shell.
60
57
 
61
 
        Returns the output of that command. Working directory is ROOT.
 
58
        Returns the output of that command. Working directory is self.root.
62
59
        """
63
60
        if redirect_output:
64
61
            stdout = subprocess.PIPE
94
91
        virtual environment.
95
92
        """
96
93
        if not os.path.isdir(self.venv):
97
 
            print 'Creating venv...',
 
94
            print('Creating venv...', end=' ')
98
95
            if no_site_packages:
99
96
                self.run_command(['virtualenv', '-q', '--no-site-packages',
100
97
                                 self.venv])
101
98
            else:
102
99
                self.run_command(['virtualenv', '-q', self.venv])
103
 
            print 'done.'
104
 
            print 'Installing pip in virtualenv...',
 
100
            print('done.')
 
101
            print('Installing pip in venv...', end=' ')
105
102
            if not self.run_command(['tools/with_venv.sh', 'easy_install',
106
103
                                    'pip>1.0']).strip():
107
104
                self.die("Failed to install pip.")
108
 
            print 'done.'
 
105
            print('done.')
109
106
        else:
110
 
            print "venv already exists..."
 
107
            print("venv already exists...")
111
108
            pass
112
109
 
113
110
    def pip_install(self, *args):
116
113
                         redirect_output=False)
117
114
 
118
115
    def install_dependencies(self):
119
 
        print 'Installing dependencies with pip (this can take a while)...'
 
116
        print('Installing dependencies with pip (this can take a while)...')
120
117
 
121
118
        # First things first, make sure our venv has the latest pip and
122
119
        # distribute.
139
136
 
140
137
    def parse_args(self, argv):
141
138
        """Parses command-line arguments."""
142
 
        cli_opts = [
143
 
            cfg.BoolOpt('no-site-packages',
144
 
                        default=False,
145
 
                        short='n',
146
 
                        help="Do not inherit packages from global Python"
147
 
                             "install"),
148
 
        ]
149
 
        CLI = cfg.ConfigOpts()
150
 
        CLI.register_cli_opts(cli_opts)
151
 
        CLI(argv[1:])
152
 
        return CLI
 
139
        parser = optparse.OptionParser()
 
140
        parser.add_option('-n', '--no-site-packages',
 
141
                          action='store_true',
 
142
                          help="Do not inherit packages from global Python "
 
143
                               "install")
 
144
        return parser.parse_args(argv[1:])[0]
153
145
 
154
146
 
155
147
class Distro(InstallVenv):
163
155
            return
164
156
 
165
157
        if self.check_cmd('easy_install'):
166
 
            print 'Installing virtualenv via easy_install...',
 
158
            print('Installing virtualenv via easy_install...', end=' ')
167
159
            if self.run_command(['easy_install', 'virtualenv']):
168
 
                print 'Succeeded'
 
160
                print('Succeeded')
169
161
                return
170
162
            else:
171
 
                print 'Failed'
 
163
                print('Failed')
172
164
 
173
165
        self.die('ERROR: virtualenv not found.\n\n%s development'
174
166
                 ' requires virtualenv, please install it using your'
193
185
        return self.run_command_with_code(['rpm', '-q', pkg],
194
186
                                          check_exit_code=False)[1] == 0
195
187
 
196
 
    def yum_install(self, pkg, **kwargs):
197
 
        print "Attempting to install '%s' via yum" % pkg
198
 
        self.run_command(['sudo', 'yum', 'install', '-y', pkg], **kwargs)
199
 
 
200
188
    def apply_patch(self, originalfile, patchfile):
201
 
        self.run_command(['patch', originalfile, patchfile])
 
189
        self.run_command(['patch', '-N', originalfile, patchfile],
 
190
                         check_exit_code=False)
202
191
 
203
192
    def install_virtualenv(self):
204
193
        if self.check_cmd('virtualenv'):
205
194
            return
206
195
 
207
196
        if not self.check_pkg('python-virtualenv'):
208
 
            self.yum_install('python-virtualenv', check_exit_code=False)
 
197
            self.die("Please install 'python-virtualenv'.")
209
198
 
210
199
        super(Fedora, self).install_virtualenv()
211
200
 
223
212
 
224
213
        # Install "patch" program if it's not there
225
214
        if not self.check_pkg('patch'):
226
 
            self.yum_install('patch')
 
215
            self.die("Please install 'patch'.")
227
216
 
228
217
        # Apply the eventlet patch
229
218
        self.apply_patch(os.path.join(self.venv, 'lib', self.py_version,