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

Side by Side Diff: build/copy_test_data.py

Issue 10790008: Adds a way to specify test data files for unittests. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Updates. Created 8 years, 5 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
« no previous file with comments | « build/copy_test_data.gypi ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
pkl (ping after 24h if needed) 2012/07/16 17:15:34 google3 python files do *not* require shebang line
2 # Copyright (c) 2012 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 """Copies test data files into an iOS app bundle."""
7
8 import optparse
9 import os
10 import shutil
11 import sys
12
13 class WrongNumberOfArgumentsException(Exception):
14 pass
15
16 def ExpandFilesForPath(path):
17 output = []
18 # Files get returned without modification.
19 if not os.path.isdir(path):
20 output.append(path)
21 return output
22
23 # Directories get recursively expanded.
24 contents = os.listdir(path)
25 for item in contents:
26 full_path = os.path.join(path, item)
27 output.extend(ExpandFilesForPath(full_path))
28 return output
29
30 def CalcInputs(inputs):
31 # Inputs is a list of possibly-space-separated strings. Break apart the list
pkl (ping after 24h if needed) 2012/07/16 17:15:34 Use triple-" for function doc strings.
32 # and tokenize the string.
33 output = []
34 for input in inputs:
35 tokens = input.split()
36 for token in tokens:
37 output.extend(ExpandFilesForPath(token))
38 return output
39
40 def CopyFiles(relative_filenames, output_basedir):
41 for file in relative_filenames:
42 relative_dirname = os.path.dirname(file)
pkl (ping after 24h if needed) 2012/07/16 17:15:34 indent 2
43 output_dir = os.path.join(output_basedir, relative_dirname)
44 if not os.path.exists(output_dir):
45 os.makedirs(output_dir)
46 output_filename = os.path.join(output_basedir, file)
47 shutil.copy(file, output_filename)
48
49 def DoMain(argv):
50 parser = optparse.OptionParser()
51 usage = 'Usage: %prog -o <output_dir> [--inputs] [--outputs] <input_files>'
52 parser.set_usage(usage)
53 parser.add_option('-o', dest='output_dir')
54 parser.add_option('--inputs', action='store_true', dest='list_inputs')
55 parser.add_option('--outputs', action='store_true', dest='list_outputs')
56 options, arglist = parser.parse_args(argv)
57
58 if len(arglist) == 0:
59 raise WrongNumberOfArgumentsException("<input_files> required.")
pkl (ping after 24h if needed) 2012/07/16 17:15:34 single quote strings.
60
61 files_to_copy = CalcInputs(arglist)
62 if options.list_inputs:
63 return '\n'.join(files_to_copy)
64
65 if not options.output_dir:
66 raise WrongNumberOfArgumentsException("-o required.")
67
68 if options.list_outputs:
69 outputs = [os.path.join(options.output_dir, x) for x in files_to_copy]
70 return '\n'.join(outputs)
71
72 CopyFiles(files_to_copy, options.output_dir)
73 return 0
74
75 def main(argv):
76 try:
77 result = DoMain(argv[1:])
78 except WrongNumberOfArguments, e:
79 print >>sys.stderr, e
80 return 1
81 print result
82 return 0
83
84 if __name__ == '__main__':
85 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « build/copy_test_data.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698