Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 5 additions & 3 deletions fossology/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,16 @@ def __init__(self, url, token, version="v1"):
self.token = token
self.users = list()
self.folders = list()
self.version = version
self.api = f"{self.host}/api/{version}"
self.session = requests.Session()
self.session.headers.update({"Authorization": f"Bearer {self.token}"})
self.info = self.get_info()
self.health = self.get_health()
self.user = self.get_self()
self.user: User = self.get_self()
self.name = self.user.name
self.rootFolder = self.detail_folder(self.user.rootFolderId)
if self.user.rootFolderId is not None:
self.rootFolder = self.detail_folder(self.user.rootFolderId)
self.folders = self.list_folders()

logger.info(
Expand Down Expand Up @@ -186,7 +188,7 @@ def get_info(self) -> ApiInfo:
description = "Error while getting API info"
raise FossologyApiError(description, response)

def get_health(self) -> ApiInfo:
def get_health(self) -> HealthInfo:
"""Get health from the server

API endpoint: GET /health
Expand Down
8 changes: 7 additions & 1 deletion fossology/foss_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,13 @@ def start_workflow( # noqa: C901
logger.debug(f"job {job.id} is in state {job.status} ")
if job.status == "Processing":
logger.fatal(
f"job {job.id} is still in state {job.status}: Please try again later with --reuse_newest_upload --reuse_newest_job "
f"job {job.id} is still in state {job.status}: Please try again later with --reuse_newest_upload --reuse_newest_job "
)
ctx.exit(1)

if job.status == "Failed":
logger.fatal(
f"job {job.id} is {job.status}: Please try again later with --reuse_newest_upload --reuse_newest_job"
)
ctx.exit(1)

Expand Down
25 changes: 13 additions & 12 deletions fossology/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def item_info(
:rtype: FileInfo
:raises FossologyApiError: if the REST call failed
"""
response = self.session.get(
f"{self.api}/uploads/{upload.id}/item/{item_id}/info"
response = self.session.get( # type: ignore
f"{self.api}/uploads/{upload.id}/item/{item_id}/info" # type: ignore
)

if response.status_code == 200:
Expand Down Expand Up @@ -71,8 +71,8 @@ def item_copyrights(
:rtype: int
:raises FossologyApiError: if the REST call failed
"""
response = self.session.get(
f"{self.api}/uploads/{upload.id}/item/{item_id}/totalcopyrights?status={status.value}"
response = self.session.get( # type: ignore
f"{self.api}/uploads/{upload.id}/item/{item_id}/totalcopyrights?status={status.value}" # type: ignore
)

if response.status_code == 200:
Expand Down Expand Up @@ -103,8 +103,8 @@ def get_clearing_history(
:raises FossologyApiError: if the REST call failed
:raises AuthorizationError: if the REST call is not authorized
"""
response = self.session.get(
f"{self.api}/uploads/{upload.id}/item/{item_id}/clearing-history"
response = self.session.get( # type: ignore
f"{self.api}/uploads/{upload.id}/item/{item_id}/clearing-history" # type: ignore
)

if response.status_code == 200:
Expand Down Expand Up @@ -142,8 +142,9 @@ def get_prev_next(
if selection:
params["selection"] = selection

response = self.session.get(
f"{self.api}/uploads/{upload.id}/item/{item_id}/prev-next", params=params
response = self.session.get( # type: ignore
f"{self.api}/uploads/{upload.id}/item/{item_id}/prev-next", # type: ignore
params=params, # type: ignore
)

if response.status_code == 200:
Expand Down Expand Up @@ -174,8 +175,8 @@ def get_bulk_history(
:raises FossologyApiError: if the REST call failed
:raises AuthorizationError: if the REST call is not authorized
"""
response = self.session.get(
f"{self.api}/uploads/{upload.id}/item/{item_id}/bulk-history"
response = self.session.get( # type: ignore
f"{self.api}/uploads/{upload.id}/item/{item_id}/bulk-history" # type: ignore
)

if response.status_code == 200:
Expand Down Expand Up @@ -231,8 +232,8 @@ def schedule_bulk_scan(
:raises AuthorizationError: if the REST call is not authorized
"""
headers = {"Content-Type": "application/json"}
response = self.session.post(
f"{self.api}/uploads/{upload.id}/item/{item_id}/bulk-scan",
response = self.session.post( # type: ignore
f"{self.api}/uploads/{upload.id}/item/{item_id}/bulk-scan", # type: ignore
headers=headers,
data=json.dumps(spec),
)
Expand Down
16 changes: 9 additions & 7 deletions fossology/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def list_jobs(
params["upload"] = upload.id

jobs_list = list()
jobs_endpoint = f"{self.api}/jobs"
jobs_endpoint = f"{self.api}/jobs" # type: ignore
if all:
jobs_endpoint += "/all"
if all_pages:
Expand All @@ -61,7 +61,7 @@ def list_jobs(
x_total_pages = page
while page <= x_total_pages:
headers["page"] = str(page)
response = self.session.get(jobs_endpoint, params=params, headers=headers)
response = self.session.get(jobs_endpoint, params=params, headers=headers) # type: ignore
if response.status_code == 200:
for job in response.json():
jobs_list.append(Job.from_json(job))
Expand Down Expand Up @@ -96,7 +96,7 @@ def detail_job(self, job_id: int, wait: bool = False, timeout: int = 10) -> Job:
:rtype: Job
:raises FossologyApiError: if the REST call failed
"""
response = self.session.get(f"{self.api}/jobs/{job_id}")
response = self.session.get(f"{self.api}/jobs/{job_id}") # type: ignore
if wait:
if response.status_code == 200:
job = Job.from_json(response.json())
Expand All @@ -108,7 +108,7 @@ def detail_job(self, job_id: int, wait: bool = False, timeout: int = 10) -> Job:
raise FossologyApiError(description, response)
logger.debug(f"Waiting for job {job_id} to complete")
time.sleep(timeout)
response = self.session.get(f"{self.api}/jobs/{job_id}")
response = self.session.get(f"{self.api}/jobs/{job_id}") # type: ignore

if response.status_code == 200:
logger.debug(f"Got details for job {job_id}")
Expand All @@ -128,7 +128,7 @@ def jobs_history(self, upload: Upload) -> list[Job]:
:rtype: list of ShowJob
:raises FossologyApiError: if the REST call failed
"""
response = self.session.get(f"{self.api}/jobs/history?upload={upload.id}")
response = self.session.get(f"{self.api}/jobs/history?upload={upload.id}") # type: ignore
jobs_list = list()
if response.status_code == 200:
logger.debug(f"Got jobs for upload {upload.id}")
Expand Down Expand Up @@ -212,8 +212,10 @@ def schedule_jobs(
if group:
headers["groupName"] = group

response = self.session.post(
f"{self.api}/jobs", headers=headers, data=json.dumps(spec)
response = self.session.post( # type: ignore
f"{self.api}/jobs", # type: ignore
headers=headers,
data=json.dumps(spec), # type: ignore
)

if response.status_code == 201:
Expand Down
11 changes: 8 additions & 3 deletions fossology/obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __init__(
rootFolderId: int | None = None,
emailNotification: str | None = None,
default_group: str | None = None,
agents: dict | None = None,
agents: Agents | None = None,
**kwargs: dict,
):
self.id = id
Expand Down Expand Up @@ -252,9 +252,10 @@ def __init__(
self.additional_info = kwargs

def __str__(self):
len_copyright = len(self.copyright) if self.copyright else 0
return (
f"Licenses found by scanners: {self.scanner}, concluded licenses: {self.conclusion}, "
f"{len(self.copyright)} copyrights"
f"{len_copyright} copyrights"
)

@classmethod
Expand Down Expand Up @@ -699,7 +700,11 @@ def __init__(
self.additional_info = kwargs

def __str__(self):
return f"File {self.filepath} has {len(self.findings.conclusion)} license and {len(self.findings.copyright)}matches"
len_conclusion = (
len(self.findings.conclusion) if self.findings.conclusion else 0
)
len_copyright = len(self.findings.copyright) if self.findings.copyright else 0
return f"File {self.filepath} has {len_conclusion} license and {len_copyright} copyrights found."

@classmethod
def from_json(cls, json_dict):
Expand Down
8 changes: 5 additions & 3 deletions fossology/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def search(
x_total_pages = page
while page <= x_total_pages:
headers["page"] = str(page)
response = self.session.get(f"{self.api}/search", headers=headers)
response = self.session.get(f"{self.api}/search", headers=headers) # type: ignore

if response.status_code == 200:
for result in response.json():
Expand Down Expand Up @@ -161,8 +161,10 @@ def filesearch(
if group:
headers["groupName"] = group

response = self.session.post(
f"{self.api}/filesearch", headers=headers, json=filelist
response = self.session.post( # type: ignore
f"{self.api}/filesearch",
headers=headers,
json=filelist, # type: ignore
)

if response.status_code == 200:
Expand Down
Loading