Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(139)

Side by Side Diff: testing_support/local_rietveld.py

Issue 1156923006: Install google appengine. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Improve the error message. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Setups a local Rietveld instance to test against a live server for 6 """Setups a local Rietveld instance to test against a live server for
7 integration tests. 7 integration tests.
8 8
9 It makes sure Google AppEngine SDK is found, download Rietveld and Django code 9 It makes sure Google AppEngine SDK is found, download Rietveld and Django code
10 if necessary and starts the server on a free inbound TCP port. 10 if necessary and starts the server on a free inbound TCP port.
11 """ 11 """
12 12
13 import base64
13 import logging 14 import logging
14 import optparse 15 import optparse
15 import os 16 import os
16 import shutil 17 import shutil
17 import socket 18 import socket
18 import sys 19 import sys
19 import tempfile 20 import tempfile
20 import time 21 import time
22 import urllib2
23
24
25 INSTALL_GOOGLE_APPENGINE_HASH = 'f849aad85ac3589c931197bff861faf0e2ef0ece'
26 INSTALL_GOOGLE_APPENGINE_URL = (
27 'https://chromium.googlesource.com/infra/infra/+/%s'
28 '/bootstrap/get_appengine.py?format=TEXT' % INSTALL_GOOGLE_APPENGINE_HASH)
pgervais 2015/05/28 20:51:46 Downloading code before executing it is dangerous.
21 29
22 try: 30 try:
23 import subprocess2 31 import subprocess2
24 except ImportError: 32 except ImportError:
25 sys.path.append( 33 sys.path.append(
26 os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) 34 os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
27 import subprocess2 35 import subprocess2
28 36
29 37
30 class Failure(Exception): 38 class Failure(Exception):
(...skipping 25 matching lines...) Expand all
56 if not self.base_dir: 64 if not self.base_dir:
57 self.base_dir = os.path.dirname(os.path.abspath(__file__)) 65 self.base_dir = os.path.dirname(os.path.abspath(__file__))
58 # TODO(maruel): This should be in /tmp but that would mean having to fetch 66 # TODO(maruel): This should be in /tmp but that would mean having to fetch
59 # everytime. This test is already annoyingly slow. 67 # everytime. This test is already annoyingly slow.
60 self.rietveld = os.path.join(self.base_dir, '_rietveld') 68 self.rietveld = os.path.join(self.base_dir, '_rietveld')
61 self.rietveld_app = os.path.join( 69 self.rietveld_app = os.path.join(
62 self.rietveld, 'appengine', 'chromium_rietveld') 70 self.rietveld, 'appengine', 'chromium_rietveld')
63 self.test_server = None 71 self.test_server = None
64 self.port = None 72 self.port = None
65 self.tempdir = None 73 self.tempdir = None
74 self.dev_app = None
66 75
67 # Find the GAE SDK 76 def urlfetch(self, url):
68 previous_dir = '' 77 req = urllib2.Request(url)
69 self.sdk_path = '' 78 req.add_header('User-Agent', 'depot_tools local_rietveld.py')
70 base_dir = self.base_dir 79 for i in range(4):
pgervais 2015/05/28 20:51:46 Please use an exponential backoff here.
71 while base_dir != previous_dir: 80 try:
72 previous_dir = base_dir 81 return urllib2.urlopen(req).read()
73 self.sdk_path = os.path.join(base_dir, 'google_appengine') 82 except urllib2.URLError:
74 if not os.path.isfile(os.path.join(self.sdk_path, 'VERSION')): 83 if i == 3:
75 base_dir = os.path.dirname(base_dir) 84 raise
76 self.dev_app = os.path.join(self.sdk_path, 'dev_appserver.py') 85
86 def download_base64_and_run(self, url, dest, args=None):
87 with open(dest, 'wb') as f:
88 f.write(base64.b64decode(self.urlfetch(url)))
89 os.chmod(dest, 0755)
90 cmd = [dest]
91 if args:
92 cmd.extend(args)
93 try:
94 subprocess2.check_call(cmd)
95 except (OSError, subprocess2.CalledProcessError), e:
96 raise Failure('Failed to run %s\n%s' % (cmd, e))
77 97
78 def install_prerequisites(self): 98 def install_prerequisites(self):
79 # First, verify the Google AppEngine SDK is available. 99 # First, install the Google AppEngine SDK.
80 if not os.path.isfile(self.dev_app): 100 self.download_base64_and_run(
81 raise Failure( 101 INSTALL_GOOGLE_APPENGINE_URL,
82 'Install google_appengine sdk in %s or higher up' % self.base_dir) 102 '/tmp/get_appengine.py',
103 ['--dest=%s' % self.base_dir])
104 sdk_path = os.path.join(self.base_dir, 'google_appengine')
105 self.dev_app = os.path.join(sdk_path, 'dev_appserver.py')
83 106
84 if os.path.isdir(os.path.join(self.rietveld, '.hg')): 107 if os.path.isdir(os.path.join(self.rietveld, '.hg')):
85 # Left over from mercurial. Delete it. 108 # Left over from mercurial. Delete it.
86 print('Deleting deprecated mercurial rietveld files...') 109 print('Deleting deprecated mercurial rietveld files...')
87 shutil.rmtree(self.rietveld) 110 shutil.rmtree(self.rietveld)
88 111
89 # Second, checkout rietveld if not available. 112 # Second, checkout rietveld if not available.
90 if not os.path.isdir(self.rietveld): 113 if not os.path.isdir(self.rietveld):
91 print('Checking out rietveld...') 114 print('Checking out rietveld...')
92 try: 115 try:
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 instance.start_server(verbose=options.verbose) 207 instance.start_server(verbose=options.verbose)
185 print 'Local rietveld instance started on port %d' % instance.port 208 print 'Local rietveld instance started on port %d' % instance.port
186 while True: 209 while True:
187 time.sleep(0.1) 210 time.sleep(0.1)
188 finally: 211 finally:
189 instance.stop_server() 212 instance.stop_server()
190 213
191 214
192 if __name__ == '__main__': 215 if __name__ == '__main__':
193 main() 216 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698