Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyharrison committed Jul 28, 2024
1 parent 8f8af7e commit 893e1f2
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 256 deletions.
2 changes: 1 addition & 1 deletion lib4sbom/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def _generate_cyclonedx(self, project_name: str, sbom_data: SBOMData) -> None:
parent = project_name
if "licenses" in sbom_data and len(sbom_data["licenses"]) > 0:
# Load user defined licences
print ("User defined licences available")
print("User defined licences available")
# Process list of files
if "files" in sbom_data:
# Process list of files
Expand Down
6 changes: 3 additions & 3 deletions lib4sbom/license.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def find_license_id(self, license):
return self.DEFAULT_LICENSE

def get_license_text(self, license_id):
license_text=""
license_text = ""
filename = f"{self.license_text_path}/{license_id}.txt"
# check filename exists
if os.path.exists(filename):
Expand All @@ -94,7 +94,7 @@ def get_license_name(self, license_id):
for lic in self.licenses["licenses"]:
if lic["licenseId"] == license_id:
return lic["name"]
return "" # License not found
return "" # License not found

def get_license_url(self, license_id):
# Assume that license_id is a valid SPDX id
Expand Down Expand Up @@ -193,7 +193,7 @@ def get_license_type(self, license):

def get_license_category(self, license_list):
# For each license
if license_list is None or len (license_list) == 0:
if license_list is None or len(license_list) == 0:
return "UNKNOWN"
license_category = {}
for license in license_list:
Expand Down
8 changes: 6 additions & 2 deletions lib4sbom/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ def parse_file(self, filename: str) -> None:
self.licenses,
) = self.parser.parse(filename)
# but if no packages or files found, assume it must be CycloneDX
if len(self.packages) == 0 and len(self.files) == 0 and len(self.vulnerabilities) == 0:
if (
len(self.packages) == 0
and len(self.files) == 0
and len(self.vulnerabilities) == 0
):
self.sbom_type = "cyclonedx"
self.parser = CycloneDXParser()
(
Expand Down Expand Up @@ -200,4 +204,4 @@ def get_licenses(self) -> List[Dict]:
licenses : list of SBOMLicense objects
"""
return self.sbom.get_licenses()
return self.sbom.get_licenses()
2 changes: 1 addition & 1 deletion lib4sbom/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2024 Anthony Harrison
# SPDX-License-Identifier: Apache-2.0

VERSION: str = "0.7.1"
VERSION: str = "0.7.2"
159 changes: 0 additions & 159 deletions test.json

This file was deleted.

76 changes: 0 additions & 76 deletions test.spdx.json

This file was deleted.

12 changes: 10 additions & 2 deletions test/test_cyclonedx_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import pytest

from lib4sbom.cyclonedx.cyclonedx_parser import CycloneDXParser as test_module
Expand All @@ -23,9 +24,16 @@ def test_parse_cyclonedx_multiple_licenses_json(self):
test_parser = test_module()
result = test_parser.parse(self.get_test_filepath("testapp2.json"))

cyclonedx_document, files, packages, relationships, vulnerabilities, services = result
(
cyclonedx_document,
files,
packages,
relationships,
vulnerabilities,
services,
) = result
multi_license = None
for (p, v) in packages:
for p, v in packages:
if p == "multi-license":
multi_license = packages[(p, v)]
break
Expand Down
25 changes: 13 additions & 12 deletions tools/get_license_text.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
import os
import json
import os

import requests

license_dir, filename = os.path.split(__file__)
# Bodge the pathname
license_path = os.path.join(license_dir, "../lib4sbom/license_data", "spdx_licenses.json")
license_path = os.path.join(
license_dir, "../lib4sbom/license_data", "spdx_licenses.json"
)
licfile = open(license_path, "r", encoding="utf-8")
licenses = json.load(licfile)

# Process each licence
for lic in licenses["licenses"]:
#print (lic)
# print (lic)
id = lic["licenseId"].lower()
name = lic["name"].lower()
url = lic["detailsUrl"]
print (f"{name} - {id}: {url}")
print(f"{name} - {id}: {url}")

filename=f"{id}.txt"
filename = f"{id}.txt"
file_path = os.path.join(license_dir, "../lib4sbom/license_data/text", filename)
# Get text
try:
license_text = requests.get(url).json()
if license_text.get("licenseText") is not None:
#text=license_text["licenseText"]
html=license_text["licenseTextHtml"]
#print (html)
# text=license_text["licenseText"]
html = license_text["licenseTextHtml"]
# print (html)
# Create file
with open(file_path,"w") as f:
with open(file_path, "w") as f:
f.write(html)
except requests.exceptions.RequestException:
print (f"Unable to find license text for {name}")


print(f"Unable to find license text for {name}")

0 comments on commit 893e1f2

Please sign in to comment.