Skip to content

Commit 593c019

Browse files
Add scancode license data dump as a console script #2738
* Removes CLI option `--dump-license-data` * Adds new console script `scancode-license-data --path PATH` * Updates CHANGELOG Signed-off-by: Ayan Sinha Mahapatra <[email protected]>
1 parent 9a7693a commit 593c019

File tree

6 files changed

+35
-30
lines changed

6 files changed

+35
-30
lines changed

CHANGELOG.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ License detection:
175175

176176
- See https://github.com/nexB/scancode-toolkit/issues/3049
177177

178-
- There is a new ``--get-license-data`` scancode command line option to export
178+
- There is a new console script ``scancode-license-data`` to export
179179
license data in JSON, YAML and HTML, with indexes and a static website for use
180180
in the licensedb web site. This becomes the API way to getr scancode license
181181
data.

setup-mini.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ packages =
147147
console_scripts =
148148
scancode = scancode.cli:scancode
149149
scancode-reindex-licenses = licensedcode.reindex:reindex_licenses
150+
scancode-license-data = licensedcode.license_db:dump_scancode_license_data
150151

151152
# These are configurations for ScanCode plugins as setuptools entry points.
152153
# Each plugin entry hast this form:

setup.cfg

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ packages =
147147
console_scripts =
148148
scancode = scancode.cli:scancode
149149
scancode-reindex-licenses = licensedcode.reindex:reindex_licenses
150+
scancode-license-data = licensedcode.license_db:dump_scancode_license_data
150151

151152
# These are configurations for ScanCode plugins as setuptools entry points.
152153
# Each plugin entry hast this form:

src/licensedcode/license_db.py

+31-8
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
from os.path import join
3232
from distutils.dir_util import copy_tree
3333

34+
import click
3435
import saneyaml
36+
37+
from commoncode.cliutils import MISC_GROUP
38+
from commoncode.cliutils import PluggableCommandLineOption
3539
from jinja2 import Environment, FileSystemLoader
3640
from licensedcode.models import load_licenses
3741
from licensedcode.models import licenses_data_dir
@@ -200,19 +204,38 @@ def generate(
200204
return count
201205

202206

203-
def dump_license_data(ctx, param, value):
207+
def scancode_license_data(path):
204208
"""
205209
Dump license data from scancode licenses to the directory ``value`` passed
206210
in from command line.
207211
208212
Dumps data in JSON, YAML and HTML formats and also dumps the .LICENSE file
209213
with the license text and the data as YAML frontmatter.
210214
"""
211-
if not value or ctx.resilient_parsing:
212-
return
213-
214-
import click
215-
click.secho(f'Dumping license data to: {value}', err=True)
216-
count = generate(build_location=value)
215+
click.secho(f'Dumping license data to: {path}', err=True)
216+
count = generate(build_location=path)
217217
click.secho(f'Done dumping #{count} licenses.', err=True)
218-
ctx.exit(0)
218+
219+
220+
@click.command(name='scancode-license-data')
221+
@click.option(
222+
'--path',
223+
type=click.Path(exists=False, readable=True, file_okay=False, resolve_path=True, path_type=str),
224+
metavar='DIR',
225+
help='Dump the license data in this directory in the LicenseDB format and exit. '
226+
'Creates the directory if it does not exist. ',
227+
help_group=MISC_GROUP,
228+
cls=PluggableCommandLineOption,
229+
)
230+
@click.help_option('-h', '--help')
231+
def dump_scancode_license_data(
232+
path,
233+
*args,
234+
**kwargs,
235+
):
236+
"""Reindex scancode licenses and exit"""
237+
scancode_license_data(path=path)
238+
239+
240+
if __name__ == '__main__':
241+
dump_scancode_license_data()

src/licensedcode/plugin_license.py

+1-16
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@
1212
from functools import partial
1313

1414
import attr
15-
import click
1615
from commoncode.cliutils import PluggableCommandLineOption
1716
from commoncode.cliutils import SCAN_GROUP
1817
from commoncode.cliutils import SCAN_OPTIONS_GROUP
19-
from commoncode.cliutils import MISC_GROUP
2018
from plugincode.scan import ScanPlugin
2119
from plugincode.scan import scan_impl
2220

@@ -33,7 +31,6 @@
3331
from licensedcode.detection import LicenseDetectionFromResult
3432
from licensedcode.detection import LicenseMatchFromResult
3533
from licensedcode.detection import UniqueDetection
36-
from licensedcode.license_db import dump_license_data
3734
from packagedcode.utils import combine_expressions
3835
from scancode.api import SCANCODE_LICENSEDB_URL
3936

@@ -121,19 +118,7 @@ class LicenseScanner(ScanPlugin):
121118
required_options=['license'],
122119
help='[EXPERIMENTAL] Detect unknown licenses. ',
123120
help_group=SCAN_OPTIONS_GROUP,
124-
),
125-
126-
# TODO: consider creating a separate comamnd line option exe instead
127-
PluggableCommandLineOption(
128-
('--dump-license-data',),
129-
type=click.Path(exists=False, readable=True, file_okay=False, resolve_path=True, path_type=str),
130-
metavar='DIR',
131-
callback=dump_license_data,
132-
help='Dump the license data in this directory in the LicenseDB format and exit. '
133-
'Creates the directory if it does not exist. ',
134-
help_group=MISC_GROUP,
135-
is_eager=True,
136-
),
121+
)
137122
]
138123

139124
def is_enabled(self, license, **kwargs): # NOQA

tests/scancode/data/help/help.txt

-5
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ Options:
148148
and including the starting directory. Use 0 for no
149149
scan depth limit.
150150

151-
miscellaneous:
152-
--dump-license-data DIR Dump the license data in this directory in the
153-
LicenseDB format and exit. Creates the directory if
154-
it does not exist.
155-
156151
documentation:
157152
-h, --help Show this message and exit.
158153
-A, --about Show information about ScanCode and licensing and exit.

0 commit comments

Comments
 (0)