@@ -104,6 +104,15 @@ def __parse_args(desc):
104104 return args
105105
106106
107+ def __write_export (config : dict [str , str ], file : str , format : str ) -> None :
108+ """Writes the configuration in file"""
109+ with utilities .open_file (file ) as fd :
110+ if format == "yaml" :
111+ print (yaml .dump (config ), file = fd )
112+ else :
113+ print (utilities .json_dump (config ), file = fd )
114+
115+
107116def __export_config (endpoint : platform .Platform , what : list [str ], ** kwargs ) -> None :
108117 """Exports a platform configuration in a JSON file"""
109118 export_settings = {
@@ -119,15 +128,12 @@ def __export_config(endpoint: platform.Platform, what: list[str], **kwargs) -> N
119128
120129 log .info ("Exporting configuration from %s" , kwargs [options .URL ])
121130 key_list = kwargs [options .KEYS ]
122- sq_settings = {}
123- sq_settings [__JSON_KEY_PLATFORM ] = endpoint .basics ()
131+ sq_settings = {__JSON_KEY_PLATFORM : endpoint .basics ()}
124132 if options .WHAT_SETTINGS in what :
125133 sq_settings [__JSON_KEY_SETTINGS ] = endpoint .export (export_settings = export_settings )
126- if options .WHAT_RULES in what :
134+ if options .WHAT_RULES in what or options . WHAT_PROFILES in what :
127135 sq_settings [__JSON_KEY_RULES ] = rules .export (endpoint , export_settings = export_settings )
128136 if options .WHAT_PROFILES in what :
129- if options .WHAT_RULES not in what :
130- sq_settings [__JSON_KEY_RULES ] = rules .export (endpoint , export_settings = export_settings )
131137 sq_settings [__JSON_KEY_PROFILES ] = qualityprofiles .export (endpoint , export_settings = export_settings )
132138 if options .WHAT_GATES in what :
133139 sq_settings [__JSON_KEY_GATES ] = qualitygates .export (endpoint , export_settings = export_settings )
@@ -151,11 +157,7 @@ def __export_config(endpoint: platform.Platform, what: list[str], **kwargs) -> N
151157 sq_settings = utilities .remove_empties (sq_settings )
152158 if not kwargs ["dontInlineLists" ]:
153159 sq_settings = utilities .inline_lists (sq_settings , exceptions = ("conditions" ,))
154- with utilities .open_file (kwargs ["file" ]) as fd :
155- if kwargs [options .FORMAT ] == "yaml" :
156- print (yaml .dump (sq_settings ), file = fd )
157- else :
158- print (utilities .json_dump (sq_settings ), file = fd )
160+ __write_export (sq_settings , kwargs [options .REPORT_FILE ], kwargs [options .FORMAT ])
159161 log .info ("Exporting configuration from %s completed" , kwargs ["url" ])
160162
161163
0 commit comments