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.
7 """Generates the assets_list file from a directory."""
14 parser
= argparse
.ArgumentParser(usage
="--dir <directory>")
16 parser
.add_argument('--dir', help='Directory read files from.', required
=True)
18 options
, _
= parser
.parse_known_args()
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
24 root_dir
= os
.path
.abspath(options
.dir)
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
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
):
36 all_files
.extend([rel_root
+ f
for f
in files
])
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')
44 if __name__
== '__main__':