| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 if not os.path.isfile(self.dev_app): | 64 if not os.path.isfile(self.dev_app): |
| 65 raise Failure('Install google_appengine sdk in %s' % self.sdk_path) | 65 raise Failure('Install google_appengine sdk in %s' % self.sdk_path) |
| 66 | 66 |
| 67 # Second, checkout rietveld if not available. | 67 # Second, checkout rietveld if not available. |
| 68 if not os.path.isdir(self.rietveld): | 68 if not os.path.isdir(self.rietveld): |
| 69 print('Checking out rietveld...') | 69 print('Checking out rietveld...') |
| 70 try: | 70 try: |
| 71 subprocess2.check_call( | 71 subprocess2.check_call( |
| 72 ['svn', 'co', '-q', 'http://rietveld.googlecode.com/svn/trunk@681', | 72 ['svn', 'co', '-q', 'http://rietveld.googlecode.com/svn/trunk@681', |
| 73 self.rietveld]) | 73 self.rietveld]) |
| 74 except subprocess2.CalledProcessError: | 74 except (OSError, subprocess2.CalledProcessError), e: |
| 75 raise Failure('Failed to checkout rietveld') | 75 raise Failure('Failed to checkout rietveld\n%s' % e) |
| 76 else: | 76 else: |
| 77 print('Syncing rietveld...') | 77 print('Syncing rietveld...') |
| 78 try: | 78 try: |
| 79 subprocess2.check_call( | 79 subprocess2.check_call( |
| 80 ['svn', 'up', '-q', '-r', '681'], cwd=self.rietveld) | 80 ['svn', 'up', '-q', '-r', '681'], cwd=self.rietveld) |
| 81 except subprocess2.CalledProcessError: | 81 except (OSError, subprocess2.CalledProcessError), e: |
| 82 raise Failure('Failed to checkout rietveld') | 82 raise Failure('Failed to sync rietveld\n%s' % e) |
| 83 | 83 |
| 84 def start_server(self, verbose=False): | 84 def start_server(self, verbose=False): |
| 85 self.install_prerequisites() | 85 self.install_prerequisites() |
| 86 self.port = find_free_port() | 86 self.port = find_free_port() |
| 87 if verbose: | 87 if verbose: |
| 88 pipe = None | 88 pipe = None |
| 89 else: | 89 else: |
| 90 pipe = subprocess2.VOID | 90 pipe = subprocess2.VOID |
| 91 cmd = [ | 91 cmd = [ |
| 92 sys.executable, |
| 92 self.dev_app, | 93 self.dev_app, |
| 93 '--skip_sdk_update_check', | 94 '--skip_sdk_update_check', |
| 94 '.', | 95 '.', |
| 95 '--port=%d' % self.port, | 96 '--port=%d' % self.port, |
| 96 '--datastore_path=' + os.path.join(self.rietveld, 'tmp.db'), | 97 '--datastore_path=' + os.path.join(self.rietveld, 'tmp.db'), |
| 97 '-c'] | 98 '-c'] |
| 98 self.test_server = subprocess2.Popen( | 99 self.test_server = subprocess2.Popen( |
| 99 cmd, stdout=pipe, stderr=pipe, cwd=self.rietveld) | 100 cmd, stdout=pipe, stderr=pipe, cwd=self.rietveld) |
| 100 # Loop until port 127.0.0.1:port opens or the process dies. | 101 # Loop until port 127.0.0.1:port opens or the process dies. |
| 101 while not test_port(self.port): | 102 while not test_port(self.port): |
| (...skipping 23 matching lines...) Expand all Loading... |
| 125 instance.start_server(verbose=options.verbose) | 126 instance.start_server(verbose=options.verbose) |
| 126 print 'Local rietveld instance started on port %d' % instance.port | 127 print 'Local rietveld instance started on port %d' % instance.port |
| 127 while True: | 128 while True: |
| 128 time.sleep(0.1) | 129 time.sleep(0.1) |
| 129 finally: | 130 finally: |
| 130 instance.stop_server() | 131 instance.stop_server() |
| 131 | 132 |
| 132 | 133 |
| 133 if __name__ == '__main__': | 134 if __name__ == '__main__': |
| 134 main() | 135 main() |
| OLD | NEW |