OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2017, 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 |
| 6 import argparse |
| 7 import os |
| 8 import re |
| 9 import shutil |
| 10 import sys |
| 11 |
| 12 def ParseArgs(args): |
| 13 args = args[1:] |
| 14 parser = argparse.ArgumentParser( |
| 15 description='A script to copy a file tree somewhere') |
| 16 |
| 17 parser.add_argument('--exclude_patterns', '-e', |
| 18 type=str, |
| 19 help='Patterns to exclude [passed to shutil.copytree]') |
| 20 parser.add_argument('--from', '-f', |
| 21 dest="copy_from", |
| 22 type=str, |
| 23 required=True, |
| 24 help='Source tree root') |
| 25 parser.add_argument('--to', '-t', |
| 26 type=str, |
| 27 required=True, |
| 28 help='Destination') |
| 29 |
| 30 return parser.parse_args(args) |
| 31 |
| 32 |
| 33 def ValidateArgs(args): |
| 34 if not os.path.isdir(args.copy_from): |
| 35 print "--from argument must refer to a directory" |
| 36 return False |
| 37 return True |
| 38 |
| 39 |
| 40 def Main(argv): |
| 41 args = ParseArgs(argv) |
| 42 if not ValidateArgs(args): |
| 43 return -1 |
| 44 if os.path.exists(args.to): |
| 45 shutil.rmtree(args.to) |
| 46 if args.exclude_patterns == None: |
| 47 shutil.copytree(args.copy_from, args.to) |
| 48 else: |
| 49 patterns = args.exclude_patterns.split(',') |
| 50 shutil.copytree(args.copy_from, args.to, |
| 51 ignore=shutil.ignore_patterns(tuple(patterns))) |
| 52 return 0 |
| 53 |
| 54 |
| 55 if __name__ == '__main__': |
| 56 sys.exit(Main(sys.argv)) |
OLD | NEW |