Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(599)

Side by Side Diff: mojo/public/tools/bindings/gen_data_files_list.py

Issue 2745293005: Moving mojo/validation test into LayoutTests (Closed)
Patch Set: added sources to script action Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2017 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 """Generates a list of all files in a directory
yzshen1 2017/03/27 00:29:17 style nit: trailing ".", please.
5
6 This script takes in a directory and an output file name as input.
7 It then reads the directory and creates a list of all file names
8 in that directory. The list is written to the output file.
9 There is also an option to pass in '-p' or '--pattern'
10 which will check each file name against a regular expression
11 pattern that is passed in. Only files which match the regex
12 will be written to the list.
13 """
14
15 from optparse import OptionParser
16 from os import listdir
17 import re
18 import sys
19
20 def main():
21 parser = OptionParser()
22 parser.add_option('-d', '--directory', help='Read files from DIRECTORY')
23 parser.add_option('-o', '--output', help='Write list to FILE')
24 parser.add_option('-p',
25 '--pattern',
26 help='Only reads files that name matches PATTERN',
27 default=".")
28 (options, _) = parser.parse_args()
29 pattern = re.compile(options.pattern)
30 files = [ f for f in listdir(options.directory) if pattern.match(f)]
31 out = file(options.output, 'w')
32 with out:
33 for f in files:
34 out.write(f + '\n')
35
36 if __name__ == '__main__':
37 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698