Skip to content

Commit 818b9fb

Browse files
author
Glenn Snyder
committed
adding options to control retries and sleep time
1 parent 0835e46 commit 818b9fb

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

examples/generate_csv_reports_for_project_version.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
default="version,scans,components,vulnerabilities,source",
2121
help="Comma separated list (no spaces) of the reports to generate - version, scans, components, vulnerabilities, source, and cryptography reports (default: all, except cryptography")
2222
parser.add_argument('--format', default='CSV', choices=["CSV"], help="Report format - only CSV available for now")
23+
parser.add_argument('-t', '--tries', default=4, type=int, help="How many times to retry downloading the report, i.e. wait for the report to be generated")
24+
parser.add_argument('-s', '--sleep_time', default=5, type=int, help="The amount of time to sleep in-between (re-)tries to download the report")
2325

2426
args = parser.parse_args()
2527

@@ -33,27 +35,10 @@
3335
'source':'FILES'
3436
}
3537

36-
# def get_version_id(version_obj):
37-
# version_id = version_obj['_meta']['href'].split("/")[-1]
38-
# return version_id
39-
40-
# def generate_reports_json(version_obj, reports_str):
41-
# version_id = get_version_id(version_obj)
42-
# reports_l = reports_str.split(",")
43-
# categories = [version_name_map[r.lower()] for r in reports_l]
44-
# reports_json = {
45-
# 'categories': categories,
46-
# 'versionId': version_id,
47-
# 'reportType': 'VERSION',
48-
# 'reportFormat': 'CSV',
49-
# }
50-
# return json.dumps(reports_json)
51-
52-
# TODO: Promote this to the API
5338
class FailedReportDownload(Exception):
5439
pass
5540

56-
def download_report(location, filename, retries=4):
41+
def download_report(location, filename, retries=args.tries):
5742
report_id = location.split("/")[-1]
5843

5944
if retries:
@@ -66,7 +51,7 @@ def download_report(location, filename, retries=4):
6651
else:
6752
print("Failed to retrieve report {}".format(report_id))
6853
print("Probably not ready yet, waiting 5 seconds then retrying...")
69-
time.sleep(5)
54+
time.sleep(args.sleep_time)
7055
retries -= 1
7156
download_report(location, filename, retries)
7257
else:

0 commit comments

Comments
 (0)