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. |
11 """ | 11 """ |
12 | 12 |
13 import optparse | 13 import optparse |
14 import os | 14 import os |
| 15 import shutil |
15 import socket | 16 import socket |
16 import sys | 17 import sys |
17 import time | 18 import time |
18 | 19 |
19 import subprocess2 | 20 try: |
| 21 import subprocess2 |
| 22 except ImportError: |
| 23 sys.path.append( |
| 24 os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) |
| 25 import subprocess2 |
20 | 26 |
21 | 27 |
22 class Failure(Exception): | 28 class Failure(Exception): |
23 pass | 29 pass |
24 | 30 |
25 | 31 |
26 def test_port(port): | 32 def test_port(port): |
27 s = socket.socket() | 33 s = socket.socket() |
28 try: | 34 try: |
29 return s.connect_ex(('127.0.0.1', port)) == 0 | 35 return s.connect_ex(('127.0.0.1', port)) == 0 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 if not os.path.isfile(os.path.join(self.sdk_path, 'VERSION')): | 72 if not os.path.isfile(os.path.join(self.sdk_path, 'VERSION')): |
67 base_dir = os.path.dirname(base_dir) | 73 base_dir = os.path.dirname(base_dir) |
68 self.dev_app = os.path.join(self.sdk_path, 'dev_appserver.py') | 74 self.dev_app = os.path.join(self.sdk_path, 'dev_appserver.py') |
69 | 75 |
70 def install_prerequisites(self): | 76 def install_prerequisites(self): |
71 # First, verify the Google AppEngine SDK is available. | 77 # First, verify the Google AppEngine SDK is available. |
72 if not os.path.isfile(self.dev_app): | 78 if not os.path.isfile(self.dev_app): |
73 raise Failure( | 79 raise Failure( |
74 'Install google_appengine sdk in %s or higher up' % self.base_dir) | 80 'Install google_appengine sdk in %s or higher up' % self.base_dir) |
75 | 81 |
| 82 if os.path.isdir(os.path.join(self.rietveld, '.svn')): |
| 83 # Left over from subversion. Delete it. |
| 84 shutil.rmtree(self.rietveld) |
| 85 |
76 # Second, checkout rietveld if not available. | 86 # Second, checkout rietveld if not available. |
| 87 rev = '9349cab9a3bb' |
77 if not os.path.isdir(self.rietveld): | 88 if not os.path.isdir(self.rietveld): |
78 print('Checking out rietveld...') | 89 print('Checking out rietveld...') |
79 try: | 90 try: |
80 subprocess2.check_call( | 91 subprocess2.check_call( |
81 ['svn', 'co', '-q', 'http://rietveld.googlecode.com/svn/trunk@681', | 92 [ 'hg', 'clone', '-q', '-u', rev, '-r', rev, |
82 self.rietveld]) | 93 'https://code.google.com/p/rietveld/', self.rietveld]) |
83 except (OSError, subprocess2.CalledProcessError), e: | 94 except (OSError, subprocess2.CalledProcessError), e: |
84 raise Failure('Failed to checkout rietveld\n%s' % e) | 95 raise Failure( |
| 96 'Failed to checkout rietveld. Do you have mercurial installed?\n' |
| 97 '%s' % e) |
85 else: | 98 else: |
86 print('Syncing rietveld...') | 99 print('Syncing rietveld...') |
87 try: | 100 try: |
88 subprocess2.check_call( | 101 subprocess2.check_call( |
89 ['svn', 'up', '-q', '-r', '681'], cwd=self.rietveld) | 102 ['hg', 'co', '-q', '-C', rev], cwd=self.rietveld) |
90 except (OSError, subprocess2.CalledProcessError), e: | 103 except (OSError, subprocess2.CalledProcessError), e: |
91 raise Failure('Failed to sync rietveld\n%s' % e) | 104 raise Failure('Failed to sync rietveld\n%s' % e) |
92 | 105 |
93 def start_server(self, verbose=False): | 106 def start_server(self, verbose=False): |
94 self.install_prerequisites() | 107 self.install_prerequisites() |
95 self.port = find_free_port() | 108 self.port = find_free_port() |
96 if verbose: | 109 if verbose: |
97 pipe = None | 110 pipe = None |
98 else: | 111 else: |
99 pipe = subprocess2.VOID | 112 pipe = subprocess2.VOID |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 instance.start_server(verbose=options.verbose) | 156 instance.start_server(verbose=options.verbose) |
144 print 'Local rietveld instance started on port %d' % instance.port | 157 print 'Local rietveld instance started on port %d' % instance.port |
145 while True: | 158 while True: |
146 time.sleep(0.1) | 159 time.sleep(0.1) |
147 finally: | 160 finally: |
148 instance.stop_server() | 161 instance.stop_server() |
149 | 162 |
150 | 163 |
151 if __name__ == '__main__': | 164 if __name__ == '__main__': |
152 main() | 165 main() |
OLD | NEW |