Index: tools/observatory_tool.py |
diff --git a/tools/observatory_tool.py b/tools/observatory_tool.py |
index 45fc36a9ef2901c79e25923e869de30e51e79fb9..f5ac40b74c6849824a9cb942d3f9f7e7034a4d7c 100755 |
--- a/tools/observatory_tool.py |
+++ b/tools/observatory_tool.py |
@@ -30,54 +30,85 @@ def BuildArguments(): |
result = argparse.ArgumentParser(usage=usage) |
result.add_argument("--package-root", help="package root", default=None) |
result.add_argument("--dart-executable", help="dart executable", default=None) |
+ result.add_argument("--pub-executable", help="pub executable", default=None) |
result.add_argument("--directory", help="observatory root", default=None) |
result.add_argument("--command", help="[get, build, deploy]", default=None) |
return result |
def ProcessOptions(options, args): |
+ # Required options. |
+ if (options.command == None) or (options.directory == None): |
+ return False |
+ # If we have a pub executable, we are running from the dart-sdk. |
+ if (options.pub_executable != None): |
+ return True |
+ # Otherwise, we need a dart executable and a package root. |
return ((options.package_root != None) and |
- (options.directory != None) and |
- (options.command != None) and |
(options.dart_executable != None)) |
def ChangeDirectory(directory): |
os.chdir(directory); |
-def PubGet(dart_executable, pkg_root): |
+def PubGet(dart_executable, pub_executable, pkg_root): |
# Always remove pubspec.lock before running 'pub get'. |
try: |
os.remove('pubspec.lock'); |
except OSError as e: |
pass |
- return subprocess.call(['python', |
- RUN_PUB, |
- '--package-root=' + pkg_root, |
- '--dart-executable=' + dart_executable, |
- 'get', |
- '--offline']) |
+ if (pub_executable != None): |
+ return subprocess.call([pub_executable, |
+ 'get', |
+ '--offline']) |
+ else: |
+ return subprocess.call(['python', |
+ RUN_PUB, |
+ '--package-root=' + pkg_root, |
+ '--dart-executable=' + dart_executable, |
+ 'get', |
+ '--offline']) |
-def PubBuild(dart_executable, pkg_root, output_dir): |
- return subprocess.call(['python', |
- RUN_PUB, |
- '--package-root=' + pkg_root, |
- '--dart-executable=' + dart_executable, |
- 'build', |
- '--output', |
- output_dir]) |
+def PubBuild(dart_executable, pub_executable, pkg_root, output_dir): |
+ if (pub_executable != None): |
+ return subprocess.call([pub_executable, |
+ 'build', |
+ '--output', |
+ output_dir]) |
+ else: |
+ return subprocess.call(['python', |
+ RUN_PUB, |
+ '--package-root=' + pkg_root, |
+ '--dart-executable=' + dart_executable, |
+ 'build', |
+ '--output', |
+ output_dir]) |
def Deploy(input_dir, output_dir): |
shutil.rmtree(output_dir) |
shutil.copytree(input_dir, output_dir, ignore=IGNORE_PATTERNS) |
return 0 |
+def RewritePubSpec(input_path, output_path, search, replace): |
+ with open(input_path, 'rb') as input_file: |
+ input_data = input_file.read() |
+ input_data = input_data.replace(search, replace) |
+ with open(output_path, 'wb+') as output_file: |
+ output_file.write(input_data) |
+ |
def ExecuteCommand(options, args): |
cmd = options.command |
if (cmd == 'get'): |
- return PubGet(options.dart_executable, options.package_root) |
+ return PubGet(options.dart_executable, |
+ options.pub_executable, |
+ options.package_root) |
elif (cmd == 'build'): |
- return PubBuild(options.dart_executable, options.package_root, args[0]) |
+ return PubBuild(options.dart_executable, |
+ options.pub_executable, |
+ options.package_root, |
+ args[0]) |
elif (cmd == 'deploy'): |
Deploy('build', 'deployed') |
+ elif (cmd == 'rewrite'): |
+ RewritePubSpec(args[0], args[1], args[2], args[3]) |
else: |
print >> sys.stderr, ('ERROR: command "%s" not supported') % (cmd) |
return -1; |
@@ -92,8 +123,12 @@ def main(): |
if os.getenv('DART_USE_BOOTSTRAP_BIN') != None: |
dart_executable = options.dart_executable |
# Calculate absolute paths before changing directory. |
- options.package_root = os.path.abspath(options.package_root) |
- options.dart_executable = os.path.abspath(options.dart_executable) |
+ if (options.package_root != None): |
+ options.package_root = os.path.abspath(options.package_root) |
+ if (options.dart_executable != None): |
+ options.dart_executable = os.path.abspath(options.dart_executable) |
+ if (options.pub_executable != None): |
+ options.pub_executable = os.path.abspath(options.pub_executable) |
if len(args) == 1: |
args[0] = os.path.abspath(args[0]) |
# Pub must be run from the project's root directory. |