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

Side by Side Diff: presubmit.py

Issue 113290: Deprecate gcl.GetSVNFileInfo() for gclient.CaptureSVNInfo(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: fixed presubmit.py and updated unit tests Created 11 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 | Annotate | Revision Log
« no previous file with comments | « gcl.py ('k') | tests/gcl_unittest.py » ('j') | 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) 2006-2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-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 5
6 """Enables directory-specific presubmit checks to run at upload and/or commit. 6 """Enables directory-specific presubmit checks to run at upload and/or commit.
7 """ 7 """
8 8
9 __version__ = '1.0.1' 9 __version__ = '1.0.1'
10 10
(...skipping 14 matching lines...) Expand all
25 import subprocess # Exposed through the API. 25 import subprocess # Exposed through the API.
26 import sys # Parts exposed through API. 26 import sys # Parts exposed through API.
27 import tempfile # Exposed through the API. 27 import tempfile # Exposed through the API.
28 import types 28 import types
29 import urllib2 # Exposed through the API. 29 import urllib2 # Exposed through the API.
30 30
31 # Local imports. 31 # Local imports.
32 # TODO(joi) Would be cleaner to factor out utils in gcl to separate module, but 32 # TODO(joi) Would be cleaner to factor out utils in gcl to separate module, but
33 # for now it would only be a couple of functions so hardly worth it. 33 # for now it would only be a couple of functions so hardly worth it.
34 import gcl 34 import gcl
35 import gclient
35 import presubmit_canned_checks 36 import presubmit_canned_checks
36 37
37 38
38 # Matches key/value (or "tag") lines in changelist descriptions. 39 # Matches key/value (or "tag") lines in changelist descriptions.
39 _tag_line_re = re.compile( 40 _tag_line_re = re.compile(
40 '^\s*(?P<key>[A-Z][A-Z_0-9]*)\s*=\s*(?P<value>.*?)\s*$') 41 '^\s*(?P<key>[A-Z][A-Z_0-9]*)\s*=\s*(?P<value>.*?)\s*$')
41 42
42 43
43 # Friendly names may be used for certain keys. All values for key-value pairs 44 # Friendly names may be used for certain keys. All values for key-value pairs
44 # in change descriptions (like BUG=123) can be retrieved from a change object 45 # in change descriptions (like BUG=123) can be retrieved from a change object
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 201
201 Args: 202 Args:
202 Depot path as a string. 203 Depot path as a string.
203 204
204 Returns: 205 Returns:
205 The local path of the depot path under the user's current client, or None 206 The local path of the depot path under the user's current client, or None
206 if the file is not mapped. 207 if the file is not mapped.
207 208
208 Remember to check for the None case and show an appropriate error! 209 Remember to check for the None case and show an appropriate error!
209 """ 210 """
210 local_path = gcl.GetSVNFileInfo(depot_path).get('Path') 211 local_path = gclient.CaptureSVNInfo(depot_path).get('Path')
211 if not local_path: 212 if not local_path:
212 return None 213 return None
213 else: 214 else:
214 return local_path 215 return local_path
215 216
216 @staticmethod 217 @staticmethod
217 def LocalToDepotPath(local_path): 218 def LocalToDepotPath(local_path):
218 """Translate a local path to a depot path. 219 """Translate a local path to a depot path.
219 220
220 Args: 221 Args:
221 Local path (relative to current directory, or absolute) as a string. 222 Local path (relative to current directory, or absolute) as a string.
222 223
223 Returns: 224 Returns:
224 The depot path (SVN URL) of the file if mapped, otherwise None. 225 The depot path (SVN URL) of the file if mapped, otherwise None.
225 """ 226 """
226 depot_path = gcl.GetSVNFileInfo(local_path).get('URL') 227 depot_path = gclient.CaptureSVNInfo(local_path).get('URL')
227 if not depot_path: 228 if not depot_path:
228 return None 229 return None
229 else: 230 else:
230 return depot_path 231 return depot_path
231 232
232 @staticmethod 233 @staticmethod
233 def FilterTextFiles(affected_files, include_deletes=True): 234 def FilterTextFiles(affected_files, include_deletes=True):
234 """Filters out all except text files and optionally also filters out 235 """Filters out all except text files and optionally also filters out
235 deleted files. 236 deleted files.
236 237
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 def __init__(self, path, action, repository_root=''): 325 def __init__(self, path, action, repository_root=''):
325 self.path = path 326 self.path = path
326 self.action = action.strip() 327 self.action = action.strip()
327 self.repository_root = repository_root 328 self.repository_root = repository_root
328 329
329 def ServerPath(self): 330 def ServerPath(self):
330 """Returns a path string that identifies the file in the SCM system. 331 """Returns a path string that identifies the file in the SCM system.
331 332
332 Returns the empty string if the file does not exist in SCM. 333 Returns the empty string if the file does not exist in SCM.
333 """ 334 """
334 return gcl.GetSVNFileInfo(self.AbsoluteLocalPath()).get('URL', '') 335 return gclient.CaptureSVNInfo(self.AbsoluteLocalPath()).get('URL', '')
335 336
336 def LocalPath(self): 337 def LocalPath(self):
337 """Returns the path of this file on the local disk relative to client root. 338 """Returns the path of this file on the local disk relative to client root.
338 """ 339 """
339 return normpath(self.path) 340 return normpath(self.path)
340 341
341 def AbsoluteLocalPath(self): 342 def AbsoluteLocalPath(self):
342 """Returns the absolute path of this file on the local disk. 343 """Returns the absolute path of this file on the local disk.
343 """ 344 """
344 return normpath(os.path.join(self.repository_root, self.LocalPath())) 345 return normpath(os.path.join(self.repository_root, self.LocalPath()))
345 346
346 def IsDirectory(self): 347 def IsDirectory(self):
347 """Returns true if this object is a directory.""" 348 """Returns true if this object is a directory."""
348 if os.path.exists(self.path): 349 if os.path.exists(self.path):
349 # Retrieve directly from the file system; it is much faster than querying 350 # Retrieve directly from the file system; it is much faster than querying
350 # subversion, especially on Windows. 351 # subversion, especially on Windows.
351 return os.path.isdir(self.path) 352 return os.path.isdir(self.path)
352 else: 353 else:
353 return gcl.GetSVNFileInfo(self.path).get('Node Kind') == 'directory' 354 return gclient.CaptureSVNInfo(self.path).get('Node Kind') in ('dir',
355 'directory')
354 356
355 def SvnProperty(self, property_name): 357 def SvnProperty(self, property_name):
356 """Returns the specified SVN property of this file, or the empty string 358 """Returns the specified SVN property of this file, or the empty string
357 if no such property. 359 if no such property.
358 """ 360 """
359 return gcl.GetSVNFileProperty(self.AbsoluteLocalPath(), property_name) 361 return gcl.GetSVNFileProperty(self.AbsoluteLocalPath(), property_name)
360 362
361 def Action(self): 363 def Action(self):
362 """Returns the action on this opened file, e.g. A, M, D, etc.""" 364 """Returns the action on this opened file, e.g. A, M, D, etc."""
363 return self.action 365 return self.action
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 print "Found %d files." % len(files) 702 print "Found %d files." % len(files)
701 return DoPresubmitChecks(gcl.ChangeInfo(name='temp', files=files), 703 return DoPresubmitChecks(gcl.ChangeInfo(name='temp', files=files),
702 options.commit, 704 options.commit,
703 options.verbose, 705 options.verbose,
704 sys.stdout, 706 sys.stdout,
705 sys.stdin) 707 sys.stdin)
706 708
707 709
708 if __name__ == '__main__': 710 if __name__ == '__main__':
709 sys.exit(Main(sys.argv)) 711 sys.exit(Main(sys.argv))
OLDNEW
« no previous file with comments | « gcl.py ('k') | tests/gcl_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698