Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 2 # Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 3 # for details. All rights reserved. Use of this source code is governed by a | 3 # for details. All rights reserved. Use of this source code is governed by a |
| 4 # BSD-style license that can be found in the LICENSE file. | 4 # BSD-style license that can be found in the LICENSE file. |
| 5 """Helper for building and deploying Observatory""" | 5 """Helper for building and deploying Observatory""" |
| 6 | 6 |
| 7 import argparse | 7 import argparse |
| 8 import os | 8 import os |
| 9 import platform | 9 import platform |
| 10 import shutil | 10 import shutil |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 result.add_argument("--package-root", help="package root", default=None) | 34 result.add_argument("--package-root", help="package root", default=None) |
| 35 result.add_argument("--dart-executable", help="dart executable", default=None) | 35 result.add_argument("--dart-executable", help="dart executable", default=None) |
| 36 result.add_argument("--pub-executable", help="pub executable", default=None) | 36 result.add_argument("--pub-executable", help="pub executable", default=None) |
| 37 result.add_argument("--directory", help="observatory root", default=None) | 37 result.add_argument("--directory", help="observatory root", default=None) |
| 38 result.add_argument("--command", help="[get, build, deploy]", default=None) | 38 result.add_argument("--command", help="[get, build, deploy]", default=None) |
| 39 result.add_argument("--silent", help="silence all output", default=False) | 39 result.add_argument("--silent", help="silence all output", default=False) |
| 40 result.add_argument("--sdk", help="Use prebuilt sdk", default=False) | 40 result.add_argument("--sdk", help="Use prebuilt sdk", default=False) |
| 41 return result | 41 return result |
| 42 | 42 |
| 43 def ProcessOptions(options, args): | 43 def ProcessOptions(options, args): |
| 44 # Required options. | 44 with open(os.devnull, 'wb') as silent_sink: |
| 45 if options.command is None or options.directory is None: | 45 # Required options. |
| 46 return False | 46 if options.command is None or options.directory is None: |
| 47 return False | |
| 47 | 48 |
| 48 # Set a default value for pub_snapshot. | 49 # Set a default value for pub_snapshot. |
| 49 options.pub_snapshot = None | 50 options.pub_snapshot = None |
| 50 | 51 |
| 51 # If we have a working pub executable, try and use that. | 52 # If we have a working pub executable, try and use that. |
| 52 # TODO(whesse): Drop the pub-executable option if it isn't used. | 53 # TODO(whesse): Drop the pub-executable option if it isn't used. |
| 53 if options.pub_executable is not None: | 54 if options.pub_executable is not None: |
| 54 try: | 55 try: |
| 55 if 0 == subprocess.call([options.pub_executable, '--version']): | 56 if 0 == subprocess.call([options.pub_executable, '--version'], |
| 56 return True | 57 stdout=silent_sink, |
| 57 except OSError as e: | 58 stderr=silent_sink): |
| 58 pass | 59 return True |
| 59 options.pub_executable = None | 60 except OSError as e: |
| 61 pass | |
| 62 options.pub_executable = None | |
| 60 | 63 |
| 61 if options.sdk is not None and utils.CheckedInSdkCheckExecutable(): | 64 if options.sdk is not None and utils.CheckedInSdkCheckExecutable(): |
| 62 # Use the checked in pub executable. | 65 # Use the checked in pub executable. |
| 63 options.pub_snapshot = os.path.join(utils.CheckedInSdkPath(), | 66 options.pub_snapshot = os.path.join(utils.CheckedInSdkPath(), |
| 64 'bin', | 67 'bin', |
| 65 'snapshots', | 68 'snapshots', |
| 66 'pub.dart.snapshot'); | 69 'pub.dart.snapshot'); |
| 67 try: | 70 try: |
| 68 if 0 == subprocess.call([utils.CheckedInSdkExecutable(), | 71 if 0 == subprocess.call([utils.CheckedInSdkExecutable(), |
| 69 options.pub_snapshot, | 72 options.pub_snapshot, |
| 70 '--version']): | 73 '--version'], |
| 71 return True | 74 stdout=silent_sink, |
| 72 except OSError as e: | 75 stderr=silent_sink): |
| 73 pass | 76 return True |
| 74 options.pub_snapshot = None | 77 except OSError as e: |
| 78 pass | |
| 79 options.pub_snapshot = None | |
| 75 | 80 |
| 76 # We need a dart executable and a package root. | 81 # We need a dart executable and a package root. |
| 77 return (options.package_root is not None and | 82 return (options.package_root is not None and |
| 78 options.dart_executable is not None) | 83 options.dart_executable is not None) |
|
Bob Nystrom
2015/09/29 16:06:57
Drive-by! Instead of making an explicit null sink,
| |
| 79 | 84 |
| 80 def ChangeDirectory(directory): | 85 def ChangeDirectory(directory): |
| 81 os.chdir(directory); | 86 os.chdir(directory); |
| 82 | 87 |
| 83 def DisplayBootstrapWarning(): | 88 def DisplayBootstrapWarning(): |
| 84 print """\ | 89 print """\ |
| 85 | 90 |
| 86 | 91 |
| 87 WARNING: Your system cannot run the checked-in Dart SDK. Using the | 92 WARNING: Your system cannot run the checked-in Dart SDK. Using the |
| 88 bootstrap Dart executable will make debug builds slow. | 93 bootstrap Dart executable will make debug builds slow. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 if (options.pub_snapshot != None): | 177 if (options.pub_snapshot != None): |
| 173 options.pub_snapshot = os.path.abspath(options.pub_snapshot) | 178 options.pub_snapshot = os.path.abspath(options.pub_snapshot) |
| 174 if len(args) == 1: | 179 if len(args) == 1: |
| 175 args[0] = os.path.abspath(args[0]) | 180 args[0] = os.path.abspath(args[0]) |
| 176 # Pub must be run from the project's root directory. | 181 # Pub must be run from the project's root directory. |
| 177 ChangeDirectory(options.directory) | 182 ChangeDirectory(options.directory) |
| 178 return ExecuteCommand(options, args) | 183 return ExecuteCommand(options, args) |
| 179 | 184 |
| 180 if __name__ == '__main__': | 185 if __name__ == '__main__': |
| 181 sys.exit(main()); | 186 sys.exit(main()); |
| OLD | NEW |