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

Side by Side Diff: tools/isolate/run_test_from_archive.py

Issue 10449089: Copy fix_python_path() in more standalone files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 | « testing/test_env.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/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 """Reads a manifest, creates a tree of hardlinks and runs the test. 6 """Reads a manifest, creates a tree of hardlinks and runs the test.
7 7
8 Keeps a local cache. 8 Keeps a local cache.
9 """ 9 """
10 10
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 """Returns the number of free bytes.""" 129 """Returns the number of free bytes."""
130 if sys.platform == 'win32': 130 if sys.platform == 'win32':
131 free_bytes = ctypes.c_ulonglong(0) 131 free_bytes = ctypes.c_ulonglong(0)
132 ctypes.windll.kernel32.GetDiskFreeSpaceExW( 132 ctypes.windll.kernel32.GetDiskFreeSpaceExW(
133 ctypes.c_wchar_p(path), None, None, ctypes.pointer(free_bytes)) 133 ctypes.c_wchar_p(path), None, None, ctypes.pointer(free_bytes))
134 return free_bytes.value 134 return free_bytes.value
135 f = os.statvfs(path) 135 f = os.statvfs(path)
136 return f.f_bfree * f.f_frsize 136 return f.f_bfree * f.f_frsize
137 137
138 138
139 def fix_python_path(cmd):
140 """Returns the fixed command line to call the right python executable."""
141 out = cmd[:]
142 if out[0] == 'python':
143 out[0] = sys.executable
144 elif out[0].endswith('.py'):
145 out.insert(0, sys.executable)
146 return out
147
148
139 class Cache(object): 149 class Cache(object):
140 """Stateful LRU cache. 150 """Stateful LRU cache.
141 151
142 Saves its state as json file. 152 Saves its state as json file.
143 """ 153 """
144 STATE_FILE = 'state.json' 154 STATE_FILE = 'state.json'
145 155
146 def __init__(self, cache_dir, remote, max_cache_size, min_free_space): 156 def __init__(self, cache_dir, remote, max_cache_size, min_free_space):
147 """ 157 """
148 Arguments: 158 Arguments:
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 os.chmod(outfile, properties['mode']) 270 os.chmod(outfile, properties['mode'])
261 271
262 cwd = os.path.join(outdir, manifest['relative_cwd']) 272 cwd = os.path.join(outdir, manifest['relative_cwd'])
263 if not os.path.isdir(cwd): 273 if not os.path.isdir(cwd):
264 os.makedirs(cwd) 274 os.makedirs(cwd)
265 if manifest.get('read_only'): 275 if manifest.get('read_only'):
266 make_writable(outdir, True) 276 make_writable(outdir, True)
267 cmd = manifest['command'] 277 cmd = manifest['command']
268 # Ensure paths are correctly separated on windows. 278 # Ensure paths are correctly separated on windows.
269 cmd[0] = cmd[0].replace('/', os.path.sep) 279 cmd[0] = cmd[0].replace('/', os.path.sep)
280 cmd = fix_python_path(cmd)
270 logging.info('Running %s, cwd=%s' % (cmd, cwd)) 281 logging.info('Running %s, cwd=%s' % (cmd, cwd))
271 try: 282 try:
272 return subprocess.call(cmd, cwd=cwd) 283 return subprocess.call(cmd, cwd=cwd)
273 except OSError: 284 except OSError:
274 print >> sys.stderr, 'Failed to run %s; cwd=%s' % (cmd, cwd) 285 print >> sys.stderr, 'Failed to run %s; cwd=%s' % (cmd, cwd)
275 raise 286 raise
276 finally: 287 finally:
277 # Save first, in case an exception occur in the following lines, then clean 288 # Save first, in case an exception occur in the following lines, then clean
278 # up. 289 # up.
279 cache.save() 290 cache.save()
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 parser.error('Unsupported args %s' % ' '.join(args)) 337 parser.error('Unsupported args %s' % ' '.join(args))
327 338
328 manifest = json.load(open_remote(options.manifest)) 339 manifest = json.load(open_remote(options.manifest))
329 return run_tha_test( 340 return run_tha_test(
330 manifest, os.path.abspath(options.cache), options.remote, 341 manifest, os.path.abspath(options.cache), options.remote,
331 options.max_cache_size, options.min_free_space) 342 options.max_cache_size, options.min_free_space)
332 343
333 344
334 if __name__ == '__main__': 345 if __name__ == '__main__':
335 sys.exit(main()) 346 sys.exit(main())
OLDNEW
« no previous file with comments | « testing/test_env.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698