OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/python | |
2 # Copyright 2014 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 """Generates the contents of an Cronet LICENSE file for the third-party code. | |
7 | |
8 It makes use of src/tools/licenses.py and the README.chromium files on which | |
9 it depends. Based on android_webview/tools/webview_licenses.py. | |
10 """ | |
11 | |
12 import optparse | |
13 import os | |
14 import sys | |
15 import textwrap | |
16 | |
17 REPOSITORY_ROOT = os.path.abspath(os.path.join( | |
18 os.path.dirname(__file__), '..', '..', '..')) | |
cbentzel
2014/05/19 19:11:01
You may want to get an infrastructure person or so
mef
2014/05/19 21:38:03
Sounds good. I've copied this pattern from webview
| |
19 | |
20 sys.path.append(os.path.join(REPOSITORY_ROOT, 'tools')) | |
21 import licenses | |
22 | |
23 def _ReadFile(path): | |
24 """Reads a file from disk. | |
25 Args: | |
26 path: The path of the file to read, relative to the root of the repository. | |
27 Returns: | |
28 The contents of the file as a string. | |
29 """ | |
30 | |
cbentzel
2014/05/19 19:11:01
Nit: extra newline
mef
2014/05/19 21:38:03
Done.
| |
31 return open(os.path.join(REPOSITORY_ROOT, path), 'rb').read() | |
32 | |
cbentzel
2014/05/19 19:11:01
Nit: Two blank lines required before top-level def
mef
2014/05/19 21:38:03
Done.
| |
33 def GenerateLicense(): | |
34 """Generates the contents of an Cronet LICENSE file for the third-party code. | |
35 Returns: | |
36 The contents of the LICENSE file. | |
37 """ | |
38 # TODO(mef): Generate list of third_party libraries using checkdeps. | |
39 third_party_dirs = [ | |
40 "libevent", | |
41 "ashmem", | |
42 "zlib", | |
43 "modp_b64", | |
44 "openssl" | |
45 ] | |
46 | |
47 # Start with Chromium's LICENSE file | |
48 content = [_ReadFile('LICENSE')] | |
49 | |
50 # Add necessary third_party. | |
51 for directory in sorted(third_party_dirs): | |
52 metadata = licenses.ParseDir("third_party/" + directory, REPOSITORY_ROOT, | |
53 require_license_file=True) | |
54 content.append("-" * 20) | |
55 content.append(directory) | |
56 content.append("-" * 20) | |
57 license_file = metadata['License File'] | |
58 if license_file and license_file != licenses.NOT_SHIPPED: | |
59 content.append(_ReadFile(license_file)) | |
60 | |
61 return '\n'.join(content) | |
62 | |
63 def main(): | |
64 class FormatterWithNewLines(optparse.IndentedHelpFormatter): | |
65 def format_description(self, description): | |
66 paras = description.split('\n') | |
67 formatted_paras = [textwrap.fill(para, self.width) for para in paras] | |
68 return '\n'.join(formatted_paras) + '\n' | |
69 | |
70 parser = optparse.OptionParser(formatter=FormatterWithNewLines(), | |
71 usage='%prog command [options]') | |
72 parser.description = (__doc__ + | |
73 '\nCommands:\n' \ | |
74 ' license [filename]\n' \ | |
75 ' Generate Cronet LICENSE to filename or stdout.\n') | |
76 (_, args) = parser.parse_args() | |
77 if len(args) < 1: | |
cbentzel
2014/05/19 19:11:01
Could just do
if not args:
parser.print_help()
mef
2014/05/19 21:38:03
Done.
| |
78 parser.print_help() | |
79 return 1 | |
80 | |
81 if args[0] == 'license': | |
82 if len(args) > 1: | |
83 print 'Saving license to %s' % args[1] | |
84 f = open(args[1], "w") | |
85 f.write(GenerateLicense()) | |
cbentzel
2014/05/19 19:11:01
Probably should do the f.close() in a finally: blo
mef
2014/05/19 21:38:03
Done.
| |
86 f.close() | |
87 else: | |
88 print GenerateLicense() | |
89 return 0 | |
90 | |
91 parser.print_help() | |
92 return 1 | |
93 | |
94 if __name__ == '__main__': | |
95 sys.exit(main()) | |
OLD | NEW |