OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import argparse |
| 7 import os |
| 8 import shutil |
| 9 import sys |
| 10 |
| 11 |
| 12 def DoMain(argv): |
| 13 parser = argparse.ArgumentParser(description='Generate forwarding headers.') |
| 14 parser.add_argument('-i', '--list-inputs', action='store_true', |
| 15 help='List input files and exit.') |
| 16 parser.add_argument('-o', '--list-outputs', action='store_true', |
| 17 help='List output files and exit.') |
| 18 parser.add_argument('-d', '--dest-dir', type=str, |
| 19 help=('Output directory for forwarding headers.')) |
| 20 parser.add_argument('filenames', metavar='filename', type=str, nargs='+', |
| 21 help='Input filenames.') |
| 22 |
| 23 args = parser.parse_args(argv) |
| 24 if args.list_inputs: |
| 25 return list_inputs(args.filenames) |
| 26 |
| 27 if not args.dest_dir: |
| 28 print '--dest-dir is required for this command.' |
| 29 sys.exit(1) |
| 30 if args.list_outputs: |
| 31 return ' '.join( |
| 32 os.path.join(args.dest_dir, os.path.basename(filename)) |
| 33 for filename in args.filenames) |
| 34 |
| 35 if not os.path.isdir(args.dest_dir): |
| 36 os.makedirs(args.dest_dir) |
| 37 for filename in args.filenames: |
| 38 target_filename = os.path.join(args.dest_dir, os.path.basename(filename)) |
| 39 if os.path.isfile(target_filename): |
| 40 os.unlink(target_filename) |
| 41 try: |
| 42 os.link(filename, target_filename) |
| 43 except OSError as e: |
| 44 # Fallbacks to copy if hardlinking fails. |
| 45 shutil.copy(filename, target_filename) |
| 46 |
| 47 |
| 48 if __name__ == '__main__': |
| 49 results = DoMain(sys.argv[1:]) |
| 50 if results: |
| 51 print results |
OLD | NEW |