Chromium Code Reviews| 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 datetime | 9 import datetime |
| 10 import json | 10 import json |
| 11 import os | 11 import os |
| 12 import platform | 12 import platform |
| 13 import re | 13 import re |
| 14 import shutil | 14 import shutil |
| 15 import subprocess | 15 import subprocess |
| 16 import tempfile | 16 import tempfile |
| 17 import sys | 17 import sys |
| 18 | 18 |
| 19 SCRIPT_DIR = os.path.dirname(sys.argv[0]) | |
|
ricow1
2015/09/14 05:46:41
we don't normally do this, see comment in function
Cutch
2015/09/14 14:05:43
Done.
| |
| 20 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) | |
| 21 | |
| 19 class Version(object): | 22 class Version(object): |
| 20 def __init__(self, channel, major, minor, patch, prerelease, | 23 def __init__(self, channel, major, minor, patch, prerelease, |
| 21 prerelease_patch): | 24 prerelease_patch): |
| 22 self.channel = channel | 25 self.channel = channel |
| 23 self.major = major | 26 self.major = major |
| 24 self.minor = minor | 27 self.minor = minor |
| 25 self.patch = patch | 28 self.patch = patch |
| 26 self.prerelease = prerelease | 29 self.prerelease = prerelease |
| 27 self.prerelease_patch = prerelease_patch | 30 self.prerelease_patch = prerelease_patch |
| 28 | 31 |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 584 return os.path.join(dart_binary_prefix, system, 'dart-mips') | 587 return os.path.join(dart_binary_prefix, system, 'dart-mips') |
| 585 else: | 588 else: |
| 586 return os.path.join(dart_binary_prefix, system, 'dart') | 589 return os.path.join(dart_binary_prefix, system, 'dart') |
| 587 | 590 |
| 588 | 591 |
| 589 def DartSdkBinary(): | 592 def DartSdkBinary(): |
| 590 tools_dir = os.path.dirname(os.path.realpath(__file__)) | 593 tools_dir = os.path.dirname(os.path.realpath(__file__)) |
| 591 dart_binary_prefix = os.path.join(tools_dir, '..', 'sdk' , 'bin') | 594 dart_binary_prefix = os.path.join(tools_dir, '..', 'sdk' , 'bin') |
| 592 return os.path.join(dart_binary_prefix, 'dart') | 595 return os.path.join(dart_binary_prefix, 'dart') |
| 593 | 596 |
| 597 | |
| 598 def CheckedInSdkPath(): | |
| 599 osdict = {'Darwin':'mac', 'Linux':'linux', 'Windows':'win'} | |
|
ricow1
2015/09/14 05:46:41
please add a comment here:
# We don't use the norm
Cutch
2015/09/14 14:05:43
Done.
| |
| 600 system = platform.system() | |
| 601 try: | |
| 602 osname = osdict[system] | |
| 603 except KeyError: | |
| 604 print >>sys.stderr, ('WARNING: platform "%s" not supported') % (system) | |
| 605 return None; | |
| 606 return os.path.join(DART_ROOT, | |
|
ricow1
2015/09/14 05:46:41
This seems to work better in general
tools_dir = o
Cutch
2015/09/14 14:05:43
Done.
| |
| 607 'tools', | |
| 608 'sdks', | |
| 609 osname, | |
| 610 'dart-sdk') | |
| 611 | |
| 612 | |
| 613 def CheckedInPubPath(): | |
| 614 executable_name = 'pub' | |
| 615 if platform.system() == 'Windows': | |
| 616 executable_name = 'pub.bat' | |
| 617 return os.path.join(CheckedInSdkPath(), 'bin', executable_name) | |
| 618 | |
| 619 | |
| 594 class TempDir(object): | 620 class TempDir(object): |
| 595 def __init__(self, prefix=''): | 621 def __init__(self, prefix=''): |
| 596 self._temp_dir = None | 622 self._temp_dir = None |
| 597 self._prefix = prefix | 623 self._prefix = prefix |
| 598 | 624 |
| 599 def __enter__(self): | 625 def __enter__(self): |
| 600 self._temp_dir = tempfile.mkdtemp(self._prefix) | 626 self._temp_dir = tempfile.mkdtemp(self._prefix) |
| 601 return self._temp_dir | 627 return self._temp_dir |
| 602 | 628 |
| 603 def __exit__(self, *_): | 629 def __exit__(self, *_): |
| 604 shutil.rmtree(self._temp_dir, ignore_errors=True) | 630 shutil.rmtree(self._temp_dir, ignore_errors=True) |
| 605 | 631 |
| 606 class ChangedWorkingDirectory(object): | 632 class ChangedWorkingDirectory(object): |
| 607 def __init__(self, working_directory): | 633 def __init__(self, working_directory): |
| 608 self._working_directory = working_directory | 634 self._working_directory = working_directory |
| 609 | 635 |
| 610 def __enter__(self): | 636 def __enter__(self): |
| 611 self._old_cwd = os.getcwd() | 637 self._old_cwd = os.getcwd() |
| 612 print "Enter directory = ", self._working_directory | 638 print "Enter directory = ", self._working_directory |
| 613 os.chdir(self._working_directory) | 639 os.chdir(self._working_directory) |
| 614 | 640 |
| 615 def __exit__(self, *_): | 641 def __exit__(self, *_): |
| 616 print "Enter directory = ", self._old_cwd | 642 print "Enter directory = ", self._old_cwd |
| 617 os.chdir(self._old_cwd) | 643 os.chdir(self._old_cwd) |
| 618 | 644 |
| 619 | 645 |
| 620 if __name__ == "__main__": | 646 if __name__ == "__main__": |
| 621 import sys | 647 import sys |
| 622 Main() | 648 Main() |
| OLD | NEW |