@@ -280,7 +280,7 @@ def clear_plugins_table(self):
280280 while table .rowCount () > 0 :
281281 table .removeRow (0 )
282282
283- #Exports the selected plugin into a .csv or json file
283+ # Exports the selected plugin into a .csv or json file
284284 def export_plugins (self ):
285285 file_format = self .dlg .combo_file_format .currentText ()
286286 output_file = self .dlg .file_output_export .filePath ()
@@ -302,20 +302,35 @@ def export_plugins(self):
302302 plugin_list .append (current_plugin )
303303 if plugin_list :
304304 if output_file :
305- if file_format == '.csv' :
306- with open (output_file , 'w' , encoding = 'utf8' , newline = '' ) as f :
307- keys = plugin_list [0 ].keys ()
308- dict_writer = csv .DictWriter (f , keys )
309- dict_writer .writeheader ()
310- dict_writer .writerows (plugin_list )
311- self .iface .messageBar ().pushSuccess ("Success" , "Selected plugins were exported successfully." )
312- elif file_format == '.json' :
313- with open (output_file , 'w' ) as file :
314- json .dump (plugin_list , file )
315- self .iface .messageBar ().pushSuccess ("Success" , "Selected plugins were exported successfully." )
305+ try :
306+ if file_format == '.csv' :
307+ with open (output_file , 'w' , encoding = 'utf8' , newline = '' ) as f :
308+ keys = plugin_list [0 ].keys ()
309+ dict_writer = csv .DictWriter (f , keys )
310+ dict_writer .writeheader ()
311+ dict_writer .writerows (plugin_list )
312+ self .iface .messageBar ().pushSuccess ("Success" , "Selected plugins were exported successfully." )
313+ elif file_format == '.json' :
314+ with open (output_file , 'w' ) as file :
315+ json .dump (plugin_list , file )
316+ self .iface .messageBar ().pushSuccess ("Success" , "Selected plugins were exported successfully." )
317+ except IsADirectoryError :
318+ self .iface .messageBar ().pushMessage ("Error" ,
319+ "You must select a file, not a directory." ,
320+ level = Qgis .Critical )
321+ except PermissionError :
322+ self .iface .messageBar ().pushMessage ("Error" ,
323+ "You don't have permission to write to this directory. Please "
324+ "pick another location and try again." ,
325+ level = Qgis .Critical )
326+ except FileNotFoundError :
327+ self .iface .messageBar ().pushMessage ("Error" ,
328+ "No such file or directory. "
329+ "Please check the path is valid." ,
330+ level = Qgis .Critical )
316331 else :
317332 self .iface .messageBar ().pushMessage ("Error" ,
318- "You must select an output directory ." ,
333+ "You must select an output file ." ,
319334 level = Qgis .Critical )
320335 else :
321336 self .iface .messageBar ().pushMessage ("Error" ,
@@ -338,6 +353,7 @@ def import_plugins(self):
338353 self .iface .messageBar ().pushMessage ("Error" ,
339354 "Unable to read the CSV file." ,
340355 level = Qgis .Critical )
356+ return
341357 elif file_extension == '.json' :
342358 try :
343359 f = open (input_file )
@@ -346,10 +362,12 @@ def import_plugins(self):
346362 self .iface .messageBar ().pushMessage ("Error" ,
347363 "Unable to read the JSON file." ,
348364 level = Qgis .Critical )
365+ return
349366 else :
350367 self .iface .messageBar ().pushMessage ("Error" ,
351368 "Unsupported file type." ,
352369 level = Qgis .Critical )
370+ return
353371
354372 for plugin in plugins :
355373 if self .dlg .chk_skip_installed .isChecked ():
0 commit comments