Create rules from a text file with delimited blocks of metadata and texts. As an example a file would contains one of more blocks such as this: \b ---------------------------------------- license_expression: lgpl-2.1 relevance: 100
(licenses_file, dump_to_file_on_errors=False)
| 270 | |
| 271 | @click.help_option("-h", "--help") |
| 272 | def cli(licenses_file, dump_to_file_on_errors=False): |
| 273 | """ |
| 274 | Create rules from a text file with delimited blocks of metadata and texts. |
| 275 | |
| 276 | As an example a file would contains one of more blocks such as this: |
| 277 | |
| 278 | \b |
| 279 | ---------------------------------------- |
| 280 | license_expression: lgpl-2.1 |
| 281 | relevance: 100 |
| 282 | is_license_notice: yes |
| 283 | --- |
| 284 | This program is free software; you can redistribute it and/or modify |
| 285 | it under the terms of the GNU Lesser General Public License |
| 286 | version 2.1 as published by the Free Software Foundation; |
| 287 | ---------------------------------------- |
| 288 | license_expression: lgpl-2.1 |
| 289 | relevance: 100 |
| 290 | is_license_reference: yes |
| 291 | --- |
| 292 | LGPL-2.1 |
| 293 | ---------------------------------------- |
| 294 | """ |
| 295 | |
| 296 | rules_data = load_data(licenses_file) |
| 297 | rule_by_tokens = all_rule_by_tokens() |
| 298 | |
| 299 | licenses_by_key = cache.get_licenses_db() |
| 300 | skinny_rules = [] |
| 301 | |
| 302 | for rdata in rules_data: |
| 303 | relevance = rdata.data.get("relevance") |
| 304 | rdata.data["has_stored_relevance"] = bool(relevance) |
| 305 | |
| 306 | license_expression = rdata.data.get("license_expression") |
| 307 | if license_expression: |
| 308 | rdata.data["license_expression"] = license_expression.lower().strip() |
| 309 | |
| 310 | minimum_coverage = rdata.data.get("minimum_coverage") |
| 311 | rdata.data["has_stored_minimum_coverage"] = bool(minimum_coverage) |
| 312 | |
| 313 | rl = models.BasicRule(text=rdata.text, **rdata.data) |
| 314 | skinny_rules.append(rl) |
| 315 | |
| 316 | # these will raise an exception and exit on errors |
| 317 | if not dump_to_file_on_errors: |
| 318 | models.validate_rules(rules=skinny_rules, licenses_by_key=licenses_by_key, with_text=True, thorough=True) |
| 319 | else: |
| 320 | validate_and_dump_rules(rules=skinny_rules, licenses_by_key=licenses_by_key, licenses_file_path=licenses_file) |
| 321 | |
| 322 | print() |
| 323 | for rule in skinny_rules: |
| 324 | |
| 325 | if rule.is_false_positive: |
| 326 | base_name = "false-positive" |
| 327 | elif rule.is_license_intro: |
| 328 | base_name = "license-intro" |
| 329 | elif rule.is_license_clue: |
no test coverage detected