Merge lp:~markgius/horizon/tools_install_venv_fix into lp:~hudson-openstack/horizon/trunk

Proposed by Mark Gius
Status: Needs review
Proposed branch: lp:~markgius/horizon/tools_install_venv_fix
Merge into: lp:~hudson-openstack/horizon/trunk
Diff against target: 178 lines (+80/-62)
1 file modified
openstack-dashboard/tools/install_venv.py (+80/-62)
To merge this branch: bzr merge lp:~markgius/horizon/tools_install_venv_fix
Reviewer Review Type Date Requested Status
Devin Carlen Pending
Review via email: mp+62031@code.launchpad.net

Description of the change

Fixes for Bug #727414 and #785989. Also brings file into compliance with PEP8.

Tested on Ubuntu 10.04.2.

To post a comment you must log in.

Unmerged revisions

48. By Mark Gius

Merging

47. By Mark Gius

Fixes for #727414 and #785989. Also PEP8 compliance

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openstack-dashboard/tools/install_venv.py'
2--- openstack-dashboard/tools/install_venv.py 2011-05-14 00:07:04 +0000
3+++ openstack-dashboard/tools/install_venv.py 2011-05-23 20:45:57 +0000
4@@ -34,69 +34,87 @@
5
6
7 def die(message, *args):
8- print >>sys.stderr, message % args
9- sys.exit(1)
10-
11-
12-def run_command(cmd, redirect_output=True, check_exit_code=True, cwd=ROOT):
13- """
14- Runs a command in an out-of-process shell, returning the
15- output of that command. Working directory is ROOT.
16- """
17- if redirect_output:
18- stdout = subprocess.PIPE
19- else:
20- stdout = None
21-
22- proc = subprocess.Popen(cmd, cwd=cwd, stdout=stdout)
23- output = proc.communicate()[0]
24- if check_exit_code and proc.returncode != 0:
25- die('Command "%s" failed.\n%s', ' '.join(cmd), output)
26- return output
27-
28-
29-HAS_EASY_INSTALL = bool(run_command(['which', 'easy_install'], check_exit_code=False).strip())
30-HAS_VIRTUALENV = bool(run_command(['which', 'virtualenv'], check_exit_code=False).strip())
31+ print >> sys.stderr, message % args
32+ sys.exit(1)
33+
34+
35+def run_command(cmd, redirect_output=True, fail_exit_nonzero=True, cwd=ROOT):
36+ """
37+ Runs a command in an out-of-process shell, returning the output of that
38+ command and the return code. Working directory is ROOT.
39+ """
40+ if redirect_output:
41+ stdout = subprocess.PIPE
42+ else:
43+ stdout = None
44+
45+ proc = subprocess.Popen(cmd, cwd=cwd, stdout=stdout)
46+ output = proc.communicate()[0]
47+ if fail_exit_nonzero and proc.returncode != 0:
48+ die('Command "%s" failed.\n%s', ' '.join(cmd), output)
49+ return (output, proc.returncode)
50+
51+
52+HAS_EASY_INSTALL = 0 == run_command(['which', 'easy_install'],
53+ fail_exit_nonzero=False)[1]
54+HAS_VIRTUALENV = 0 == run_command(['which', 'virtualenv'],
55+ fail_exit_nonzero=False)[1]
56
57
58 def check_dependencies():
59- """Make sure virtualenv is in the path."""
60-
61- if not HAS_VIRTUALENV:
62- print 'not found.'
63- # Try installing it via easy_install...
64- if HAS_EASY_INSTALL:
65- print 'Installing virtualenv via easy_install...',
66- if not run_command(['which', 'virtualenv']):
67- die('ERROR: virtualenv not found.\n\nevelopment requires virtualenv,'
68- ' please install it using your favorite package management tool')
69- print 'done.'
70- print 'done.'
71+ """Make sure virtualenv is in the path."""
72+
73+ print 'checking dependencies...'
74+ if not HAS_VIRTUALENV:
75+ print 'virtualenv not found.'
76+ # Try installing it via easy_install...
77+ if HAS_EASY_INSTALL:
78+ print 'Installing virtualenv via easy_install...'
79+ output, exitstatus = run_command(['easy_install', 'virtualenv'],
80+ fail_exit_nonzero=False)
81+ if not exitstatus == 0:
82+ die('ERROR: easy_install of virtualenv failed.'
83+ '\n\ndevelopment requires virtualenv, please install'
84+ ' it using your favorite package management tool')
85+
86+ # verify that the place we just installed it is in the path
87+ output, exitstatus = run_command(['which', 'virtualenv'])
88+ if not exitstatus == 0:
89+ die('ERROR: virtualenv not found in path.\n\ndevelopment '
90+ ' requires virtualenv, please install it using your'
91+ ' favorite package management tool and ensure'
92+ ' virtualenv is in your path')
93+ print 'done.'
94+ else:
95+ die('easy_install not found.\n\nInstall easy_install'
96+ ' (python-setuptools in ubuntu) or virtualenv by hand,'
97+ ' then rerun.')
98+ print 'dependency check done.'
99
100
101 def create_virtualenv(venv=VENV):
102- """Creates the virtual environment and installs PIP only into the
103- virtual environment
104- """
105- print 'Creating venv...',
106- run_command(['virtualenv', '-q', '--no-site-packages', VENV])
107- print 'done.'
108- print 'Installing pip in virtualenv...',
109- if not run_command([WITH_VENV, 'easy_install', 'pip']).strip():
110- die("Failed to install pip.")
111- print 'done.'
112+ """Creates the virtual environment and installs PIP only into the
113+ virtual environment
114+ """
115+ print 'Creating venv...',
116+ run_command(['virtualenv', '-q', '--no-site-packages', VENV])
117+ print 'done.'
118+ print 'Installing pip in virtualenv...',
119+ if not 0 == run_command([WITH_VENV, 'easy_install', 'pip'])[1]:
120+ die("Failed to install pip.")
121+ print 'done.'
122
123
124 def install_dependencies(venv=VENV):
125- print 'Installing dependencies with pip (this can take a while)...'
126- run_command([WITH_VENV, 'pip', 'install', '-E', venv, '-r', PIP_REQUIRES],
127- redirect_output=False)
128+ print 'Installing dependencies with pip (this can take a while)...'
129+ run_command([WITH_VENV, 'pip', 'install', '-E', venv, '-r', PIP_REQUIRES],
130+ redirect_output=False)
131
132- # Tell the virtual env how to "import dashboard"
133- py = 'python%d.%d' % (sys.version_info[0], sys.version_info[1])
134- pthfile = os.path.join(venv, "lib", py, "site-packages", "dashboard.pth")
135- f = open(pthfile, 'w')
136- f.write("%s\n" % ROOT)
137+ # Tell the virtual env how to "import dashboard"
138+ py = 'python%d.%d' % (sys.version_info[0], sys.version_info[1])
139+ pthfile = os.path.join(venv, "lib", py, "site-packages", "dashboard.pth")
140+ f = open(pthfile, 'w')
141+ f.write("%s\n" % ROOT)
142
143
144 def install_django_openstack():
145@@ -112,7 +130,7 @@
146
147
148 def print_summary():
149- summary = """
150+ summary = """
151 OpenStack Dashboard development environment setup is complete.
152
153 To activate the virtualenv for the extent of your current shell session you
154@@ -120,16 +138,16 @@
155
156 $ source .dashboard-venv/bin/activate
157 """
158- print summary
159+ print summary
160
161
162 def main():
163- check_dependencies()
164- create_virtualenv()
165- install_dependencies()
166- install_django_openstack()
167- install_django_nova_syspanel()
168- print_summary()
169+ check_dependencies()
170+ create_virtualenv()
171+ install_dependencies()
172+ install_django_openstack()
173+ install_django_nova_syspanel()
174+ print_summary()
175
176 if __name__ == '__main__':
177- main()
178+ main()

Subscribers

People subscribed via source and target branches