Skip to content
Snippets Groups Projects
Commit e6ab1646 authored by Alberto Pianon's avatar Alberto Pianon
Browse files

custom fossy upload function

to workaround issue https://github.com/fossology/fossology/issues/2684



Signed-off-by: default avatarAlberto Pianon <alberto@pianon.eu>
parent 192f18e0
No related branches found
No related tags found
No related merge requests found
Pipeline #45743 failed
......@@ -148,14 +148,68 @@ class FossyWrapper:
def upload(self, filename: str, folder: Folder, description: str = '') -> Upload:
logger.info(f"[{filename}] Uploading the file to Fossology")
try:
upload = self.fossology.upload_file(
folder,
file=filename,
ignore_scm=True,
description=description,
wait_time=60*4
headers = {
"folderId": str(folder.id),
"uploadDescription": description,
"uploadType": "file",
"ignoreScm": True,
}
data = {
"scanOptions": {
"analysis": {
"bucket": False,
"copyright_email_author": False,
"ecc": False,
"keyword": False,
"mime": False,
"monk": False,
"nomos": False,
"ojo": False,
"package": False,
"reso": False,
"heritage": False,
},
"scancode": {
"license": False,
"copyright": False,
"email": False,
"url": False,
}
}
}
while True:
res = self.fossology.session.post(
f"{self.fossology.api}/uploads",
headers=headers,
data=data,
files={"fileInput": open(filename, "rb")}
)
if res.status_code not in [200, 201]:
raise FossyWrapperException(
"Can't upload package to fossology: "
+ res.text
)
upload_id = res.json()["message"]
sleep(30)
jobs = self.fossology,session.get(
f"{self.fossology.api}/jobs/history?upload={upload_id}"
)
for j in jobs:
for jq in j["jobQueue"]:
if jq["jobQueueType"] == "ununpack" and jq["status"] == "Failed":
ununpack_failed = True
break
else:
ununpack_failed = False
if ununpack_failed:
break
if not ununpack_failed:
break
logger.info("Ununpack failed, restarting scheduler and trying again")
self.restart_fossology_server()
try:
upload = self.fossology.detail_upload(upload_id, wait_time=60*4)
except RetryError:
raise FossyWrapperException(
"Can't upload package to fossology. Is fossology scheduler running?"
......@@ -327,7 +381,7 @@ class FossyWrapper:
"""convert json to old 1.0.16 API format, for backwards compatibility"""
new_json.pop("assignee", None)
return new_json # not necessary, it is already passed by reference, but
# it shouldn't harm
# it shouldn't harm
def get_summary(self, upload: Upload) -> Any:
res = self.fossology.session.get(f"{self.fossology.api}/uploads/{upload.id}/summary")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment