Skip to content

Commit 9e29cdd

Browse files
authored
Merge pull request #1296 from okorach:cleanup-logs
Cleanup-logs
2 parents 1eca63c + d0310cf commit 9e29cdd

File tree

3 files changed

+6
-57
lines changed

3 files changed

+6
-57
lines changed

sonar/portfolios.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,8 @@ def get_list(endpoint: pf.Platform, key_list: types.KeyList = None, use_cache: b
625625
"""
626626
with _CLASS_LOCK:
627627
if key_list is None or len(key_list) == 0 or not use_cache:
628-
log.info("Listing portfolios")
628+
log.debug("Listing portfolios")
629629
object_list = search(endpoint=endpoint)
630-
log.info("List = %s", ", ".join(list(object_list.keys())))
631630
return object_list
632631
object_list = {}
633632
for key in util.csv_to_list(key_list):

sonar/rules.py

Lines changed: 2 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ def get_object(endpoint: platform.Platform, key: str) -> Optional[Rule]:
223223
return None
224224

225225

226-
def export_all(endpoint: platform.Platform, full: bool = False) -> types.ObjectJsonRepr:
226+
def export(endpoint: platform.Platform, export_settings: types.ConfigSettings, key_list: types.KeyList = None) -> types.ObjectJsonRepr:
227227
"""Returns a JSON export of all rules"""
228228
log.info("Exporting rules")
229+
full = export_settings.get("FULL_EXPORT", False)
229230
rule_list, other_rules, instantiated_rules, extended_rules = {}, {}, {}, {}
230231
for rule_key, rule in get_list(endpoint=endpoint).items():
231232
rule_export = rule.export(full)
@@ -251,57 +252,6 @@ def export_all(endpoint: platform.Platform, full: bool = False) -> types.ObjectJ
251252
return rule_list
252253

253254

254-
def export_instantiated(endpoint: platform.Platform, full: bool = False) -> Optional[types.ObjectJsonRepr]:
255-
"""Returns a JSON of all instantiated rules"""
256-
rule_list = {}
257-
for template_key in get_list(endpoint=endpoint, is_template="true"):
258-
for rule_key, rule in get_list(endpoint=endpoint, template_key=template_key).items():
259-
rule_list[rule_key] = rule.export(full)
260-
return rule_list if len(rule_list) > 0 else None
261-
262-
263-
def export_customized(endpoint: platform.Platform, full: bool = False) -> Optional[types.ObjectJsonRepr]:
264-
"""Returns a JSON export of all customized rules (custom tags or description added)"""
265-
rule_list = {}
266-
for rule_key, rule in get_list(endpoint=endpoint, is_template="false").items():
267-
if rule.tags is None and rule.custom_desc is None:
268-
continue
269-
if full:
270-
rule_list[rule_key] = rule.export(full)
271-
continue
272-
rule_list[rule_key] = {}
273-
if rule.tags:
274-
rule_list[rule_key]["tags"] = utilities.list_to_csv(rule.tags, ", ")
275-
if rule.custom_desc:
276-
rule_list[rule_key]["description"] = rule.custom_desc
277-
return rule_list if len(rule_list) > 0 else None
278-
279-
280-
def export_needed(endpoint: platform.Platform, instantiated: bool = True, extended: bool = True, full: bool = False) -> types.ObjectJsonRepr:
281-
"""Returns a JSON export selected / needed rules"""
282-
rule_list = {}
283-
if instantiated:
284-
rule_list["instantiated"] = export_instantiated(endpoint, full)
285-
if extended:
286-
rule_list["extended"] = export_customized(endpoint, full)
287-
return utilities.remove_nones(rule_list)
288-
289-
290-
def export(endpoint: platform.Platform, export_settings: types.ConfigSettings, key_list: types.KeyList = None) -> types.ObjectJsonRepr:
291-
"""Returns a dict of rules for export
292-
:param Platform endpoint: The SonarQube Platform object to connect to
293-
:param ConfigSettings export_settings: parameters to export
294-
:param KeyList key_list: Unused
295-
:return: a dict of rules with their JSON representation
296-
:rtype: ObjectJsonRepr
297-
"""
298-
log.info("Exporting rules")
299-
# if standard:
300-
return export_all(endpoint, export_settings["FULL_EXPORT"])
301-
# else:
302-
# return export_needed(endpoint, instantiated, extended, export_settings["FULL_EXPORT"])
303-
304-
305255
def import_config(endpoint: platform.Platform, config_data: types.ObjectJsonRepr, key_list: types.KeyList = None) -> bool:
306256
"""Imports a sonar-config configuration"""
307257
if "rules" not in config_data:

test/test_rules.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ def test_get_rule_cache() -> None:
153153

154154
def test_export_not_full() -> None:
155155
"""test_export_not_full"""
156-
rule_list = rules.export_all(endpoint=util.SQ, full=False)
156+
rule_list = rules.export(endpoint=util.SQ, export_settings={"FULL_EXPORT": False})
157157
assert len(rule_list["extended"]) > 0
158-
rule_list = rules.export_all(endpoint=util.SQ, full=True)
158+
rule_list = rules.export(endpoint=util.SQ, export_settings={"FULL_EXPORT": True})
159159
assert len(rule_list["extended"]) > 0
160160

161161

@@ -170,7 +170,7 @@ def test_get_nonexisting_rule() -> None:
170170

171171
def test_export_all() -> None:
172172
"""test_export_all"""
173-
rule_list = rules.export_all(endpoint=util.SQ, full=True)
173+
rule_list = rules.export(endpoint=util.SQ, export_settings={"FULL_EXPORT": True})
174174
if util.SQ.version() < (10, 0, 0) and util.SQ.edition() == "community":
175175
assert len(rule_list.get("standard", {})) > 2800
176176
else:

0 commit comments

Comments
 (0)