Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path handling #124

Merged
merged 3 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ def validate(self,
problems.append("File error", "General", "General", f"File path is empty", filePath)
return False, problems

if not os.path.isfile(filePath):
logger.error(f"File does not exist {filePath}")
problems.append("File error", "General", "General", f"File does not exits ({filePath})", filePath)
return False, problems

file = os.path.basename(filePath)
dir_name = os.path.dirname(filePath)
logger.debug(f"File path is {dir_name}, filename is {file}")
Expand Down Expand Up @@ -381,6 +386,7 @@ def __ntiaErrorLogNew(self, components, problems, doc, problemText, file):
def referred_yocto_all(self, doc: Document, dir_name: str):
logger.debug("In Yocto all")
documents = []
ref_base = ""
if doc.creation_info.document_namespace:
# http://spdx.org/spdxdoc/recipe-serviceuser-user-7abdc33d-d61f-549c-a5f7-05ffbd5118e8
result = re.search("^(.*/)[\w-]+$", doc.creation_info.document_namespace)
Expand All @@ -399,15 +405,18 @@ def referred_yocto_all(self, doc: Document, dir_name: str):
result = re.search("([\w-]+)-[\w-]{8}(-[\w-]{4}){3}-[\w-]{12}$", doc_location)
if result:
doc_location = result.group(1)

doc_location = f"{dir_name}/{doc_location}.spdx.json"
if dir_name == "":
doc_location = f"{doc_location}.spdx.json"
else:
doc_location = f"{dir_name}/{doc_location}.spdx.json"
logger.debug(f"Document location is: {doc_location}")
documents.append(doc_location)
return documents

def referred_yocto_contains_only(self, doc: Document, dir_name: str):
logger.debug("In Yocto contains only")
documents = []
ref_base = ""
if doc.creation_info.document_namespace:
# http://spdx.org/spdxdoc/recipe-serviceuser-user-7abdc33d-d61f-549c-a5f7-05ffbd5118e8
result = re.search("^(.*/)[\w-]+$", doc.creation_info.document_namespace)
Expand All @@ -426,7 +435,10 @@ def referred_yocto_contains_only(self, doc: Document, dir_name: str):
result = re.search("([\w-]+)-[\w-]{8}(-[\w-]{4}){3}-[\w-]{12}$", doc_location)
if result:
doc_location = result.group(1)
doc_location = f"{dir_name}/{doc_location}.spdx.json"
if dir_name == "":
doc_location = f"{doc_location}.spdx.json"
else:
doc_location = f"{dir_name}/{doc_location}.spdx.json"
logger.debug(f"Document location is: {doc_location}, ref: {ref.document_ref_id}")
external_refs[ref.document_ref_id] = doc_location
if doc.relationships:
Expand Down