Skip to content

Commit 03748ae

Browse files
committed
#396 - add option --android to create MODULE_LICENSE and NOTICE
* Create empty MODULE_LICENSE_XXX based on the license key * Create NOTICE with the ccontext from copyright, notice file and license file * Update copyright date * Update some doc The test code has not been updated and expect some tests will fail
1 parent a1c18fe commit 03748ae

File tree

6 files changed

+59
-9
lines changed

6 files changed

+59
-9
lines changed

NOTICE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2013-2019 nexB Inc. http://www.nexb.com/ - All rights reserved.
1+
Copyright (c) 2013-2020 nexB Inc. http://www.nexb.com/ - All rights reserved.
22
Licensed under the Apache License, Version 2.0 (the "License");
33
you may not use this file except in compliance with the License.
44
You may obtain a copy of the License at

REFERENCE.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ gen
151151

152152
::
153153

154+
--android Generate MODULE_LICENSE_XXX (XXX will be
155+
replaced by license key) and NOTICE as the same
156+
design as from Android.
157+
154158
--fetch-license api_url api_key Fetch licenses data from DejaCode License
155159
Library and create <license>.LICENSE
156160
side-by-side with the generated .ABOUT file.
@@ -178,6 +182,17 @@ Options
178182

179183
::
180184

185+
--android
186+
187+
Create an empty file named `MODULE_LICENSE_XXX` where `XXX` is the license
188+
key and create a NOTICE file which these two files follow the design from
189+
Android Open Source Project.
190+
191+
The input **must** have the license key information as this is needed to
192+
create the empty MODULE_LICENSE_XXX
193+
194+
$ about gen --android LOCATION OUTPUT
195+
181196
--fetch-license
182197

183198
Fetch licenses text from a DejaCode API. and create <license>.LICENSE side-by-side

about.ABOUT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ about_resource: .
22
name: AboutCode-toolkit
33
version: 4.0.1
44
author: Jillian Daguil, Chin Yeung Li, Philippe Ombredanne, Thomas Druez
5-
copyright: Copyright (c) 2013-2019 nexB Inc.
5+
copyright: Copyright (c) 2013-2020 nexB Inc.
66
description: |
77
AboutCode Toolkit is a tool to process ABOUT files. An ABOUT file
88
provides a simple way to document the provenance (origin and license)

src/attributecode/cmd.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: utf8 -*-
33

44
# ============================================================================
5-
# Copyright (c) 2013-2019 nexB Inc. http://www.nexb.com/ - All rights reserved.
5+
# Copyright (c) 2013-2020 nexB Inc. http://www.nexb.com/ - All rights reserved.
66
# Licensed under the Apache License, Version 2.0 (the "License");
77
# you may not use this file except in compliance with the License.
88
# You may obtain a copy of the License at
@@ -46,7 +46,7 @@
4646

4747

4848
__copyright__ = """
49-
Copyright (c) 2013-2019 nexB Inc and others. All rights reserved.
49+
Copyright (c) 2013-2020 nexB Inc and others. All rights reserved.
5050
Licensed under the Apache License, Version 2.0 (the "License");
5151
you may not use this file except in compliance with the License.
5252
You may obtain a copy of the License at
@@ -210,6 +210,11 @@ def inventory(location, output, format, quiet, verbose): # NOQA
210210
metavar='OUTPUT',
211211
type=click.Path(exists=True, file_okay=False, writable=True, resolve_path=True))
212212

213+
@click.option('--android',
214+
is_flag=True,
215+
help='Generate MODULE_LICENSE_XXX (XXX will be replaced by license key) and NOTICE '
216+
'as the same design as from Android.')
217+
213218
# FIXME: the CLI UX should be improved with two separate options for API key and URL
214219
@click.option('--fetch-license',
215220
nargs=2,
@@ -233,7 +238,7 @@ def inventory(location, output, format, quiet, verbose): # NOQA
233238

234239
@click.help_option('-h', '--help')
235240

236-
def gen(location, output, fetch_license, reference, quiet, verbose):
241+
def gen(location, output, android, fetch_license, reference, quiet, verbose):
237242
"""
238243
Generate .ABOUT files in OUTPUT from an inventory of .ABOUT files at LOCATION.
239244
@@ -245,12 +250,14 @@ def gen(location, output, fetch_license, reference, quiet, verbose):
245250
print_version()
246251
click.echo('Generating .ABOUT files...')
247252

