Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(852)

Side by Side Diff: trychange.py

Issue 2016006: Makes trychange.py search harder for codereview.settings in a gclient checkout. (Closed)
Patch Set: Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/trychange_unittest.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2009 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 """Client-side script to send a try job to the try server. It communicates to 5 """Client-side script to send a try job to the try server. It communicates to
6 the try server by either writting to a svn repository or by directly connecting 6 the try server by either writting to a svn repository or by directly connecting
7 to the server by HTTP. 7 to the server by HTTP.
8 """ 8 """
9 9
10 import datetime 10 import datetime
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 self.codereview_settings = {} 110 self.codereview_settings = {}
111 settings_file = self.ReadRootFile(self.codereview_settings_file) 111 settings_file = self.ReadRootFile(self.codereview_settings_file)
112 if settings_file: 112 if settings_file:
113 for line in settings_file.splitlines(): 113 for line in settings_file.splitlines():
114 if not line or line.lstrip().startswith('#'): 114 if not line or line.lstrip().startswith('#'):
115 continue 115 continue
116 k, v = line.split(":", 1) 116 k, v = line.split(":", 1)
117 self.codereview_settings[k.strip()] = v.strip() 117 self.codereview_settings[k.strip()] = v.strip()
118 return self.codereview_settings.get(key, '') 118 return self.codereview_settings.get(key, '')
119 119
120 def GclStyleSettings(self): 120 def _GclStyleSettings(self):
121 """Set default settings based on the gcl-style settings from the 121 """Set default settings based on the gcl-style settings from the
122 repository.""" 122 repository."""
123 settings = { 123 settings = {
124 'port': self.GetCodeReviewSetting('TRYSERVER_HTTP_PORT'), 124 'port': self.GetCodeReviewSetting('TRYSERVER_HTTP_PORT'),
125 'host': self.GetCodeReviewSetting('TRYSERVER_HTTP_HOST'), 125 'host': self.GetCodeReviewSetting('TRYSERVER_HTTP_HOST'),
126 'svn_repo': self.GetCodeReviewSetting('TRYSERVER_SVN_URL'), 126 'svn_repo': self.GetCodeReviewSetting('TRYSERVER_SVN_URL'),
127 'project': self.GetCodeReviewSetting('TRYSERVER_PROJECT'), 127 'project': self.GetCodeReviewSetting('TRYSERVER_PROJECT'),
128 'root': self.GetCodeReviewSetting('TRYSERVER_ROOT'), 128 'root': self.GetCodeReviewSetting('TRYSERVER_ROOT'),
129 'patchlevel': self.GetCodeReviewSetting('TRYSERVER_PATCHLEVEL'), 129 'patchlevel': self.GetCodeReviewSetting('TRYSERVER_PATCHLEVEL'),
130 } 130 }
131 logging.info('\n'.join(['%s: %s' % (k, v)
132 for (k, v) in settings.iteritems() if v]))
131 for (k, v) in settings.iteritems(): 133 for (k, v) in settings.iteritems():
132 if v and getattr(self.options, k) is None: 134 if v and getattr(self.options, k) is None:
133 setattr(self.options, k, v) 135 setattr(self.options, k, v)
134 136
135 def GclientStyleSettings(self): 137 def _GclientStyleSettings(self):
136 """Find the root, assuming a gclient-style checkout.""" 138 """Find the root, assuming a gclient-style checkout."""
139 self.gclient_root = None
137 if not self.options.no_gclient and not self.options.root: 140 if not self.options.no_gclient and not self.options.root:
138 root = self.checkout_root 141 root = self.checkout_root
139 gclient_root = gclient_utils.FindGclientRoot(root) 142 self.gclient_root = gclient_utils.FindGclientRoot(root)
140 if gclient_root: 143 if self.gclient_root:
141 self.options.root = gclient_utils.PathDifference(gclient_root, root) 144 logging.info('Found .gclient at %s' % self.gclient_root)
145 self.options.root = gclient_utils.PathDifference(self.gclient_root,
146 root)
142 147
143 def AutomagicalSettings(self): 148 def AutomagicalSettings(self):
144 """Determines settings based on supported code review and checkout tools. 149 """Determines settings based on supported code review and checkout tools.
145 """ 150 """
146 self.GclStyleSettings() 151 self._GclientStyleSettings()
147 self.GclientStyleSettings() 152 self._GclStyleSettings()
148 153
149 def ReadRootFile(self, filename): 154 def ReadRootFile(self, filename):
150 raise NotImplementedError() 155 if not self.options.root:
156 filepath = os.path.join(self.checkout_root, filename)
157 if os.path.isfile(filepath):
158 logging.info('Found %s at %s' % (filename, self.checkout_root))
159 return gclient_util.FileRead(filepath)
160 return None
161 root = os.path.abspath(self.gclient_root)
162 cur = os.path.abspath(self.checkout_root)
163 assert cur.startswith(root), (root, cur)
164 while cur.startswith(root):
165 filepath = os.path.join(cur, filename)
166 if os.path.isfile(filepath):
167 logging.info('Found %s at %s' % (filename, cur))
168 return gclient_utils.FileRead(filepath)
169 cur = os.path.dirname(cur)
170 logging.warning('Didn\'t find %s' % filename)
171 return None
151 172
152 173
153 class SVN(SCM): 174 class SVN(SCM):
154 """Gathers the options and diff for a subversion checkout.""" 175 """Gathers the options and diff for a subversion checkout."""
155 def __init__(self, *args, **kwargs): 176 def __init__(self, *args, **kwargs):
156 SCM.__init__(self, *args, **kwargs) 177 SCM.__init__(self, *args, **kwargs)
157 self.checkout_root = scm.SVN.GetCheckoutRoot(self.checkout_root) 178 self.checkout_root = scm.SVN.GetCheckoutRoot(self.checkout_root)
158 if not self.options.email: 179 if not self.options.email:
159 # Assumes the svn credential is an email address. 180 # Assumes the svn credential is an email address.
160 self.options.email = scm.SVN.GetEmail(self.checkout_root) 181 self.options.email = scm.SVN.GetEmail(self.checkout_root)
161 logging.info("SVN(%s)" % self.checkout_root) 182 logging.info("SVN(%s)" % self.checkout_root)
162 183
163 def ReadRootFile(self, filename): 184 def ReadRootFile(self, filename):
185 data = SCM.ReadRootFile(self, filename)
186 if data:
187 return data
188
189 # Try to search on the subversion repository for the file.
164 try: 190 try:
165 # Try to search on the subversion repository for the file. 191 from gcl import GetCachedFile
166 import gcl
167 data = gcl.GetCachedFile(filename)
168 logging.debug('%s:\n%s' % (filename, data))
169 return data
170 except ImportError: 192 except ImportError:
171 try: 193 return None
172 data = gclient_utils.FileRead(os.path.join(self.checkout_root, 194 data = GetCachedFile(filename)
173 filename)) 195 logging.debug('%s:\n%s' % (filename, data))
174 logging.debug('%s:\n%s' % (filename, data)) 196 return data
175 return data
176 except (IOError, OSError):
177 logging.debug('%s:\nNone' % filename)
178 return None
179 197
180 def GenerateDiff(self): 198 def GenerateDiff(self):
181 """Returns a string containing the diff for the given file list. 199 """Returns a string containing the diff for the given file list.
182 200
183 The files in the list should either be absolute paths or relative to the 201 The files in the list should either be absolute paths or relative to the
184 given root. 202 given root.
185 """ 203 """
186 if not self.files: 204 if not self.files:
187 previous_cwd = os.getcwd() 205 previous_cwd = os.getcwd()
188 os.chdir(self.checkout_root) 206 os.chdir(self.checkout_root)
(...skipping 26 matching lines...) Expand all
215 self.options.email = scm.GIT.GetEmail(self.checkout_root) 233 self.options.email = scm.GIT.GetEmail(self.checkout_root)
216 if not self.diff_against: 234 if not self.diff_against:
217 self.diff_against = scm.GIT.GetUpstreamBranch(self.checkout_root) 235 self.diff_against = scm.GIT.GetUpstreamBranch(self.checkout_root)
218 if not self.diff_against: 236 if not self.diff_against:
219 raise NoTryServerAccess( 237 raise NoTryServerAccess(
220 "Unable to determine default branch to diff against. " 238 "Unable to determine default branch to diff against. "
221 "Verify this branch is set up to track another" 239 "Verify this branch is set up to track another"
222 "(via the --track argument to \"git checkout -b ...\"") 240 "(via the --track argument to \"git checkout -b ...\"")
223 logging.info("GIT(%s)" % self.checkout_root) 241 logging.info("GIT(%s)" % self.checkout_root)
224 242
225 def ReadRootFile(self, filename):
226 try:
227 # A git checkout is always a full checkout.
228 data = gclient_utils.FileRead(os.path.join(self.checkout_root, filename))
229 logging.debug('%s:\n%s' % (filename, data))
230 return data
231 except (IOError, OSError):
232 logging.debug('%s:\nNone' % filename)
233 return None
234
235 def GenerateDiff(self): 243 def GenerateDiff(self):
236 if not self.files: 244 if not self.files:
237 self.files = scm.GIT.GetDifferentFiles(self.checkout_root, 245 self.files = scm.GIT.GetDifferentFiles(self.checkout_root,
238 branch=self.diff_against) 246 branch=self.diff_against)
239 247
240 def NotExcluded(f): 248 def NotExcluded(f):
241 for r in self.options.exclude: 249 for r in self.options.exclude:
242 if re.search(r, f): 250 if re.search(r, f):
243 logging.info('Ignoring "%s"' % f) 251 logging.info('Ignoring "%s"' % f)
244 return False 252 return False
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 help="SVN url to use to write the changes in; --use_svn is " 584 help="SVN url to use to write the changes in; --use_svn is "
577 "implied when using --svn_repo") 585 "implied when using --svn_repo")
578 parser.add_option_group(group) 586 parser.add_option_group(group)
579 587
580 options, args = parser.parse_args(argv) 588 options, args = parser.parse_args(argv)
581 if len(args) == 1 and args[0] == 'help': 589 if len(args) == 1 and args[0] == 'help':
582 parser.print_help() 590 parser.print_help()
583 591
584 if not swallow_exception: 592 if not swallow_exception:
585 if options.verbose == 0: 593 if options.verbose == 0:
586 logging.basicConfig(level=logging.ERROR) 594 logging.basicConfig(level=logging.WARNING)
587 elif options.verbose == 1: 595 elif options.verbose == 1:
588 logging.basicConfig(level=logging.WARNING)
589 elif options.verbose == 2:
590 logging.basicConfig(level=logging.INFO) 596 logging.basicConfig(level=logging.INFO)
591 elif options.verbose > 2: 597 elif options.verbose > 1:
592 logging.basicConfig(level=logging.DEBUG) 598 logging.basicConfig(level=logging.DEBUG)
593 599
594 logging.debug(argv) 600 logging.debug(argv)
595 601
596 if options.rietveld_url: 602 if options.rietveld_url:
597 # Try to extract the review number if possible and fix the protocol. 603 # Try to extract the review number if possible and fix the protocol.
598 if not '://' in options.rietveld_url: 604 if not '://' in options.rietveld_url:
599 options.rietveld_url = 'http://' + options.rietveld_url 605 options.rietveld_url = 'http://' + options.rietveld_url
600 match = re.match(r'^(.*)/(\d+)$', options.rietveld_url) 606 match = re.match(r'^(.*)/(\d+)$', options.rietveld_url)
601 if match: 607 if match:
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 except (InvalidScript, NoTryServerAccess), e: 718 except (InvalidScript, NoTryServerAccess), e:
713 if swallow_exception: 719 if swallow_exception:
714 return 1 720 return 1
715 print e 721 print e
716 return 1 722 return 1
717 return 0 723 return 0
718 724
719 725
720 if __name__ == "__main__": 726 if __name__ == "__main__":
721 sys.exit(TryChange(None, [], False)) 727 sys.exit(TryChange(None, [], False))
OLDNEW
« no previous file with comments | « tests/trychange_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698