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.
6 """Generates the contents of an Cronet LICENSE file for the third-party code.
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.
17 REPOSITORY_ROOT
= os
.path
.abspath(os
.path
.join(
18 os
.path
.dirname(__file__
), '..', '..', '..'))
20 sys
.path
.append(os
.path
.join(REPOSITORY_ROOT
, 'tools'))
24 """Reads a file from disk.
26 path: The path of the file to read, relative to the root of the repository.
28 The contents of the file as a string.
30 return open(os
.path
.join(REPOSITORY_ROOT
, path
), 'rb').read()
33 def GenerateLicense():
34 """Generates the contents of an Cronet LICENSE file for the third-party code.
36 The contents of the LICENSE file.
38 # TODO(mef): Generate list of third_party libraries using checkdeps.
47 # Start with Chromium's LICENSE file
48 content
= [_ReadFile('LICENSE')]
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
))
61 return '\n'.join(content
)
65 class FormatterWithNewLines(optparse
.IndentedHelpFormatter
):
66 def format_description(self
, description
):
67 paras
= description
.split('\n')
68 formatted_paras
= [textwrap
.fill(para
, self
.width
) for para
in paras
]
69 return '\n'.join(formatted_paras
) + '\n'
71 parser
= optparse
.OptionParser(formatter
=FormatterWithNewLines(),
72 usage
='%prog command [options]')
73 parser
.description
= (__doc__
+
75 ' license [filename]\n' \
76 ' Generate Cronet LICENSE to filename or stdout.\n')
77 (_
, args
) = parser
.parse_args()
82 if args
[0] == 'license':
84 print 'Saving license to %s' % args
[1]
85 f
= open(args
[1], "w")
87 f
.write(GenerateLicense())
91 print GenerateLicense()
98 if __name__
== '__main__':