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

Side by Side Diff: gclient_utils.py

Issue 18851005: Print time of long running hook actions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Pretty print command, escape for shells. Created 7 years, 5 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 | « gclient.py ('k') | 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 (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generic utils.""" 5 """Generic utils."""
6 6
7 import codecs 7 import codecs
8 import logging 8 import logging
9 import os 9 import os
10 import pipes
10 import Queue 11 import Queue
11 import re 12 import re
12 import stat 13 import stat
13 import subprocess 14 import subprocess
14 import sys 15 import sys
15 import tempfile 16 import tempfile
16 import threading 17 import threading
17 import time 18 import time
18 import urlparse 19 import urlparse
19 20
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 os.makedirs(tree) 176 os.makedirs(tree)
176 except OSError, e: 177 except OSError, e:
177 # 17 POSIX, 183 Windows 178 # 17 POSIX, 183 Windows
178 if e.errno not in (17, 183): 179 if e.errno not in (17, 183):
179 raise 180 raise
180 if count > 40: 181 if count > 40:
181 # Give up. 182 # Give up.
182 raise 183 raise
183 184
184 185
186 def CommandToStr(args):
187 """Converts an arg list into a shell escaped string."""
188 return ' '.join(pipes.quote(arg) for arg in args)
189
190
185 def CheckCallAndFilterAndHeader(args, always=False, header=None, **kwargs): 191 def CheckCallAndFilterAndHeader(args, always=False, header=None, **kwargs):
186 """Adds 'header' support to CheckCallAndFilter. 192 """Adds 'header' support to CheckCallAndFilter.
187 193
188 If |always| is True, a message indicating what is being done 194 If |always| is True, a message indicating what is being done
189 is printed to stdout all the time even if not output is generated. Otherwise 195 is printed to stdout all the time even if not output is generated. Otherwise
190 the message header is printed only if the call generated any ouput. 196 the message header is printed only if the call generated any ouput.
191 """ 197 """
192 stdout = kwargs.setdefault('stdout', sys.stdout) 198 stdout = kwargs.setdefault('stdout', sys.stdout)
193 if header is None: 199 if header is None:
194 header = "\n________ running '%s' in '%s'\n" % ( 200 header = "\n________ running '%s' in '%s'\n" % (
195 ' '.join(args), kwargs.get('cwd', '.')) 201 CommandToStr(args), kwargs.get('cwd', '.'))
196 202
197 if always: 203 if always:
198 stdout.write(header) 204 stdout.write(header)
199 else: 205 else:
200 filter_fn = kwargs.get('filter_fn') 206 filter_fn = kwargs.get('filter_fn')
201 def filter_msg(line): 207 def filter_msg(line):
202 if line is None: 208 if line is None:
203 stdout.write(header) 209 stdout.write(header)
204 elif filter_fn: 210 elif filter_fn:
205 filter_fn(line) 211 filter_fn(line)
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 877
872 Python on OSX 10.6 raises a NotImplementedError exception. 878 Python on OSX 10.6 raises a NotImplementedError exception.
873 """ 879 """
874 try: 880 try:
875 import multiprocessing 881 import multiprocessing
876 return multiprocessing.cpu_count() 882 return multiprocessing.cpu_count()
877 except: # pylint: disable=W0702 883 except: # pylint: disable=W0702
878 # Mac OS 10.6 only 884 # Mac OS 10.6 only
879 # pylint: disable=E1101 885 # pylint: disable=E1101
880 return int(os.sysconf('SC_NPROCESSORS_ONLN')) 886 return int(os.sysconf('SC_NPROCESSORS_ONLN'))
OLDNEW
« no previous file with comments | « gclient.py ('k') | tests/gclient_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698