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 18 matching lines...) Expand all Loading... |
29 | 29 |
30 usage = """observatory_tool.py [options]""" | 30 usage = """observatory_tool.py [options]""" |
31 | 31 |
32 def BuildArguments(): | 32 def BuildArguments(): |
33 result = argparse.ArgumentParser(usage=usage) | 33 result = argparse.ArgumentParser(usage=usage) |
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=None) |
40 result.add_argument("--sdk", help="Use prebuilt sdk", default=False) | 40 result.add_argument("--sdk", help="Use prebuilt sdk", default=None) |
41 return result | 41 return result |
42 | 42 |
43 def ProcessOptions(options, args): | 43 def ProcessOptions(options, args): |
| 44 # Fix broken boolean parsing in argparse, where False ends up being True. |
| 45 if (options.silent is not None) and (options.silent == "True"): |
| 46 options.silent = True |
| 47 elif (options.silent is None) or (options.silent == "False"): |
| 48 options.silent = False |
| 49 else: |
| 50 print "--silent expects 'True' or 'False' argument." |
| 51 return False |
| 52 |
| 53 if (options.sdk is not None) and (options.sdk == "True"): |
| 54 options.sdk = True |
| 55 elif (options.sdk is None) or (options.sdk == "False"): |
| 56 options.sdk = False |
| 57 else: |
| 58 print "--sdk expects 'True' or 'False' argument." |
| 59 return False |
| 60 |
44 with open(os.devnull, 'wb') as silent_sink: | 61 with open(os.devnull, 'wb') as silent_sink: |
45 # Required options. | 62 # Required options. |
46 if options.command is None or options.directory is None: | 63 if options.command is None or options.directory is None: |
47 return False | 64 return False |
48 | 65 |
49 # Set a default value for pub_snapshot. | 66 # Set a default value for pub_snapshot. |
50 options.pub_snapshot = None | 67 options.pub_snapshot = None |
51 | 68 |
52 # If we have a working pub executable, try and use that. | 69 # If we have a working pub executable, try and use that. |
53 # TODO(whesse): Drop the pub-executable option if it isn't used. | 70 # TODO(whesse): Drop the pub-executable option if it isn't used. |
54 if options.pub_executable is not None: | 71 if options.pub_executable is not None: |
55 try: | 72 try: |
56 if 0 == subprocess.call([options.pub_executable, '--version'], | 73 if 0 == subprocess.call([options.pub_executable, '--version'], |
57 stdout=silent_sink, | 74 stdout=silent_sink, |
58 stderr=silent_sink): | 75 stderr=silent_sink): |
59 return True | 76 return True |
60 except OSError as e: | 77 except OSError as e: |
61 pass | 78 pass |
62 options.pub_executable = None | 79 options.pub_executable = None |
63 | 80 |
64 if options.sdk is not None and utils.CheckedInSdkCheckExecutable(): | 81 if options.sdk and utils.CheckedInSdkCheckExecutable(): |
65 # Use the checked in pub executable. | 82 # Use the checked in pub executable. |
66 options.pub_snapshot = os.path.join(utils.CheckedInSdkPath(), | 83 options.pub_snapshot = os.path.join(utils.CheckedInSdkPath(), |
67 'bin', | 84 'bin', |
68 'snapshots', | 85 'snapshots', |
69 'pub.dart.snapshot'); | 86 'pub.dart.snapshot'); |
70 try: | 87 try: |
71 if 0 == subprocess.call([utils.CheckedInSdkExecutable(), | 88 if 0 == subprocess.call([utils.CheckedInSdkExecutable(), |
72 options.pub_snapshot, | 89 options.pub_snapshot, |
73 '--version'], | 90 '--version'], |
74 stdout=silent_sink, | 91 stdout=silent_sink, |
(...skipping 11 matching lines...) Expand all Loading... |
86 os.chdir(directory); | 103 os.chdir(directory); |
87 | 104 |
88 def DisplayBootstrapWarning(): | 105 def DisplayBootstrapWarning(): |
89 print """\ | 106 print """\ |
90 | 107 |
91 | 108 |
92 WARNING: Your system cannot run the checked-in Dart SDK. Using the | 109 WARNING: Your system cannot run the checked-in Dart SDK. Using the |
93 bootstrap Dart executable will make debug builds slow. | 110 bootstrap Dart executable will make debug builds slow. |
94 Please see the Wiki for instructions on replacing the checked-in Dart SDK. | 111 Please see the Wiki for instructions on replacing the checked-in Dart SDK. |
95 | 112 |
96 https://github.com/dart-lang/sdk/wiki/The-checked-in-SDK-in--tools | 113 https://github.com/dart-lang/sdk/wiki/The-checked-in-SDK-in-tools |
| 114 |
| 115 To use the dart_bootstrap binary please update the PubCommand function |
| 116 in the tools/observatory_tool.py script. |
97 | 117 |
98 """ | 118 """ |
99 | 119 |
100 def PubCommand(dart_executable, | 120 def PubCommand(dart_executable, |
101 pub_executable, | 121 pub_executable, |
102 pub_snapshot, | 122 pub_snapshot, |
103 pkg_root, | 123 pkg_root, |
104 command, | 124 command, |
105 silent): | 125 silent): |
106 with open(os.devnull, 'wb') as silent_sink: | 126 with open(os.devnull, 'wb') as silent_sink: |
107 if pub_executable is not None: | 127 if pub_executable is not None: |
108 executable = [pub_executable] | 128 executable = [pub_executable] |
109 elif pub_snapshot is not None: | 129 elif pub_snapshot is not None: |
110 executable = [utils.CheckedInSdkExecutable(), pub_snapshot] | 130 executable = [utils.CheckedInSdkExecutable(), pub_snapshot] |
111 else: | 131 else: |
112 DisplayBootstrapWarning() | 132 DisplayBootstrapWarning() |
113 executable = [dart_executable, '--package-root=' + pkg_root, PUB_PATH] | 133 executable = [dart_executable, '--package-root=' + pkg_root, PUB_PATH] |
| 134 # Prevent the bootstrap Dart executable from running in regular |
| 135 # development flow. |
| 136 # REMOVE THE FOLLOWING LINE TO USE the dart_bootstrap binary. |
| 137 return False |
114 return subprocess.call(executable + command, | 138 return subprocess.call(executable + command, |
115 stdout=silent_sink if silent else None, | 139 stdout=silent_sink if silent else None, |
116 stderr=silent_sink if silent else None) | 140 stderr=silent_sink if silent else None) |
117 | 141 |
118 def Deploy(input_dir, output_dir): | 142 def Deploy(input_dir, output_dir): |
119 shutil.rmtree(output_dir) | 143 shutil.rmtree(output_dir) |
120 shutil.copytree(input_dir, output_dir, ignore=IGNORE_PATTERNS) | 144 shutil.copytree(input_dir, output_dir, ignore=IGNORE_PATTERNS) |
121 index_file = os.path.join(output_dir, 'web', 'index.html') | 145 index_file = os.path.join(output_dir, 'web', 'index.html') |
122 os.utime(index_file, None) | 146 os.utime(index_file, None) |
123 return 0 | 147 return 0 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 if (options.pub_snapshot != None): | 201 if (options.pub_snapshot != None): |
178 options.pub_snapshot = os.path.abspath(options.pub_snapshot) | 202 options.pub_snapshot = os.path.abspath(options.pub_snapshot) |
179 if len(args) == 1: | 203 if len(args) == 1: |
180 args[0] = os.path.abspath(args[0]) | 204 args[0] = os.path.abspath(args[0]) |
181 # Pub must be run from the project's root directory. | 205 # Pub must be run from the project's root directory. |
182 ChangeDirectory(options.directory) | 206 ChangeDirectory(options.directory) |
183 return ExecuteCommand(options, args) | 207 return ExecuteCommand(options, args) |
184 | 208 |
185 if __name__ == '__main__': | 209 if __name__ == '__main__': |
186 sys.exit(main()); | 210 sys.exit(main()); |
OLD | NEW |