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

Side by Side Diff: gclient_utils.py

Issue 502078: Remove trychange.RunCommand and replace it by gclient_utils.CheckCall. (Closed)
Patch Set: Created 11 years 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 | « no previous file | tests/gclient_utils_test.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 # Copyright 2009 Google Inc. All Rights Reserved. 1 # Copyright 2009 Google Inc. All Rights Reserved.
2 # 2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
6 # 6 #
7 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
8 # 8 #
9 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and 12 # See the License for the specific language governing permissions and
13 # limitations under the License. 13 # limitations under the License.
14 14
15 """Generic utils.""" 15 """Generic utils."""
16 16
17 import errno 17 import errno
18 import os 18 import os
19 import re 19 import re
20 import stat 20 import stat
21 import subprocess 21 import subprocess
22 import sys 22 import sys
23 import time 23 import time
24 import xml.dom.minidom 24 import xml.dom.minidom
25 import xml.parsers.expat 25 import xml.parsers.expat
26 26
27 27
28 class CheckCallError(OSError):
29 """CheckCall() returned non-0."""
30 def __init__(self, command, cwd, retcode, stdout):
31 OSError.__init__(self, command, cwd, retcode, stdout)
32 self.command = command
33 self.cwd = cwd
34 self.retcode = retcode
35 self.stdout = stdout
36
37
38 def CheckCall(command, cwd=None):
39 """Like subprocess.check_call() but returns stdout.
40
41 Works on python 2.4
42 """
43 process = subprocess.Popen(command, cwd=cwd,
44 shell=sys.platform.startswith('win'),
45 stdout=subprocess.PIPE)
46 output = process.communicate()[0]
47 if process.retcode:
48 raise CheckCallError(command, cwd, process.retcode, output)
49 return output
50
51
28 def SplitUrlRevision(url): 52 def SplitUrlRevision(url):
29 """Splits url and returns a two-tuple: url, rev""" 53 """Splits url and returns a two-tuple: url, rev"""
30 if url.startswith('ssh:'): 54 if url.startswith('ssh:'):
31 # Make sure ssh://test@example.com/test.git@stable works 55 # Make sure ssh://test@example.com/test.git@stable works
32 regex = r"(ssh://(?:[\w]+@)?[-\w:\.]+/[-\w\./]+)(?:@(.+))?" 56 regex = r"(ssh://(?:[\w]+@)?[-\w:\.]+/[-\w\./]+)(?:@(.+))?"
33 components = re.search(regex, url).groups() 57 components = re.search(regex, url).groups()
34 else: 58 else:
35 components = url.split("@") 59 components = url.split("@")
36 if len(components) == 1: 60 if len(components) == 1:
37 components += [None] 61 components += [None]
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 raise Error(msg) 293 raise Error(msg)
270 294
271 295
272 def IsUsingGit(root, paths): 296 def IsUsingGit(root, paths):
273 """Returns True if we're using git to manage any of our checkouts. 297 """Returns True if we're using git to manage any of our checkouts.
274 |entries| is a list of paths to check.""" 298 |entries| is a list of paths to check."""
275 for path in paths: 299 for path in paths:
276 if os.path.exists(os.path.join(root, path, '.git')): 300 if os.path.exists(os.path.join(root, path, '.git')):
277 return True 301 return True
278 return False 302 return False
OLDNEW
« no previous file with comments | « no previous file | tests/gclient_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698