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

Side by Side Diff: gclient_utils.py

Issue 551215: Change CheckCall behavior when print_error=False (Closed)
Patch Set: Created 10 years, 10 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 | « no previous file | scm.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,
(...skipping 10 matching lines...) Expand all
21 import stat 21 import stat
22 import subprocess 22 import subprocess
23 import sys 23 import sys
24 import time 24 import time
25 import xml.dom.minidom 25 import xml.dom.minidom
26 import xml.parsers.expat 26 import xml.parsers.expat
27 27
28 28
29 class CheckCallError(OSError): 29 class CheckCallError(OSError):
30 """CheckCall() returned non-0.""" 30 """CheckCall() returned non-0."""
31 def __init__(self, command, cwd, retcode, stdout): 31 def __init__(self, command, cwd, retcode, stdout, stderr=None):
32 OSError.__init__(self, command, cwd, retcode, stdout) 32 OSError.__init__(self, command, cwd, retcode, stdout, stderr)
33 self.command = command 33 self.command = command
34 self.cwd = cwd 34 self.cwd = cwd
35 self.retcode = retcode 35 self.retcode = retcode
36 self.stdout = stdout 36 self.stdout = stdout
37 self.stderr = stderr
37 38
38 39
39 def CheckCall(command, cwd=None, print_error=True): 40 def CheckCall(command, cwd=None, print_error=True):
40 """Like subprocess.check_call() but returns stdout. 41 """Like subprocess.check_call() but returns stdout.
41 42
42 Works on python 2.4 43 Works on python 2.4
43 """ 44 """
44 logging.debug("%s, cwd=%s" % (str(command), str(cwd))) 45 logging.debug("%s, cwd=%s" % (str(command), str(cwd)))
45 try: 46 try:
46 stderr = None 47 stderr = None
47 if not print_error: 48 if not print_error:
48 stderr = subprocess.PIPE 49 stderr = subprocess.PIPE
49 process = subprocess.Popen(command, cwd=cwd, 50 process = subprocess.Popen(command, cwd=cwd,
50 shell=sys.platform.startswith('win'), 51 shell=sys.platform.startswith('win'),
51 stdout=subprocess.PIPE, 52 stdout=subprocess.PIPE,
52 stderr=stderr) 53 stderr=stderr)
53 output = process.communicate()[0] 54 std_out,std_err = process.communicate()
M-A Ruel 2010/01/30 03:09:21 std_out, std_err
Nasser Grainawi 2010/01/30 04:49:26 Done.
54 except OSError, e: 55 except OSError, e:
55 raise CheckCallError(command, cwd, e.errno, None) 56 raise CheckCallError(command, cwd, e.errno, None)
56 if process.returncode: 57 if process.returncode:
57 raise CheckCallError(command, cwd, process.returncode, output) 58 raise CheckCallError(command, cwd, process.returncode, std_out, std_err)
58 return output 59 return std_out,std_err
M-A Ruel 2010/01/30 03:09:21 idem
Nasser Grainawi 2010/01/30 04:49:26 Done.
59 60
60 61
61 def SplitUrlRevision(url): 62 def SplitUrlRevision(url):
62 """Splits url and returns a two-tuple: url, rev""" 63 """Splits url and returns a two-tuple: url, rev"""
63 if url.startswith('ssh:'): 64 if url.startswith('ssh:'):
64 # Make sure ssh://test@example.com/test.git@stable works 65 # Make sure ssh://test@example.com/test.git@stable works
65 regex = r"(ssh://(?:[\w]+@)?[-\w:\.]+/[-\w\./]+)(?:@(.+))?" 66 regex = r"(ssh://(?:[\w]+@)?[-\w:\.]+/[-\w\./]+)(?:@(.+))?"
66 components = re.search(regex, url).groups() 67 components = re.search(regex, url).groups()
67 else: 68 else:
68 components = url.split("@") 69 components = url.split("@")
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 """Returns the difference subpath minus root.""" 316 """Returns the difference subpath minus root."""
316 root = os.path.realpath(root) 317 root = os.path.realpath(root)
317 subpath = os.path.realpath(subpath) 318 subpath = os.path.realpath(subpath)
318 if not subpath.startswith(root): 319 if not subpath.startswith(root):
319 return None 320 return None
320 # If the root does not have a trailing \ or /, we add it so the returned 321 # If the root does not have a trailing \ or /, we add it so the returned
321 # path starts immediately after the seperator regardless of whether it is 322 # path starts immediately after the seperator regardless of whether it is
322 # provided. 323 # provided.
323 root = os.path.join(root, '') 324 root = os.path.join(root, '')
324 return subpath[len(root):] 325 return subpath[len(root):]
OLDNEW
« no previous file with comments | « no previous file | scm.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698