Write Licenses/Rules from scancode into a CSV file with all details. Output can be optionally filtered by category/license-key.
(licenses, rules, category, license_key, with_text)
| 173 | ) |
| 174 | @click.help_option("-h", "--help") |
| 175 | def cli(licenses, rules, category, license_key, with_text): |
| 176 | """ |
| 177 | Write Licenses/Rules from scancode into a CSV file with all details. |
| 178 | Output can be optionally filtered by category/license-key. |
| 179 | """ |
| 180 | licenses_output = [] |
| 181 | rules_output = [] |
| 182 | |
| 183 | licenses_data = load_licenses() |
| 184 | |
| 185 | if licenses: |
| 186 | for lic in licenses_data.values(): |
| 187 | license_data = lic.to_dict() |
| 188 | if with_text: |
| 189 | license_data["text"] = lic.text[:200] |
| 190 | license_data["is_unknown"] = lic.is_unknown |
| 191 | license_data["length"] = len(lic.text) |
| 192 | license_data["reference_url"] = SCANCODE_LICENSEDB_URL.format(lic.key) |
| 193 | licenses_output.append(license_data) |
| 194 | |
| 195 | if category: |
| 196 | licenses_output = filter_by_attribute( |
| 197 | data=licenses_output, attribute="category", required_key=category |
| 198 | ) |
| 199 | |
| 200 | if license_key: |
| 201 | licenses_output = filter_by_attribute( |
| 202 | data=licenses_output, |
| 203 | attribute="key", |
| 204 | required_key=license_key, |
| 205 | ) |
| 206 | |
| 207 | licenses_output = flatten_output(data=licenses_output) |
| 208 | write_data_to_csv(data=licenses_output, output_csv=licenses, fieldnames=LICENSES_FIELDNAMES) |
| 209 | |
| 210 | if rules: |
| 211 | rules_data = list(load_rules()) |
| 212 | for rule in rules_data: |
| 213 | rule_data = rule.to_dict() |
| 214 | rule_data["identifier"] = rule.identifier |
| 215 | rule_data["referenced_filenames"] = rule.referenced_filenames |
| 216 | if with_text: |
| 217 | rule_data["text"] = rule.text[:200] |
| 218 | rule_data["has_unknown"] = rule.has_unknown |
| 219 | rule_data["length"] = len(rule.text) |
| 220 | try: |
| 221 | rule_data["category"] = licenses_data[rule_data["license_expression"]].category |
| 222 | except KeyError: |
| 223 | pass |
| 224 | rules_output.append(rule_data) |
| 225 | |
| 226 | if category: |
| 227 | rules_output = filter_by_attribute( |
| 228 | data=rules_output, |
| 229 | attribute="category", |
| 230 | required_key=category, |
| 231 | ) |
| 232 |
no test coverage detected