Skip to content

Commit

Permalink
Fix linting issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h-abdelsalam committed Sep 3, 2024
1 parent 9892b86 commit 17eef9b
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions scripts/list-tasks.gmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ def list_tasks(gmp: Gmp, args: Namespace) -> None:
response_xml = gmp.get_tasks(details=True, filter_string="rows=-1")
tasks_xml = response_xml.xpath("task")

heading = ["#", "Name", "Id", "Target", "Scanner", "Scan Order", "Severity", "Average Duration", "Last Scan Duration (hours)"]
heading = [
"#",
"Name",
"Id",
"Target",
"Scanner",
"Scan Order",
"Severity",
"Average Duration",
"Last Scan Duration (hours)",
]

rows = []
numberRows = 0
Expand All @@ -33,19 +43,37 @@ def list_tasks(gmp: Gmp, args: Namespace) -> None:
severity = "".join(task.xpath("last_report/report/severity/text()"))
order = "".join(task.xpath("hosts_ordering/text()"))
average_duration = "".join(task.xpath("average_duration/text()"))
average_duration_int = 0 if not average_duration else int(average_duration)
average_duration_int = (
0 if not average_duration else int(average_duration)
)
average_duration_hours = f"{average_duration_int / 3600:.2f}"
scan_start_iso = "".join(task.xpath("last_report/report/scan_start/text()"))
scan_start_iso = "".join(
task.xpath("last_report/report/scan_start/text()")
)
scan_end_iso = "".join(task.xpath("last_report/report/scan_end/text()"))
if not scan_start_iso or not scan_end_iso:
duration_hours = ""
else:
scan_start_time = datetime.fromisoformat(scan_start_iso.replace('Z', '+00:00'))
scan_end_time = datetime.fromisoformat(scan_end_iso.replace('Z', '+00:00'))
scan_start_time = datetime.fromisoformat(
scan_start_iso.replace("Z", "+00:00")
)
scan_end_time = datetime.fromisoformat(
scan_end_iso.replace("Z", "+00:00")
)
duration = scan_end_time - scan_start_time
duration_hours = f"{duration.total_seconds() / 3600:.2f}"
rows.append(
[rowNumber, name, task_id, targetname, scanner, order, severity, average_duration_hours, duration_hours]
[
rowNumber,
name,
task_id,
targetname,
scanner,
order,
severity,
average_duration_hours,
duration_hours,
]
)

print(Table(heading=heading, rows=rows))
Expand All @@ -57,5 +85,6 @@ def main(gmp: Gmp, args: Namespace) -> None:

list_tasks(gmp, args)

Check warning on line 86 in scripts/list-tasks.gmp.py

View check run for this annotation

Codecov / codecov/patch

scripts/list-tasks.gmp.py#L86

Added line #L86 was not covered by tests


if __name__ == "__gmp__":
main(gmp, args)

0 comments on commit 17eef9b

Please sign in to comment.