Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
|
sdefresne
2016/02/22 16:36:48
Rename to copy_files.py
| |
| 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 datetime | |
|
sdefresne
2016/02/22 16:36:48
Remove.
| |
| 8 import os | |
| 9 import sys | |
|
sdefresne
2016/02/22 16:36:48
import shutil
| |
| 10 | |
| 11 COPYRIGHT = """// Copyright {0} The Chromium Authors. All rights reserved. | |
|
sdefresne
2016/02/22 16:36:48
Remove.
| |
| 12 // Use of this source code is governed by a BSD-style license that can be | |
| 13 // found in the LICENSE file.\n | |
| 14 """.format(datetime.date.today().year) | |
| 15 | |
| 16 def filter_header_files(inputs): | |
|
sdefresne
2016/02/22 16:36:48
Remove.
| |
| 17 return [filename for filename in inputs if filename.endswith('.h')] | |
| 18 | |
| 19 def get_output_filename(input_filename, dest_dir): | |
| 20 return os.path.join(dest_dir, os.path.basename(input_filename)) | |
| 21 | |
| 22 def list_inputs(possible_inputs): | |
|
sdefresne
2016/02/22 16:36:48
Remove.
| |
| 23 return ' '.join(filter_header_files(possible_inputs)) | |
| 24 | |
| 25 def list_outputs(possible_inputs, dest_dir): | |
|
sdefresne
2016/02/22 16:36:48
s/possible_inputs/inputs/
| |
| 26 outputs = [] | |
|
sdefresne
2016/02/22 16:36:48
outputs = [ get_output_filename(filename, dest_dir
| |
| 27 for filename in filter_header_files(possible_inputs): | |
| 28 outputs.append(get_output_filename(filename, dest_dir)) | |
| 29 return ' '.join(outputs) | |
| 30 | |
| 31 def generate_headers(possible_inputs, dest_dir): | |
|
sdefresne
2016/02/22 16:36:48
Remove and replace with:
def copy_files(inputs, d
| |
| 32 for filename in filter_header_files(possible_inputs): | |
| 33 content = COPYRIGHT + '#import "{0}"\n'.format(filename) | |
| 34 forwarding_header = get_output_filename(filename, dest_dir) | |
| 35 if os.path.isfile(forwarding_header): | |
| 36 with open(forwarding_header, 'r') as header: | |
| 37 old_content = header.read() | |
| 38 if old_content == content: | |
| 39 continue | |
| 40 with open(forwarding_header, 'w') as header: | |
| 41 header.write(content) | |
| 42 | |
| 43 def DoMain(argv): | |
| 44 parser = argparse.ArgumentParser(description='Generate forwarding headers.') | |
| 45 parser.add_argument('-i', '--list-inputs', action='store_true', | |
|
sdefresne
2016/02/22 16:36:48
Remove '-i' argument.
| |
| 46 help='List input files and exit.') | |
| 47 parser.add_argument('-o', '--list-outputs', action='store_true', | |
| 48 help='List output files and exit.') | |
| 49 parser.add_argument('-d', '--dest-dir', type=str, | |
| 50 help=('Output directory for forwarding headers.')) | |
| 51 parser.add_argument('filenames', metavar='filename', type=str, nargs='+', | |
| 52 help='Input filenames.') | |
| 53 | |
| 54 args = parser.parse_args(argv) | |
| 55 if args.list_inputs: | |
|
sdefresne
2016/02/22 16:36:48
Remove.
| |
| 56 return list_inputs(args.filenames) | |
| 57 | |
| 58 if not args.dest_dir: | |
| 59 print '--dest-dir is required for this command.' | |
| 60 sys.exit(1) | |
| 61 if args.list_outputs: | |
| 62 return list_outputs(args.filenames, args.dest_dir) | |
| 63 | |
| 64 if not os.path.isdir(args.dest_dir): | |
| 65 os.makedirs(args.dest_dir) | |
| 66 generate_headers(args.filenames, args.dest_dir) | |
|
sdefresne
2016/02/22 16:36:48
copy_files(args.filenames, args.dest_dir)
| |
| 67 return | |
| 68 | |
| 69 if __name__ == '__main__': | |
| 70 results = DoMain(sys.argv[1:]) | |
| 71 print results | |
| OLD | NEW |