2424from qgis .PyQt .QtCore import QSettings , QTranslator , QCoreApplication
2525from qgis .PyQt .QtGui import QIcon
2626from qgis .PyQt .QtWidgets import QAction , QLabel , QCheckBox
27- from qgis .core import Qgis
28- import qgis . utils
27+ from qgis .core import Qgis , QgsSettings
28+ from pyplugin_installer . installer_data import repositories
2929import pyplugin_installer
30+ import qgis .utils
3031import os .path
3132import csv
3233import json
@@ -289,6 +290,11 @@ def export_plugins(self):
289290 rows = table .rowCount ()
290291 cols = table .columnCount ()
291292
293+ if self .dlg .chk_core_plugins .isChecked ():
294+ repos = repositories .allEnabled ()
295+ else :
296+ repos = None
297+
292298 for row in range (rows ):
293299 for col in range (cols ):
294300 current_widget = table .cellWidget (row , col )
@@ -308,6 +314,12 @@ def export_plugins(self):
308314 keys = plugin_list [0 ].keys ()
309315 dict_writer = csv .DictWriter (f , keys )
310316 dict_writer .writeheader ()
317+ if repos :
318+ for key , value in repos .items ():
319+ if key == 'QGIS Official Plugin Repository' :
320+ pass
321+ else :
322+ dict_writer .writerow ({'id' : '-' , 'name' : key , 'zip_repository' : value ['url' ]})
311323 dict_writer .writerows (plugin_list )
312324 self .iface .messageBar ().pushSuccess ("Success" , "Selected plugins were exported successfully." )
313325 elif file_format == '.json' :
@@ -342,7 +354,6 @@ def import_plugins(self):
342354 input_file = self .dlg .file_input_import .filePath ()
343355 file_extension = pathlib .Path (input_file ).suffix
344356 installed_plugins = qgis .utils .available_plugins
345- pyplugin_installer .instance ().fetchAvailablePlugins (True )
346357
347358 if file_extension == '.csv' :
348359 try :
@@ -376,13 +387,33 @@ def import_plugins(self):
376387 "Skipped " + plugin ['name' ] + " as it's already installed." )
377388 continue
378389 try :
390+ if plugin ['id' ] == '-' : # It's a third party repository
391+ self .add_repository (plugin )
392+ pyplugin_installer .instance ().fetchAvailablePlugins (True )
379393 pyplugin_installer .instance ().installPlugin (plugin ['id' ])
380394 self .iface .messageBar ().pushSuccess ("Success" , plugin ['name' ] + " was installed successfully." )
381395 except KeyError :
382396 self .iface .messageBar ().pushMessage ("Error" ,
383397 "Could not install " + plugin ['name' ] + "." ,
384398 level = Qgis .Critical )
385399
400+ # This method is pretty much a copy of the addRepository function in
401+ # https://github.com/qgis/QGIS/blob/master/python/pyplugin_installer/installer.py
402+ def add_repository (self , repo_info ):
403+ settings = QgsSettings ()
404+ settings .beginGroup ("app/plugin_repositories" )
405+ reposName = repo_info ['name' ]
406+ reposURL = repo_info ['zip_repository' ]
407+ if reposName in repositories .all ():
408+ reposName = reposName + "(2)"
409+ # add to settings
410+ settings .setValue (reposName + "/url" , reposURL )
411+ settings .setValue (reposName + "/authcfg" , "" ) #dlg.editAuthCfg.text().strip())
412+ settings .setValue (reposName + "/enabled" , "True" ) #bool(dlg.checkBoxEnabled.checkState()))
413+ # refresh lists and populate widgets
414+ #plugins.removeRepository(reposName)
415+ pyplugin_installer .instance ().reloadAndExportData ()
416+
386417 # Disables and enables widgets
387418 def toggle_widget (self ):
388419 if self .dlg .rd_import .isChecked ():
0 commit comments