Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 | |
| 3 """ | |
| 4 The goal of this script is to integrate IDL file path under the directory to tex t file. | |
|
bashi
2015/09/02 05:17:37
Please describe a typical usage here. Developers t
| |
| 5 """ | |
| 6 import os | |
| 7 import sys | |
| 8 | |
| 9 | |
| 10 def get_idl_files(path): | |
| 11 """ | |
|
bashi
2015/09/02 05:17:37
Please add one line summary as shiino-san suggeste
| |
| 12 Args: | |
| 13 path: directory path | |
| 14 Return: | |
| 15 str, absolute IDL file path | |
|
bashi
2015/09/02 05:17:37
This function returns a generator, not a str.
| |
| 16 """ | |
| 17 file_type = '.idl' | |
| 18 non_idl_set = ( | |
| 19 'InspectorInstrumentation.idl', | |
| 20 ) | |
|
bashi
2015/09/02 05:17:37
Let move |file_type| and |non_idl_set| out from th
| |
| 21 for dir_path, dir_names, file_names in os.walk(path): | |
| 22 for file_name in file_names: | |
| 23 if file_name.endswith(file_type) and file_name not in non_idl_set: | |
| 24 yield os.path.join(dir_path, file_name) | |
| 25 | |
| 26 | |
| 27 def main(args): | |
| 28 path = args[0] | |
| 29 filename = args[1] | |
| 30 f = open(filename, 'w') | |
|
bashi
2015/09/02 05:17:37
How about:
with open(filename, 'w') as f:
.
| |
| 31 for filepath in get_idl_files(path): | |
| 32 f.write(filepath + '\n') | |
| 33 f.close() | |
| 34 | |
| 35 | |
| 36 if __name__ == '__main__': | |
| 37 main(sys.argv[1:]) | |
| OLD | NEW |