24
24
from qgis .PyQt .QtCore import QSettings , QTranslator , QCoreApplication
25
25
from qgis .PyQt .QtGui import QIcon
26
26
from 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
29
29
import pyplugin_installer
30
+ import qgis .utils
30
31
import os .path
31
32
import csv
32
33
import json
@@ -289,6 +290,11 @@ def export_plugins(self):
289
290
rows = table .rowCount ()
290
291
cols = table .columnCount ()
291
292
293
+ if self .dlg .chk_core_plugins .isChecked ():
294
+ repos = repositories .allEnabled ()
295
+ else :
296
+ repos = None
297
+
292
298
for row in range (rows ):
293
299
for col in range (cols ):
294
300
current_widget = table .cellWidget (row , col )
@@ -308,6 +314,12 @@ def export_plugins(self):
308
314
keys = plugin_list [0 ].keys ()
309
315
dict_writer = csv .DictWriter (f , keys )
310
316
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' ]})
311
323
dict_writer .writerows (plugin_list )
312
324
self .iface .messageBar ().pushSuccess ("Success" , "Selected plugins were exported successfully." )
313
325
elif file_format == '.json' :
@@ -342,7 +354,6 @@ def import_plugins(self):
342
354
input_file = self .dlg .file_input_import .filePath ()
343
355
file_extension = pathlib .Path (input_file ).suffix
344
356
installed_plugins = qgis .utils .available_plugins
345
- pyplugin_installer .instance ().fetchAvailablePlugins (True )
346
357
347
358
if file_extension == '.csv' :
348
359
try :
@@ -376,13 +387,33 @@ def import_plugins(self):
376
387
"Skipped " + plugin ['name' ] + " as it's already installed." )
377
388
continue
378
389
try :
390
+ if plugin ['id' ] == '-' : # It's a third party repository
391
+ self .add_repository (plugin )
392
+ pyplugin_installer .instance ().fetchAvailablePlugins (True )
379
393
pyplugin_installer .instance ().installPlugin (plugin ['id' ])
380
394
self .iface .messageBar ().pushSuccess ("Success" , plugin ['name' ] + " was installed successfully." )
381
395
except KeyError :
382
396
self .iface .messageBar ().pushMessage ("Error" ,
383
397
"Could not install " + plugin ['name' ] + "." ,
384
398
level = Qgis .Critical )
385
399
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
+
386
417
# Disables and enables widgets
387
418
def toggle_widget (self ):
388
419
if self .dlg .rd_import .isChecked ():
0 commit comments