| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 2 # | |
| 3 # Copyright 2015 The Chromium Authors. All rights reserved. | |
| 4 # Use of this source code is governed by a BSD-style license that can be | |
| 5 # found in the LICENSE file. | |
| 6 | |
| 7 """Utility for updating third_party packages used in the Mojo Dart SDK""" | |
| 8 | |
| 9 import argparse | |
| 10 import errno | |
| 11 import json | |
| 12 import os | |
| 13 import shutil | |
| 14 import subprocess | |
| 15 import sys | |
| 16 | |
| 17 SCRIPT_DIR = os.path.dirname(sys.argv[0]) | |
| 18 | |
| 19 def check_for_pubspec_yaml(directory): | |
| 20 return os.path.exists(os.path.join(directory, 'pubspec.yaml')) | |
| 21 | |
| 22 def change_directory(directory): | |
| 23 return os.chdir(directory) | |
| 24 | |
| 25 def list_packages(directory): | |
| 26 for child in os.listdir(directory): | |
| 27 path = os.path.join(directory, child) | |
| 28 if os.path.isdir(path): | |
| 29 print(child) | |
| 30 | |
| 31 def remove_existing_packages(base_path): | |
| 32 print('Removing all package directories under %s' % base_path) | |
| 33 for child in os.listdir(base_path): | |
| 34 path = os.path.join(base_path, child) | |
| 35 if os.path.isdir(path): | |
| 36 print('Removing %s ' % path) | |
| 37 shutil.rmtree(path) | |
| 38 | |
| 39 def pub_get(pub_exe): | |
| 40 return subprocess.check_output([pub_exe, 'get']) | |
| 41 | |
| 42 def copy_packages(base_path): | |
| 43 packages_path = os.path.join(base_path, 'packages') | |
| 44 for package in os.listdir(packages_path): | |
| 45 lib_path = os.path.realpath(os.path.join(packages_path, package)) | |
| 46 package_path = os.path.normpath(os.path.join(lib_path, '..')) | |
| 47 destinaton_path = os.path.join(base_path, package) | |
| 48 print('Copying %s to %s' % (package_path, destinaton_path)) | |
| 49 shutil.copytree(package_path, destinaton_path) | |
| 50 | |
| 51 def cleanup(base_path): | |
| 52 shutil.rmtree(os.path.join(base_path, 'packages'), True) | |
| 53 shutil.rmtree(os.path.join(base_path, '.pub'), True) | |
| 54 os.remove(os.path.join(base_path, '.packages')) | |
| 55 | |
| 56 def main(): | |
| 57 parser = argparse.ArgumentParser(description='Update third_party packages') | |
| 58 parser.add_argument( | |
| 59 '--pub-exe', | |
| 60 action='store', | |
| 61 metavar='pub_exe', | |
| 62 help='Path to the pub executable', | |
| 63 default='../../../../third_party/dart-sdk/dart-sdk/bin/pub') | |
| 64 parser.add_argument('--directory', | |
| 65 action='store', | |
| 66 metavar='directory', | |
| 67 help='Directory containing pubspec.yaml', | |
| 68 default='.') | |
| 69 parser.add_argument('--list', | |
| 70 help='List mode', | |
| 71 action='store_true', | |
| 72 default=False) | |
| 73 args = parser.parse_args() | |
| 74 args.directory = os.path.abspath(args.directory) | |
| 75 | |
| 76 if not check_for_pubspec_yaml(args.directory): | |
| 77 print('Error could not find pubspec.yaml') | |
| 78 return 1 | |
| 79 | |
| 80 if args.list: | |
| 81 list_packages(args.directory) | |
| 82 else: | |
| 83 remove_existing_packages(args.directory) | |
| 84 change_directory(args.directory) | |
| 85 print('Running pub get') | |
| 86 pub_get(args.pub_exe) | |
| 87 copy_packages(args.directory) | |
| 88 print('Cleaning up') | |
| 89 cleanup(args.directory) | |
| 90 | |
| 91 if __name__ == '__main__': | |
| 92 sys.exit(main()) | |
| OLD | NEW |