| 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 '''Generates the assets_list file from a directory.''' | |
| 8 | |
| 9 import argparse | |
| 10 import os | |
| 11 import sys | |
| 12 | |
| 13 def main(): | |
| 14 parser = argparse.ArgumentParser(usage='--dir <directory>') | |
| 15 | |
| 16 parser.add_argument('--dir', help='Directory read files from.', required=True) | |
| 17 | |
| 18 options, _ = parser.parse_known_args() | |
| 19 | |
| 20 if not os.path.exists(options.dir) or not os.path.isdir(options.dir): | |
| 21 print 'Directory does not exist, or path is not a directory', options.dir | |
| 22 return -1 | |
| 23 | |
| 24 root_dir = os.path.abspath(options.dir) | |
| 25 all_files = [] | |
| 26 for current_root, _, files in os.walk(options.dir): | |
| 27 current_root_absolute = os.path.abspath(current_root) | |
| 28 if len(current_root_absolute) < len(root_dir): | |
| 29 print 'unexpected directory', current_root_absolute | |
| 30 return -1 | |
| 31 rel_root = current_root_absolute[len(root_dir):] | |
| 32 if len(rel_root) and rel_root.startswith(os.sep): | |
| 33 rel_root = rel_root[len(os.sep):] | |
| 34 if len(rel_root) and not rel_root.endswith(os.sep): | |
| 35 rel_root += os.sep | |
| 36 all_files.extend([rel_root + f for f in files]) | |
| 37 | |
| 38 with open(os.path.join(options.dir, 'assets_list'), 'w') as f: | |
| 39 for a_file in all_files: | |
| 40 f.write(a_file + '\n') | |
| 41 | |
| 42 return 0 | |
| 43 | |
| 44 if __name__ == '__main__': | |
| 45 sys.exit(main()) | |
| 46 | |
| OLD | NEW |