Chromium Code Reviews| 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 """Client-side script to send a try job to the try server. It communicates to | 6 """Client-side script to send a try job to the try server. It communicates to |
| 7 the try server by either writting to a svn repository or by directly connecting | 7 the try server by either writting to a svn repository or by directly connecting |
| 8 to the server by HTTP. | 8 to the server by HTTP. |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 return self.args[0] + '\n' + HELP_STRING | 84 return self.args[0] + '\n' + HELP_STRING |
| 85 | 85 |
| 86 | 86 |
| 87 def Escape(name): | 87 def Escape(name): |
| 88 """Escapes characters that could interfere with the file system or try job | 88 """Escapes characters that could interfere with the file system or try job |
| 89 parsing. | 89 parsing. |
| 90 """ | 90 """ |
| 91 return re.sub(r'[^\w#-]', '_', name) | 91 return re.sub(r'[^\w#-]', '_', name) |
| 92 | 92 |
| 93 | 93 |
| 94 def _FindRepoCheckoutRoot(path): | |
| 95 """Returns the nearest higher-level repo dir from the specified path. | |
| 96 | |
| 97 Args: | |
| 98 path: The path to use. Defaults to cwd. | |
| 99 """ | |
| 100 path = os.path.abspath(path) | |
| 101 while path != '/': | |
|
M-A Ruel
2011/10/10 18:16:06
I'd like it to be windows-compatible, so I'd use s
rcui1
2011/10/11 19:42:34
Done.
| |
| 102 if os.path.isdir(os.path.join(path, '.repo')): | |
| 103 return path | |
| 104 path = os.path.dirname(path) | |
| 105 return None | |
| 106 | |
| 107 | |
| 94 class SCM(object): | 108 class SCM(object): |
| 95 """Simplistic base class to implement one function: ProcessOptions.""" | 109 """Simplistic base class to implement one function: ProcessOptions.""" |
| 96 def __init__(self, options, path, file_list): | 110 def __init__(self, options, path, file_list): |
| 97 items = path.split('@') | 111 items = path.split('@') |
| 98 assert len(items) <= 2 | 112 assert len(items) <= 2 |
| 99 self.checkout_root = items[0] | 113 self.checkout_root = os.path.abspath(items[0]) |
| 100 items.append(None) | 114 items.append(None) |
| 101 self.diff_against = items[1] | 115 self.diff_against = items[1] |
| 102 self.options = options | 116 self.options = options |
| 103 # Lazy-load file list from the SCM unless files were specified in options. | 117 # Lazy-load file list from the SCM unless files were specified in options. |
| 104 self._files = None | 118 self._files = None |
| 105 self._file_tuples = None | 119 self._file_tuples = None |
| 106 if file_list: | 120 if file_list: |
| 107 self._files = file_list | 121 self._files = file_list |
| 108 self._file_tuples = [('M', f) for f in self.files] | 122 self._file_tuples = [('M', f) for f in self.files] |
| 109 self.options.files = None | 123 self.options.files = None |
| 110 self.codereview_settings = None | 124 self.codereview_settings = None |
| 111 self.codereview_settings_file = 'codereview.settings' | 125 self.codereview_settings_file = 'codereview.settings' |
| 112 self.gclient_root = None | 126 self.toplevel_root = None |
| 113 | 127 |
| 114 def GetFileNames(self): | 128 def GetFileNames(self): |
| 115 """Return the list of files in the diff.""" | 129 """Return the list of files in the diff.""" |
| 116 return self.files | 130 return self.files |
| 117 | 131 |
| 118 def GetCodeReviewSetting(self, key): | 132 def GetCodeReviewSetting(self, key): |
| 119 """Returns a value for the given key for this repository. | 133 """Returns a value for the given key for this repository. |
| 120 | 134 |
| 121 Uses gcl-style settings from the repository. | 135 Uses gcl-style settings from the repository. |
| 122 """ | 136 """ |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 145 'project': self.GetCodeReviewSetting('TRYSERVER_PROJECT'), | 159 'project': self.GetCodeReviewSetting('TRYSERVER_PROJECT'), |
| 146 'root': self.GetCodeReviewSetting('TRYSERVER_ROOT'), | 160 'root': self.GetCodeReviewSetting('TRYSERVER_ROOT'), |
| 147 'patchlevel': self.GetCodeReviewSetting('TRYSERVER_PATCHLEVEL'), | 161 'patchlevel': self.GetCodeReviewSetting('TRYSERVER_PATCHLEVEL'), |
| 148 } | 162 } |
| 149 logging.info('\n'.join(['%s: %s' % (k, v) | 163 logging.info('\n'.join(['%s: %s' % (k, v) |
| 150 for (k, v) in settings.iteritems() if v])) | 164 for (k, v) in settings.iteritems() if v])) |
| 151 for (k, v) in settings.iteritems(): | 165 for (k, v) in settings.iteritems(): |
| 152 if v and getattr(self.options, k) is None: | 166 if v and getattr(self.options, k) is None: |
| 153 setattr(self.options, k, v) | 167 setattr(self.options, k, v) |
| 154 | 168 |
| 155 def _GclientStyleSettings(self): | |
| 156 """Find the root, assuming a gclient-style checkout.""" | |
| 157 if not self.options.no_gclient and not self.options.root: | |
| 158 root = self.checkout_root | |
| 159 self.gclient_root = gclient_utils.FindGclientRoot(root) | |
| 160 if self.gclient_root: | |
| 161 logging.info('Found .gclient at %s' % self.gclient_root) | |
| 162 self.options.root = gclient_utils.PathDifference(self.gclient_root, | |
| 163 root) | |
| 164 | |
| 165 def AutomagicalSettings(self): | 169 def AutomagicalSettings(self): |
| 166 """Determines settings based on supported code review and checkout tools. | 170 """Determines settings based on supported code review and checkout tools. |
| 167 """ | 171 """ |
| 168 self._GclientStyleSettings() | 172 # If user did not provide toplevel root, try to find gclient root first. |
| 173 if not self.toplevel_root and not self.options.no_gclient: | |
| 174 self.toplevel_root = gclient_utils.FindGclientRoot(self.checkout_root) | |
| 175 if self.toplevel_root: | |
| 176 logging.info('Found .gclient at %s' % self.toplevel_root) | |
|
M-A Ruel
2011/10/10 18:16:06
If you want, add:
assert os.path.abspath(self.topl
rcui1
2011/10/11 19:42:34
Done.
| |
| 177 | |
| 178 # If still no toplevel root found, try to find repo-managed chromium root | |
| 179 if not self.toplevel_root: | |
| 180 repo_root = _FindRepoCheckoutRoot(self.checkout_root) | |
| 181 if repo_root: | |
| 182 chromium_root = os.path.join(repo_root, | |
|
M-A Ruel
2011/10/10 18:16:06
weird alignment, also I've refrained from hardcodi
rcui1
2011/10/11 19:42:34
Done.
| |
| 183 'chromium') | |
| 184 if self.checkout_root.startswith(chromium_root): | |
| 185 self.toplevel_root = chromium_root | |
| 186 logging.info('Found chromium checkout root at %s' | |
| 187 % self.toplevel_root) | |
| 188 | |
| 189 if self.toplevel_root and not self.options.root: | |
| 190 self.options.root = gclient_utils.PathDifference(self.toplevel_root, | |
| 191 self.checkout_root) | |
| 192 | |
| 169 self._GclStyleSettings() | 193 self._GclStyleSettings() |
| 170 | 194 |
| 171 def ReadRootFile(self, filename): | 195 def ReadRootFile(self, filename): |
| 172 if not self.options.root: | 196 root = cur = os.path.abspath(self.checkout_root) |
|
M-A Ruel
2011/10/10 18:16:06
self.checkout_root is guaranteed to be abspath so
rcui1
2011/10/11 19:42:34
Done.
| |
| 173 filepath = os.path.join(self.checkout_root, filename) | 197 if self.toplevel_root: |
| 174 if os.path.isfile(filepath): | 198 root = os.path.abspath(self.toplevel_root) |
|
M-A Ruel
2011/10/10 18:16:06
If you also abspath toplevel_root, then you can do
rcui1
2011/10/11 19:42:34
I think the logic is pretty clear as it is.
On 20
| |
| 175 logging.info('Found %s at %s' % (filename, self.checkout_root)) | 199 |
| 176 return gclient_utils.FileRead(filepath) | |
| 177 return None | |
| 178 cur = os.path.abspath(self.checkout_root) | |
| 179 if self.gclient_root: | |
| 180 root = os.path.abspath(self.gclient_root) | |
| 181 else: | |
| 182 root = gclient_utils.FindGclientRoot(cur) | |
| 183 if not root: | |
| 184 root = cur | |
| 185 assert cur.startswith(root), (root, cur) | 200 assert cur.startswith(root), (root, cur) |
| 186 while cur.startswith(root): | 201 while cur.startswith(root): |
| 187 filepath = os.path.join(cur, filename) | 202 filepath = os.path.join(cur, filename) |
| 188 if os.path.isfile(filepath): | 203 if os.path.isfile(filepath): |
| 189 logging.info('Found %s at %s' % (filename, cur)) | 204 logging.info('Found %s at %s' % (filename, cur)) |
| 190 return gclient_utils.FileRead(filepath) | 205 return gclient_utils.FileRead(filepath) |
| 191 cur = os.path.dirname(cur) | 206 cur = os.path.dirname(cur) |
| 192 logging.warning('Didn\'t find %s' % filename) | 207 logging.warning('Didn\'t find %s' % filename) |
| 193 return None | 208 return None |
| 194 | 209 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 if options.patchlevel: | 327 if options.patchlevel: |
| 313 values['patchlevel'] = options.patchlevel | 328 values['patchlevel'] = options.patchlevel |
| 314 if options.issue: | 329 if options.issue: |
| 315 values['issue'] = options.issue | 330 values['issue'] = options.issue |
| 316 if options.patchset: | 331 if options.patchset: |
| 317 values['patchset'] = options.patchset | 332 values['patchset'] = options.patchset |
| 318 if options.target: | 333 if options.target: |
| 319 values['target'] = options.target | 334 values['target'] = options.target |
| 320 if options.project: | 335 if options.project: |
| 321 values['project'] = options.project | 336 values['project'] = options.project |
| 337 | |
|
M-A Ruel
2011/10/10 18:16:06
bof, I'd revert this line
rcui1
2011/10/11 19:42:34
Done.
| |
| 322 return values | 338 return values |
| 323 | 339 |
| 324 | 340 |
| 325 def _SendChangeHTTP(options): | 341 def _SendChangeHTTP(options): |
| 326 """Send a change to the try server using the HTTP protocol.""" | 342 """Send a change to the try server using the HTTP protocol.""" |
| 327 if not options.host: | 343 if not options.host: |
| 328 raise NoTryServerAccess('Please use the --host option to specify the try ' | 344 raise NoTryServerAccess('Please use the --host option to specify the try ' |
| 329 'server host to connect to.') | 345 'server host to connect to.') |
| 330 if not options.port: | 346 if not options.port: |
| 331 raise NoTryServerAccess('Please use the --port option to specify the try ' | 347 raise NoTryServerAccess('Please use the --port option to specify the try ' |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 return 1 | 825 return 1 |
| 810 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 826 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 811 print >> sys.stderr, e | 827 print >> sys.stderr, e |
| 812 return 1 | 828 return 1 |
| 813 return 0 | 829 return 0 |
| 814 | 830 |
| 815 | 831 |
| 816 if __name__ == "__main__": | 832 if __name__ == "__main__": |
| 817 fix_encoding.fix_encoding() | 833 fix_encoding.fix_encoding() |
| 818 sys.exit(TryChange(None, None, False)) | 834 sys.exit(TryChange(None, None, False)) |
| OLD | NEW |