253+
#FIXME: This should be checked in the `click`
248254
if not location.endswith(('.csv', '.json',)):
249255
raise click.UsageError('ERROR: Invalid input file extension: must be one .csv or .json.')
250256

251257
errors, abouts = generate_about_files(
252258
location=location,
253259
base_dir=output,
260+
android=android,
254261
reference_dir=reference,
255262
fetch_license=fetch_license,
256263
)

src/attributecode/gen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def load_inventory(location, base_dir, reference_dir=None):
211211
def update_about_resource(self):
212212
pass
213213

214-
def generate(location, base_dir, reference_dir=None, fetch_license=False):
214+
def generate(location, base_dir, android=None, reference_dir=None, fetch_license=False):
215215
"""
216216
Load ABOUT data from a CSV inventory at `location`. Write ABOUT files to
217217
base_dir. Return errors and about objects.
@@ -311,7 +311,7 @@ def generate(location, base_dir, reference_dir=None, fetch_license=False):
311311
if about.license_name.value:
312312
about.license_name.present = True
313313

314-
about.dump(dump_loc)
314+
about.dump(dump_loc, android)
315315

316316
for e in not_exist_errors:
317317
errors.append(Error(INFO, e))

src/attributecode/model.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ def validate_fields(fields, about_file_path, running_inventory, base_dir,
677677
def validate_field_name(name):
678678
if not is_valid_name(name):
679679
msg = ('Field name: %(name)r contains illegal name characters: '
680-
'0 to 9, a to z, A to Z and _.')
680+
'0 to 9, a to z, A to Z and _. (or empty spaces)')
681681
return Error(CRITICAL, msg % locals())
682682

683683

@@ -1066,7 +1066,7 @@ def dumps(self):
10661066

10671067
return saneyaml.dump(data)
10681068

1069-
def dump(self, location):
1069+
def dump(self, location, android):
10701070
"""
10711071
Write formatted ABOUT representation of self to location.
10721072
"""
@@ -1087,6 +1087,34 @@ def dump(self, location):
10871087
if on_windows:
10881088
about_file_path = add_unc(about_file_path)
10891089

1090+
if android:
1091+
for lic_key in self.license_key.value:
1092+
# Make uppercase and with dash and spaces and dots replaced by underscore
1093+
# just to look similar and consistent.
1094+
name = 'MODULE_LICENSE_' + lic_key.replace('.', '_').replace('-', '_').replace(' ', '_').upper()
1095+
module_lic_path = os.path.join(os.path.dirname(about_file_path), name)
1096+
# Create an empty MODULE_LICESE_XXX file
1097+
open(module_lic_path, 'a').close()
1098+
1099+
# Create NOTICE file with the combination context of copyright,
1100+
# notice_file and license_file
1101+
notice_path = os.path.join(os.path.dirname(about_file_path), 'NOTICE')
1102+
notice_context = ''
1103+
if self.copyright.value:
1104+
notice_context += self.copyright.value
1105+
if self.notice_file.value:
1106+
notice_file_dict = self.notice_file.value
1107+
notice_file_key = notice_file_dict.keys()
1108+
for key in notice_file_key:
1109+
notice_context += '\n\n' + notice_file_dict[key]
1110+
if self.license_file.value:
1111+
lic_file_dict = self.license_file.value
1112+
lic_file_key = lic_file_dict.keys()
1113+
for key in lic_file_key:
1114+
notice_context += '\n\n' + lic_file_dict[key]
1115+
with io.open(notice_path, mode='w', encoding='utf-8') as dumped:
1116+
dumped.write(notice_context)
1117+
10901118
with io.open(about_file_path, mode='w', encoding='utf-8') as dumped:
10911119
dumped.write(genereated_tk_version)
10921120
dumped.write(self.dumps())

0 commit comments

Comments
 (0)