OLD | NEW |
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. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 if not self.base_dir: | 56 if not self.base_dir: |
57 self.base_dir = os.path.dirname(os.path.abspath(__file__)) | 57 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 | 58 # TODO(maruel): This should be in /tmp but that would mean having to fetch |
59 # everytime. This test is already annoyingly slow. | 59 # everytime. This test is already annoyingly slow. |
60 self.rietveld = os.path.join(self.base_dir, '_rietveld') | 60 self.rietveld = os.path.join(self.base_dir, '_rietveld') |
61 self.rietveld_app = os.path.join( | 61 self.rietveld_app = os.path.join( |
62 self.rietveld, 'appengine', 'chromium_rietveld') | 62 self.rietveld, 'appengine', 'chromium_rietveld') |
63 self.test_server = None | 63 self.test_server = None |
64 self.port = None | 64 self.port = None |
65 self.tempdir = None | 65 self.tempdir = None |
66 | 66 self.dev_app = None |
67 # Find the GAE SDK | |
68 previous_dir = '' | |
69 self.sdk_path = '' | |
70 base_dir = self.base_dir | |
71 while base_dir != previous_dir: | |
72 previous_dir = base_dir | |
73 self.sdk_path = os.path.join(base_dir, 'google_appengine') | |
74 if not os.path.isfile(os.path.join(self.sdk_path, 'VERSION')): | |
75 base_dir = os.path.dirname(base_dir) | |
76 self.dev_app = os.path.join(self.sdk_path, 'dev_appserver.py') | |
77 | 67 |
78 def install_prerequisites(self): | 68 def install_prerequisites(self): |
79 # First, verify the Google AppEngine SDK is available. | 69 # First, install the Google AppEngine SDK. |
80 if not os.path.isfile(self.dev_app): | 70 cmd = [os.path.join(self.base_dir, 'get_appengine.py'), |
81 raise Failure( | 71 '--dest=%s' % self.base_dir] |
82 'Install google_appengine sdk in %s or higher up' % self.base_dir) | 72 try: |
| 73 subprocess2.check_call(cmd) |
| 74 except (OSError, subprocess2.CalledProcessError), e: |
| 75 raise Failure('Failed to run %s\n%s' % (cmd, e)) |
| 76 sdk_path = os.path.join(self.base_dir, 'google_appengine') |
| 77 self.dev_app = os.path.join(sdk_path, 'dev_appserver.py') |
83 | 78 |
84 if os.path.isdir(os.path.join(self.rietveld, '.hg')): | 79 if os.path.isdir(os.path.join(self.rietveld, '.hg')): |
85 # Left over from mercurial. Delete it. | 80 # Left over from mercurial. Delete it. |
86 print('Deleting deprecated mercurial rietveld files...') | 81 print('Deleting deprecated mercurial rietveld files...') |
87 shutil.rmtree(self.rietveld) | 82 shutil.rmtree(self.rietveld) |
88 | 83 |
89 # Second, checkout rietveld if not available. | 84 # Second, checkout rietveld if not available. |
90 if not os.path.isdir(self.rietveld): | 85 if not os.path.isdir(self.rietveld): |
91 print('Checking out rietveld...') | 86 print('Checking out rietveld...') |
92 try: | 87 try: |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 instance.start_server(verbose=options.verbose) | 179 instance.start_server(verbose=options.verbose) |
185 print 'Local rietveld instance started on port %d' % instance.port | 180 print 'Local rietveld instance started on port %d' % instance.port |
186 while True: | 181 while True: |
187 time.sleep(0.1) | 182 time.sleep(0.1) |
188 finally: | 183 finally: |
189 instance.stop_server() | 184 instance.stop_server() |
190 | 185 |
191 | 186 |
192 if __name__ == '__main__': | 187 if __name__ == '__main__': |
193 main() | 188 main() |
OLD | NEW |