Skip to content

Commit cf5243c

Browse files
author
shanko07
committed
Update notices report generation to check for 412 unfinished report contents
1 parent 54b0d8f commit cf5243c

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

examples/generate_notices_report_for_project_version.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
parser = argparse.ArgumentParser("A program to generate the notices file for a given project-version")
1919
parser.add_argument("project_name")
2020
parser.add_argument("version_name")
21-
22-
# TODO: Add the copyright checkbox option
23-
2421
parser.add_argument('-f', "--file_name_base", default="notices_report", help="Base file name to write the report data into. If the report format is TEXT a .zip file will be created, otherwise a .json file")
2522
parser.add_argument('-r', '--report_format', default='TEXT', choices=["JSON", "TEXT"], help="Report format - choices are TEXT or HTML")
2623
parser.add_argument('-c', '--include_copyright_info', action='store_true', help="Set this option to have additional copyright information from the Black Duck KB included in the notices file report.")
@@ -53,6 +50,12 @@ def download_report(location, file_name_base, retries=10):
5350
json.dump(response.json(), f, indent=3)
5451
logging.info("Successfully downloaded json file to {} for report {}".format(
5552
filename, report_id))
53+
elif response.status_code == 412 and response.json()['errorCode'] == '{report.main.read.unfinished.report.contents}':
54+
# failed to download, and report generation still in progress, wait and try again infinitely
55+
# TODO: is it possible for things to get stuck in this forever?
56+
logging.warning(f"Failed to retrieve report {report_id} for reason {response.json()['errorCode']}. Waiting 5 seconds then trying infinitely")
57+
time.sleep(5)
58+
download_report(location, file_name_base, retries)
5659
else:
5760
logging.warning("Failed to retrieve report {}".format(report_id))
5861
logging.warning("Probably not ready yet, waiting 5 seconds then retrying (remaining retries={}".format(retries))

0 commit comments

Comments
 (0)