|
31 | 31 | from os.path import join
|
32 | 32 | from distutils.dir_util import copy_tree
|
33 | 33 |
|
| 34 | +import click |
34 | 35 | import saneyaml
|
| 36 | + |
| 37 | +from commoncode.cliutils import MISC_GROUP |
| 38 | +from commoncode.cliutils import PluggableCommandLineOption |
35 | 39 | from jinja2 import Environment, FileSystemLoader
|
36 | 40 | from licensedcode.models import load_licenses
|
37 | 41 | from licensedcode.models import licenses_data_dir
|
@@ -200,19 +204,38 @@ def generate(
|
200 | 204 | return count
|
201 | 205 |
|
202 | 206 |
|
203 |
| -def dump_license_data(ctx, param, value): |
| 207 | +def scancode_license_data(path): |
204 | 208 | """
|
205 | 209 | Dump license data from scancode licenses to the directory ``value`` passed
|
206 | 210 | in from command line.
|
207 | 211 |
|
208 | 212 | Dumps data in JSON, YAML and HTML formats and also dumps the .LICENSE file
|
209 | 213 | with the license text and the data as YAML frontmatter.
|
210 | 214 | """
|
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) |
217 | 217 | 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() |
0 commit comments