| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 | 45 |
| 46 class LocalRietveld(object): | 46 class LocalRietveld(object): |
| 47 """Downloads everything needed to run a local instance of Rietveld.""" | 47 """Downloads everything needed to run a local instance of Rietveld.""" |
| 48 | 48 |
| 49 def __init__(self, base_dir=None): | 49 def __init__(self, base_dir=None): |
| 50 # Paths | 50 # Paths |
| 51 self.base_dir = base_dir | 51 self.base_dir = base_dir |
| 52 if not self.base_dir: | 52 if not self.base_dir: |
| 53 self.base_dir = os.path.dirname(os.path.abspath(__file__)) | 53 self.base_dir = os.path.dirname(os.path.abspath(__file__)) |
| 54 self.base_dir = os.path.realpath(os.path.join(self.base_dir, '..')) | 54 # TODO(maruel): This should be in /tmp but that would mean having to fetch |
| 55 self.sdk_path = os.path.abspath( | 55 # everytime. This test is already annoyingly slow. |
| 56 os.path.join(self.base_dir, '..', 'google_appengine')) | 56 self.rietveld = os.path.join(self.base_dir, '_rietveld') |
| 57 self.dev_app = os.path.join(self.sdk_path, 'dev_appserver.py') | |
| 58 self.rietveld = os.path.join(self.base_dir, 'tests', '_rietveld') | |
| 59 self.test_server = None | 57 self.test_server = None |
| 60 self.port = None | 58 self.port = None |
| 61 | 59 |
| 60 # Find the GAE SDK |
| 61 previous_dir = '' |
| 62 self.sdk_path = '' |
| 63 base_dir = self.base_dir |
| 64 while base_dir != previous_dir: |
| 65 previous_dir = base_dir |
| 66 self.sdk_path = os.path.join(base_dir, 'google_appengine') |
| 67 if not os.path.isfile(os.path.join(self.sdk_path, 'VERSION')): |
| 68 base_dir = os.path.dirname(base_dir) |
| 69 self.dev_app = os.path.join(self.sdk_path, 'dev_appserver.py') |
| 70 |
| 62 def install_prerequisites(self): | 71 def install_prerequisites(self): |
| 63 # First, verify the Google AppEngine SDK is available. | 72 # First, verify the Google AppEngine SDK is available. |
| 64 if not os.path.isfile(self.dev_app): | 73 if not os.path.isfile(self.dev_app): |
| 65 raise Failure('Install google_appengine sdk in %s' % self.sdk_path) | 74 raise Failure( |
| 75 'Install google_appengine sdk in %s or higher up' % self.base_dir) |
| 66 | 76 |
| 67 # Second, checkout rietveld if not available. | 77 # Second, checkout rietveld if not available. |
| 68 if not os.path.isdir(self.rietveld): | 78 if not os.path.isdir(self.rietveld): |
| 69 print('Checking out rietveld...') | 79 print('Checking out rietveld...') |
| 70 try: | 80 try: |
| 71 subprocess2.check_call( | 81 subprocess2.check_call( |
| 72 ['svn', 'co', '-q', 'http://rietveld.googlecode.com/svn/trunk@681', | 82 ['svn', 'co', '-q', 'http://rietveld.googlecode.com/svn/trunk@681', |
| 73 self.rietveld]) | 83 self.rietveld]) |
| 74 except (OSError, subprocess2.CalledProcessError), e: | 84 except (OSError, subprocess2.CalledProcessError), e: |
| 75 raise Failure('Failed to checkout rietveld\n%s' % e) | 85 raise Failure('Failed to checkout rietveld\n%s' % e) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 instance.start_server(verbose=options.verbose) | 136 instance.start_server(verbose=options.verbose) |
| 127 print 'Local rietveld instance started on port %d' % instance.port | 137 print 'Local rietveld instance started on port %d' % instance.port |
| 128 while True: | 138 while True: |
| 129 time.sleep(0.1) | 139 time.sleep(0.1) |
| 130 finally: | 140 finally: |
| 131 instance.stop_server() | 141 instance.stop_server() |
| 132 | 142 |
| 133 | 143 |
| 134 if __name__ == '__main__': | 144 if __name__ == '__main__': |
| 135 main() | 145 main() |
| OLD | NEW |