| 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 20 matching lines...) Expand all Loading... |
| 31 'ShadowDOM.*', | 31 'ShadowDOM.*', |
| 32 'webcomponents.*', | 32 'webcomponents.*', |
| 33 'webcomponents-lite.js', | 33 'webcomponents-lite.js', |
| 34 'unittest*', | 34 'unittest*', |
| 35 '*_buildLogs*', | 35 '*_buildLogs*', |
| 36 '*.log', | 36 '*.log', |
| 37 '*~') | 37 '*~') |
| 38 | 38 |
| 39 usage = """observatory_tool.py [options]""" | 39 usage = """observatory_tool.py [options]""" |
| 40 | 40 |
| 41 # Run |command|. If its return code is 0, return 0 and swallow its output. |
| 42 # If its return code is non-zero, emit its output unless |always_silent| is |
| 43 # True, and return the return code. |
| 44 def RunCommand(command, always_silent=False): |
| 45 try: |
| 46 subprocess.check_output(command, stderr=subprocess.STDOUT) |
| 47 return 0 |
| 48 except subprocess.CalledProcessError as e: |
| 49 if not always_silent: |
| 50 print ("Command failed: " + ' '.join(command) + "\n" + |
| 51 "output: " + e.output) |
| 52 return e.returncode |
| 53 |
| 41 def CreateTimestampFile(options): | 54 def CreateTimestampFile(options): |
| 42 if options.stamp != '': | 55 if options.stamp != '': |
| 43 dir_name = os.path.dirname(options.stamp) | 56 dir_name = os.path.dirname(options.stamp) |
| 44 if dir_name != '': | 57 if dir_name != '': |
| 45 if not os.path.exists(dir_name): | 58 if not os.path.exists(dir_name): |
| 46 os.mkdir(dir_name) | 59 os.mkdir(dir_name) |
| 47 open(options.stamp, 'w').close() | 60 open(options.stamp, 'w').close() |
| 48 | 61 |
| 49 def BuildArguments(): | 62 def BuildArguments(): |
| 50 result = argparse.ArgumentParser(usage=usage) | 63 result = argparse.ArgumentParser(usage=usage) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 68 return False | 81 return False |
| 69 | 82 |
| 70 if (options.sdk is not None) and (options.sdk == "True"): | 83 if (options.sdk is not None) and (options.sdk == "True"): |
| 71 options.sdk = True | 84 options.sdk = True |
| 72 elif (options.sdk is None) or (options.sdk == "False"): | 85 elif (options.sdk is None) or (options.sdk == "False"): |
| 73 options.sdk = False | 86 options.sdk = False |
| 74 else: | 87 else: |
| 75 print "--sdk expects 'True' or 'False' argument." | 88 print "--sdk expects 'True' or 'False' argument." |
| 76 return False | 89 return False |
| 77 | 90 |
| 78 with open(os.devnull, 'wb') as silent_sink: | 91 # Required options. |
| 79 # Required options. | 92 if options.command is None or options.directory is None: |
| 80 if options.command is None or options.directory is None: | 93 return False |
| 81 return False | |
| 82 | 94 |
| 83 # Set a default value for pub_snapshot. | 95 # Set a default value for pub_snapshot. |
| 84 options.pub_snapshot = None | 96 options.pub_snapshot = None |
| 85 | 97 |
| 86 # If we have a working pub executable, try and use that. | 98 # If we have a working pub executable, try and use that. |
| 87 # TODO(whesse): Drop the pub-executable option if it isn't used. | 99 # TODO(whesse): Drop the pub-executable option if it isn't used. |
| 88 if options.pub_executable is not None: | 100 if options.pub_executable is not None: |
| 89 try: | 101 try: |
| 90 if 0 == subprocess.call([options.pub_executable, '--version'], | 102 if 0 == RunCommand([options.pub_executable, '--version'], |
| 91 stdout=silent_sink, | 103 always_silent=True): |
| 92 stderr=silent_sink): | 104 return True |
| 93 return True | 105 except OSError as e: |
| 94 except OSError as e: | 106 pass |
| 95 pass | 107 options.pub_executable = None |
| 96 options.pub_executable = None | |
| 97 | 108 |
| 98 if options.sdk and utils.CheckedInSdkCheckExecutable(): | 109 if options.sdk and utils.CheckedInSdkCheckExecutable(): |
| 99 # Use the checked in pub executable. | 110 # Use the checked in pub executable. |
| 100 options.pub_snapshot = os.path.join(utils.CheckedInSdkPath(), | 111 options.pub_snapshot = os.path.join(utils.CheckedInSdkPath(), |
| 101 'bin', | 112 'bin', |
| 102 'snapshots', | 113 'snapshots', |
| 103 'pub.dart.snapshot'); | 114 'pub.dart.snapshot'); |
| 104 try: | 115 try: |
| 105 if 0 == subprocess.call([utils.CheckedInSdkExecutable(), | 116 if 0 == RunCommand([utils.CheckedInSdkExecutable(), |
| 106 options.pub_snapshot, | 117 options.pub_snapshot, |
| 107 '--version'], | 118 '--version'], always_silent=True): |
| 108 stdout=silent_sink, | 119 return True |
| 109 stderr=silent_sink): | 120 except OSError as e: |
| 110 return True | 121 pass |
| 111 except OSError as e: | 122 options.pub_snapshot = None |
| 112 pass | |
| 113 options.pub_snapshot = None | |
| 114 | 123 |
| 115 # We need a dart executable. | 124 # We need a dart executable. |
| 116 return (options.dart_executable is not None) | 125 return (options.dart_executable is not None) |
| 117 | 126 |
| 118 def ChangeDirectory(directory): | 127 def ChangeDirectory(directory): |
| 119 os.chdir(directory); | 128 os.chdir(directory); |
| 120 | 129 |
| 121 def DisplayBootstrapWarning(): | 130 def DisplayBootstrapWarning(): |
| 122 print """\ | 131 print """\ |
| 123 | 132 |
| 124 | 133 |
| 125 WARNING: Your system cannot run the checked-in Dart SDK. Using the | 134 WARNING: Your system cannot run the checked-in Dart SDK. Using the |
| 126 bootstrap Dart executable will make debug builds slow. | 135 bootstrap Dart executable will make debug builds slow. |
| 127 Please see the Wiki for instructions on replacing the checked-in Dart SDK. | 136 Please see the Wiki for instructions on replacing the checked-in Dart SDK. |
| 128 | 137 |
| 129 https://github.com/dart-lang/sdk/wiki/The-checked-in-SDK-in-tools | 138 https://github.com/dart-lang/sdk/wiki/The-checked-in-SDK-in-tools |
| 130 | 139 |
| 131 To use the dart_bootstrap binary please update the PubCommand function | 140 To use the dart_bootstrap binary please update the PubCommand function |
| 132 in the tools/observatory_tool.py script. | 141 in the tools/observatory_tool.py script. |
| 133 | 142 |
| 134 """ | 143 """ |
| 135 | 144 |
| 136 def PubCommand(dart_executable, | 145 def PubCommand(dart_executable, |
| 137 pub_executable, | 146 pub_executable, |
| 138 pub_snapshot, | 147 pub_snapshot, |
| 139 command, | 148 command, |
| 140 silent): | 149 silent): |
| 141 with open(os.devnull, 'wb') as silent_sink: | 150 if pub_executable is not None: |
| 142 if pub_executable is not None: | 151 executable = [pub_executable] |
| 143 executable = [pub_executable] | 152 elif pub_snapshot is not None: |
| 144 elif pub_snapshot is not None: | 153 executable = [utils.CheckedInSdkExecutable(), pub_snapshot] |
| 145 executable = [utils.CheckedInSdkExecutable(), pub_snapshot] | 154 else: |
| 146 else: | 155 if not silent: |
| 147 DisplayBootstrapWarning() | 156 DisplayBootstrapWarning() |
| 148 executable = [dart_executable, PUB_PATH] | 157 executable = [dart_executable, PUB_PATH] |
| 149 # Prevent the bootstrap Dart executable from running in regular | 158 # Prevent the bootstrap Dart executable from running in regular |
| 150 # development flow. | 159 # development flow. |
| 151 # REMOVE THE FOLLOWING LINE TO USE the dart_bootstrap binary. | 160 # REMOVE THE FOLLOWING LINE TO USE the dart_bootstrap binary. |
| 152 # return False | 161 # return False |
| 153 if not silent: | 162 if not silent: |
| 154 print >> sys.stderr, ('Running command "%s"') % (executable + command) | 163 print >> sys.stderr, ('Running command "%s"') % (executable + command) |
| 155 return subprocess.call(executable + command, | 164 return RunCommand(executable + command) |
| 156 stdout=silent_sink if silent else None, | |
| 157 stderr=silent_sink if silent else None) | |
| 158 | 165 |
| 159 def Deploy(input_dir, output_dir): | 166 def Deploy(input_dir, output_dir): |
| 160 shutil.rmtree(output_dir) | 167 shutil.rmtree(output_dir) |
| 161 shutil.copytree(input_dir, output_dir, ignore=IGNORE_PATTERNS) | 168 shutil.copytree(input_dir, output_dir, ignore=IGNORE_PATTERNS) |
| 162 index_file = os.path.join(output_dir, 'web', 'index.html') | 169 index_file = os.path.join(output_dir, 'web', 'index.html') |
| 163 os.utime(index_file, None) | 170 os.utime(index_file, None) |
| 164 return 0 | 171 return 0 |
| 165 | 172 |
| 166 def RewritePubSpec(input_path, output_path, search, replace): | 173 def RewritePubSpec(input_path, output_path, search, replace): |
| 167 with open(input_path, 'rb') as input_file: | 174 with open(input_path, 'rb') as input_file: |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 # Pub must be run from the project's root directory. | 227 # Pub must be run from the project's root directory. |
| 221 ChangeDirectory(options.directory) | 228 ChangeDirectory(options.directory) |
| 222 result = ExecuteCommand(options, args) | 229 result = ExecuteCommand(options, args) |
| 223 if result == 0: | 230 if result == 0: |
| 224 CreateTimestampFile(options) | 231 CreateTimestampFile(options) |
| 225 return result | 232 return result |
| 226 | 233 |
| 227 | 234 |
| 228 if __name__ == '__main__': | 235 if __name__ == '__main__': |
| 229 sys.exit(main()); | 236 sys.exit(main()); |
| OLD | NEW |