1818# along with this program; if not, write to the Free Software Foundation,
1919# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2020#
21- """
21+ """Audits a SonarQube platform"""
2222
23- Audits a SonarQube platform
23+ from __future__ import annotations
2424
25- """
26-
27- import sys
2825import json
2926import csv
30- from typing import TextIO
27+ from typing import TextIO , Optional
3128from threading import Thread
3229from queue import Queue
3330from requests import RequestException
@@ -58,7 +55,7 @@ def _audit_sif(sysinfo: str, audit_settings: types.ConfigSettings) -> tuple[str,
5855 """Audits a SIF and return found problems"""
5956 log .info ("Auditing SIF file '%s'" , sysinfo )
6057 try :
61- with open (sysinfo , "r" , encoding = "utf-8" ) as f :
58+ with open (sysinfo , encoding = "utf-8" ) as f :
6259 sysinfo = json .loads (f .read ())
6360 except json .decoder .JSONDecodeError :
6461 log .critical ("File %s does not seem to be a legit JSON file" , sysinfo )
@@ -74,7 +71,7 @@ def _audit_sif(sysinfo: str, audit_settings: types.ConfigSettings) -> tuple[str,
7471
7572
7673def write_csv (queue : Queue [list [problem .Problem ]], fd : TextIO , settings : types .ConfigSettings ) -> None :
77- """Writes the CSV file of audit problems"""
74+ """Thread callback to write audit problems in a CSV file """
7875 server_id = settings .get ("SERVER_ID" , None )
7976 with_url = settings .get ("WITH_URL" , False )
8077 csvwriter = csv .writer (fd , delimiter = settings .get ("CSV_DELIMITER" , "," ))
@@ -93,9 +90,7 @@ def write_csv(queue: Queue[list[problem.Problem]], fd: TextIO, settings: types.C
9390
9491
9592def write_json (queue : Queue [list [problem .Problem ]], fd : TextIO , settings : types .ConfigSettings ) -> None :
96- """
97- Thread to write problems in a JSON file
98- """
93+ """Thread callback to write problems in a JSON file"""
9994 server_id = settings .get ("SERVER_ID" , None )
10095 with_url = settings .get ("WITH_URL" , False )
10196 comma = ""
@@ -114,7 +109,7 @@ def write_json(queue: Queue[list[problem.Problem]], fd: TextIO, settings: types.
114109
115110
116111def _audit_sq (
117- sq : platform .Platform , settings : types .ConfigSettings , what_to_audit : list [str ] = None , key_list : types .KeyList = None
112+ sq : platform .Platform , settings : types .ConfigSettings , what_to_audit : Optional [ list [str ] ] = None , key_list : types .KeyList = None
118113) -> list [problem .Problem ]:
119114 """Audits a SonarQube/Cloud platform"""
120115 everything = what_to_audit is None
@@ -179,9 +174,8 @@ def __parser_args(desc: str) -> object:
179174
180175def __check_keys_exist (key_regexp : list [str ], sq : platform .Platform , what : list [str ]) -> None :
181176 """Checks if project keys exist"""
182- if key_regexp and "projects" in what :
183- if len (component_helper .get_components (sq , "projects" , key_regexp )) == 0 :
184- raise options .ArgumentsError (f"No projects found with key matching regexp '{ key_regexp } '" )
177+ if key_regexp and "projects" in what and len (component_helper .get_components (sq , "projects" , key_regexp )) == 0 :
178+ raise options .ArgumentsError (f"No projects found with key matching regexp '{ key_regexp } '" )
185179
186180
187181def main () -> None :
0 commit comments