| 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 """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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 settings_file = self.ReadRootFile(self.codereview_settings_file) | 142 settings_file = self.ReadRootFile(self.codereview_settings_file) |
| 143 if settings_file: | 143 if settings_file: |
| 144 for line in settings_file.splitlines(): | 144 for line in settings_file.splitlines(): |
| 145 if not line or line.lstrip().startswith('#'): | 145 if not line or line.lstrip().startswith('#'): |
| 146 continue | 146 continue |
| 147 k, v = line.split(":", 1) | 147 k, v = line.split(":", 1) |
| 148 self.codereview_settings[k.strip()] = v.strip() | 148 self.codereview_settings[k.strip()] = v.strip() |
| 149 return self.codereview_settings.get(key, '') | 149 return self.codereview_settings.get(key, '') |
| 150 | 150 |
| 151 def _GclStyleSettings(self): | 151 def _GclStyleSettings(self): |
| 152 """Set default settings based on the gcl-style settings from the | 152 """Set default settings based on the gcl-style settings from the repository. |
| 153 repository.""" | 153 |
| 154 The settings in the self.options object will only be set if no previous |
| 155 value exists (i.e. command line flags to the try command will override the |
| 156 settings in codereview.settings). |
| 157 """ |
| 154 settings = { | 158 settings = { |
| 155 'port': self.GetCodeReviewSetting('TRYSERVER_HTTP_PORT'), | 159 'port': self.GetCodeReviewSetting('TRYSERVER_HTTP_PORT'), |
| 156 'host': self.GetCodeReviewSetting('TRYSERVER_HTTP_HOST'), | 160 'host': self.GetCodeReviewSetting('TRYSERVER_HTTP_HOST'), |
| 157 'svn_repo': self.GetCodeReviewSetting('TRYSERVER_SVN_URL'), | 161 'svn_repo': self.GetCodeReviewSetting('TRYSERVER_SVN_URL'), |
| 158 'project': self.GetCodeReviewSetting('TRYSERVER_PROJECT'), | 162 'project': self.GetCodeReviewSetting('TRYSERVER_PROJECT'), |
| 159 'root': self.GetCodeReviewSetting('TRYSERVER_ROOT'), | 163 'root': self.GetCodeReviewSetting('TRYSERVER_ROOT'), |
| 160 'patchlevel': self.GetCodeReviewSetting('TRYSERVER_PATCHLEVEL'), | 164 'patchlevel': self.GetCodeReviewSetting('TRYSERVER_PATCHLEVEL'), |
| 161 } | 165 } |
| 162 logging.info('\n'.join(['%s: %s' % (k, v) | 166 logging.info('\n'.join(['%s: %s' % (k, v) |
| 163 for (k, v) in settings.iteritems() if v])) | 167 for (k, v) in settings.iteritems() if v])) |
| 164 for (k, v) in settings.iteritems(): | 168 for (k, v) in settings.iteritems(): |
| 169 # Avoid overwriting options already set using command line flags. |
| 165 if v and getattr(self.options, k) is None: | 170 if v and getattr(self.options, k) is None: |
| 166 setattr(self.options, k, v) | 171 setattr(self.options, k, v) |
| 167 | 172 |
| 168 def AutomagicalSettings(self): | 173 def AutomagicalSettings(self): |
| 169 """Determines settings based on supported code review and checkout tools. | 174 """Determines settings based on supported code review and checkout tools. |
| 170 """ | 175 """ |
| 171 self._GclStyleSettings() | 176 # Try to find gclient or repo root first. |
| 172 # Try to find gclient or repo root. | |
| 173 if not self.options.no_search: | 177 if not self.options.no_search: |
| 174 self.toplevel_root = gclient_utils.FindGclientRoot(self.checkout_root) | 178 self.toplevel_root = gclient_utils.FindGclientRoot(self.checkout_root) |
| 175 if self.toplevel_root: | 179 if self.toplevel_root: |
| 176 logging.info('Found .gclient at %s' % self.toplevel_root) | 180 logging.info('Found .gclient at %s' % self.toplevel_root) |
| 177 else: | 181 else: |
| 178 self.toplevel_root = gclient_utils.FindFileUpwards( | 182 self.toplevel_root = gclient_utils.FindFileUpwards( |
| 179 os.path.join('..', '.repo'), self.checkout_root) | 183 os.path.join('..', '.repo'), self.checkout_root) |
| 180 if self.toplevel_root: | 184 if self.toplevel_root: |
| 181 logging.info('Found .repo dir at %s' | 185 logging.info('Found .repo dir at %s' |
| 182 % os.path.dirname(self.toplevel_root)) | 186 % os.path.dirname(self.toplevel_root)) |
| 183 | 187 |
| 188 # Parse TRYSERVER_* settings from codereview.settings before falling back |
| 189 # on setting self.options.root manually further down. Otherwise |
| 190 # TRYSERVER_ROOT would never be used in codereview.settings. |
| 191 self._GclStyleSettings() |
| 192 |
| 184 if self.toplevel_root and not self.options.root: | 193 if self.toplevel_root and not self.options.root: |
| 185 assert os.path.abspath(self.toplevel_root) == self.toplevel_root | 194 assert os.path.abspath(self.toplevel_root) == self.toplevel_root |
| 186 self.options.root = gclient_utils.PathDifference(self.toplevel_root, | 195 self.options.root = gclient_utils.PathDifference(self.toplevel_root, |
| 187 self.checkout_root) | 196 self.checkout_root) |
| 197 else: |
| 198 self._GclStyleSettings() |
| 188 | 199 |
| 189 def ReadRootFile(self, filename): | 200 def ReadRootFile(self, filename): |
| 190 cur = self.checkout_root | 201 cur = self.checkout_root |
| 191 root = self.toplevel_root or self.checkout_root | 202 root = self.toplevel_root or self.checkout_root |
| 192 | 203 |
| 193 assert cur.startswith(root), (root, cur) | 204 assert cur.startswith(root), (root, cur) |
| 194 while cur.startswith(root): | 205 while cur.startswith(root): |
| 195 filepath = os.path.join(cur, filename) | 206 filepath = os.path.join(cur, filename) |
| 196 if os.path.isfile(filepath): | 207 if os.path.isfile(filepath): |
| 197 logging.info('Found %s at %s' % (filename, cur)) | 208 logging.info('Found %s at %s' % (filename, cur)) |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 return 1 | 884 return 1 |
| 874 except (gclient_utils.Error, subprocess2.CalledProcessError), e: | 885 except (gclient_utils.Error, subprocess2.CalledProcessError), e: |
| 875 print >> sys.stderr, e | 886 print >> sys.stderr, e |
| 876 return 1 | 887 return 1 |
| 877 return 0 | 888 return 0 |
| 878 | 889 |
| 879 | 890 |
| 880 if __name__ == "__main__": | 891 if __name__ == "__main__": |
| 881 fix_encoding.fix_encoding() | 892 fix_encoding.fix_encoding() |
| 882 sys.exit(TryChange(None, None, False)) | 893 sys.exit(TryChange(None, None, False)) |
| OLD | NEW |