OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
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 | |
4 # BSD-style license that can be found in the LICENSE file. | |
5 """Helper for building and deploying Observatory""" | |
6 | |
7 import argparse | |
8 import os | |
9 import shutil | |
10 import subprocess | |
11 import sys | |
12 | |
13 SCRIPT_DIR = os.path.dirname(sys.argv[0]) | |
14 DART_ROOT = os.path.realpath(os.path.join(SCRIPT_DIR, '..')) | |
15 RUN_PUB = os.path.join(DART_ROOT, 'tools/run_pub.py') | |
16 IGNORE_PATTERNS = shutil.ignore_patterns( | |
17 '*.map', | |
18 '*.concat.js', | |
19 '*.scriptUrls', | |
20 '*.precompiled.js', | |
21 'main.*', | |
22 'unittest*', | |
23 '*_buildLogs*', | |
24 '*.log', | |
25 '*~') | |
26 | |
27 usage = """obs_tool.py [options]""" | |
28 | |
29 def BuildArguments(): | |
30 result = argparse.ArgumentParser(usage=usage) | |
31 result.add_argument("--package-root", help="package root", default=None) | |
32 result.add_argument("--dart-executable", help="dart executable", default=None) | |
33 result.add_argument("--directory", help="observatory root", default=None) | |
34 result.add_argument("--command", help="[get, build, deploy]", default=None) | |
35 return result | |
36 | |
37 def ProcessOptions(options, args): | |
38 return ((options.package_root != None) and | |
39 (options.directory != None) and | |
40 (options.command != None) and | |
41 (options.dart_executable != None)) | |
42 | |
43 def ChangeDirectory(directory): | |
44 os.chdir(directory); | |
45 | |
46 def PubGet(dart_executable, pkg_root): | |
47 return subprocess.call(['python', | |
48 RUN_PUB, | |
49 '--package-root=' + pkg_root, | |
50 '--dart-executable=' + dart_executable, | |
51 'get', | |
52 '--offline']) | |
53 | |
54 def PubBuild(dart_executable, pkg_root, output_dir): | |
55 return subprocess.call(['python', | |
56 RUN_PUB, | |
57 '--package-root=' + pkg_root, | |
58 '--dart-executable=' + dart_executable, | |
59 'build', | |
60 '--output', | |
61 output_dir]) | |
62 | |
63 def Deploy(input_dir, output_dir): | |
64 shutil.rmtree(output_dir) | |
65 shutil.copytree(input_dir, output_dir, ignore=IGNORE_PATTERNS) | |
66 return 0 | |
67 | |
68 def ExecuteCommand(options, args): | |
69 cmd = options.command | |
70 if (cmd == 'get'): | |
71 PubGet(options.dart_executable, options.package_root) | |
72 elif (cmd == 'build'): | |
73 PubBuild(options.dart_executable, options.package_root, args[0]) | |
74 elif (cmd == 'deploy'): | |
75 Deploy('build', 'deployed') | |
76 else: | |
77 print >> sys.stderr, ('ERROR: command "%s" not supported') % (cmd) | |
78 return -1; | |
79 | |
80 def main(): | |
81 # Parse the options. | |
82 parser = BuildArguments() | |
83 (options, args) = parser.parse_known_args() | |
84 if not ProcessOptions(options, args): | |
85 parser.print_help() | |
86 return 1 | |
87 ChangeDirectory(options.directory) | |
88 return ExecuteCommand(options, args) | |
89 | |
90 if __name__ == '__main__': | |
91 sys.exit(main()); | |
OLD | NEW |