|
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
|
@@ -126,13 +130,16 @@ def generate_details(output_path, environment, licenses, test=False):
|
126 | 130 |
|
127 | 131 | ``test`` is to generate a stable output for testing only
|
128 | 132 | """
|
| 133 | + from licensedcode.cache import get_cache |
| 134 | + include_builtin = get_cache().has_additional_licenses |
| 135 | + |
129 | 136 | if test:
|
130 | 137 | base_context_mapping = base_context_test
|
131 | 138 | else:
|
132 | 139 | base_context_mapping = base_context
|
133 | 140 | license_details_template = environment.get_template("license_details.html")
|
134 | 141 | for lic in licenses.values():
|
135 |
| - license_data = lic.to_dict(include_text=True) |
| 142 | + license_data = lic.to_dict(include_text=False, include_builtin=include_builtin) |
136 | 143 | html = license_details_template.render(
|
137 | 144 | **base_context_mapping,
|
138 | 145 | license=lic,
|
@@ -200,19 +207,40 @@ def generate(
|
200 | 207 | return count
|
201 | 208 |
|
202 | 209 |
|
203 |
| -def dump_license_data(ctx, param, value): |
| 210 | +def scancode_license_data(path): |
204 | 211 | """
|
205 |
| - Dump license data from scancode licenses to the directory ``value`` passed |
| 212 | + Dump license data from scancode licenses to the directory ``path`` passed |
206 | 213 | in from command line.
|
207 | 214 |
|
208 | 215 | Dumps data in JSON, YAML and HTML formats and also dumps the .LICENSE file
|
209 | 216 | with the license text and the data as YAML frontmatter.
|
210 | 217 | """
|
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) |
| 218 | + click.secho(f'Dumping license data to: {path}', err=True) |
| 219 | + count = generate(build_location=path) |
217 | 220 | click.secho(f'Done dumping #{count} licenses.', err=True)
|
218 |
| - ctx.exit(0) |
| 221 | + |
| 222 | + |
| 223 | +@click.command(name='scancode-license-data') |
| 224 | +@click.option( |
| 225 | + '--path', |
| 226 | + type=click.Path(exists=False, writable=True, file_okay=False, resolve_path=True, path_type=str), |
| 227 | + metavar='DIR', |
| 228 | + help='Dump the license data in this directory in the LicenseDB format and exit. ' |
| 229 | + 'Creates the directory if it does not exist. ', |
| 230 | + help_group=MISC_GROUP, |
| 231 | + cls=PluggableCommandLineOption, |
| 232 | +) |
| 233 | +@click.help_option('-h', '--help') |
| 234 | +def dump_scancode_license_data( |
| 235 | + path, |
| 236 | + *args, |
| 237 | + **kwargs, |
| 238 | +): |
| 239 | + """ |
| 240 | + Dump scancode license data in various formats, and the licenseDB static website at `path`. |
| 241 | + """ |
| 242 | + scancode_license_data(path=path) |
| 243 | + |
| 244 | + |
| 245 | +if __name__ == '__main__': |
| 246 | + dump_scancode_license_data() |
0 commit comments