| OLD | NEW |
| 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 # Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 # for details. All rights reserved. Use of this source code is governed by a | 2 # for details. All rights reserved. Use of this source code is governed by a |
| 3 # BSD-style license that can be found in the LICENSE file. | 3 # BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 # This file contains a set of utilities functions used by other Python-based | 5 # This file contains a set of utilities functions used by other Python-based |
| 6 # scripts. | 6 # scripts. |
| 7 | 7 |
| 8 import commands | 8 import commands |
| 9 import os | 9 import os |
| 10 import platform | 10 import platform |
| 11 import re | 11 import re |
| 12 import shutil |
| 12 import subprocess | 13 import subprocess |
| 13 import sys | 14 import sys |
| 15 import tempfile |
| 14 | 16 |
| 15 | 17 |
| 16 # Try to guess the host operating system. | 18 # Try to guess the host operating system. |
| 17 def GuessOS(): | 19 def GuessOS(): |
| 18 id = platform.system() | 20 id = platform.system() |
| 19 if id == "Linux": | 21 if id == "Linux": |
| 20 return "linux" | 22 return "linux" |
| 21 elif id == "Darwin": | 23 elif id == "Darwin": |
| 22 return "macos" | 24 return "macos" |
| 23 elif id == "Windows" or id == "Microsoft": | 25 elif id == "Windows" or id == "Microsoft": |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 return os.path.join(dart_binary_prefix, 'windows', 'dart.exe') | 401 return os.path.join(dart_binary_prefix, 'windows', 'dart.exe') |
| 400 else: | 402 else: |
| 401 return os.path.join(dart_binary_prefix, GuessOS(), 'dart') | 403 return os.path.join(dart_binary_prefix, GuessOS(), 'dart') |
| 402 | 404 |
| 403 | 405 |
| 404 def DartSdkBinary(): | 406 def DartSdkBinary(): |
| 405 tools_dir = os.path.dirname(os.path.realpath(__file__)) | 407 tools_dir = os.path.dirname(os.path.realpath(__file__)) |
| 406 dart_binary_prefix = os.path.join(tools_dir, '..', 'sdk' , 'bin') | 408 dart_binary_prefix = os.path.join(tools_dir, '..', 'sdk' , 'bin') |
| 407 return os.path.join(dart_binary_prefix, 'dart') | 409 return os.path.join(dart_binary_prefix, 'dart') |
| 408 | 410 |
| 411 class TempDir(object): |
| 412 def __init__(self, prefix=''): |
| 413 self._temp_dir = None |
| 414 self._prefix = prefix |
| 415 |
| 416 def __enter__(self): |
| 417 self._temp_dir = tempfile.mkdtemp(self._prefix) |
| 418 return self._temp_dir |
| 419 |
| 420 def __exit__(self, *_): |
| 421 shutil.rmtree(self._temp_dir, ignore_errors=True) |
| 422 |
| 409 | 423 |
| 410 if __name__ == "__main__": | 424 if __name__ == "__main__": |
| 411 import sys | 425 import sys |
| 412 Main(sys.argv) | 426 Main(sys.argv) |
| OLD | NEW |