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

Side by Side Diff: native_client_sdk/src/tools/oshelpers.py

Issue 12220085: [NaCl SDK] Print nice error if host build can't find gcc or cl.exe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 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 | Annotate | Revision Log
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 import fnmatch 6 import fnmatch
7 import glob 7 import glob
8 import optparse 8 import optparse
9 import os 9 import os
10 import posixpath 10 import posixpath
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 print ' %s: %s (stored 0%%)' % (operation, zip_path) 462 print ' %s: %s (stored 0%%)' % (operation, zip_path)
463 elif zip_info.compress_type == zipfile.ZIP_DEFLATED: 463 elif zip_info.compress_type == zipfile.ZIP_DEFLATED:
464 print ' %s: %s (deflated %d%%)' % (operation, zip_path, 464 print ' %s: %s (deflated %d%%)' % (operation, zip_path,
465 100 - zip_info.compress_size * 100 / zip_info.file_size) 465 100 - zip_info.compress_size * 100 / zip_info.file_size)
466 finally: 466 finally:
467 zip_stream.close() 467 zip_stream.close()
468 468
469 return 0 469 return 0
470 470
471 471
472 def Which(args):
473 """A Unix style which.
474
475 Looks for all arguments in the PATH environment variable, and prints their
476 path if they are executable files.
477
478 Note: If you pass an argument with a path to which, it will just test if it
479 is executable, not if it is in the path.
480 """
481 parser = optparse.OptionParser(usage='usage: which args...')
482 _, files = parser.parse_args(args)
483 if not files:
484 return 0
485
486 env_path = os.environ.get('PATH', '')
487 paths = env_path.split(os.pathsep)
488
489 def IsExecutableFile(path):
490 return os.path.isfile(path) and os.access(path, os.X_OK)
491
492 retval = 0
493 for filename in files:
494 if os.path.sep in filename:
495 if IsExecutableFile(filename):
496 print filename
497 continue
498
499 for path in paths:
500 filepath = os.path.join(path, filename)
501 if IsExecutableFile(filepath):
502 print os.path.abspath(os.path.join(path, filename))
503 break
504 else:
505 retval = 1
506 return retval
507
508
472 FuncMap = { 509 FuncMap = {
473 'cp': Copy, 510 'cp': Copy,
474 'mkdir': Mkdir, 511 'mkdir': Mkdir,
475 'mv': Move, 512 'mv': Move,
476 'rm': Remove, 513 'rm': Remove,
477 'zip': Zip, 514 'zip': Zip,
515 'which': Which,
478 } 516 }
479 517
480 518
481 def main(args): 519 def main(args):
482 if not args: 520 if not args:
483 print 'No command specified' 521 print 'No command specified'
484 print 'Available commands: %s' % ' '.join(FuncMap) 522 print 'Available commands: %s' % ' '.join(FuncMap)
485 return 1 523 return 1
486 func = FuncMap.get(args[0]) 524 func = FuncMap.get(args[0])
487 if not func: 525 if not func:
488 print 'Do not recognize command: ' + args[0] 526 print 'Do not recognize command: ' + args[0]
489 print 'Available commands: %s' % ' '.join(FuncMap) 527 print 'Available commands: %s' % ' '.join(FuncMap)
490 return 1 528 return 1
491 return func(args[1:]) 529 return func(args[1:])
492 530
493 if __name__ == '__main__': 531 if __name__ == '__main__':
494 sys.exit(main(sys.argv[1:])) 532 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « native_client_sdk/src/tools/host_vc.mk ('k') | native_client_sdk/src/tools/tests/oshelpers_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698