11from configparser import NoSectionError , RawConfigParser
2- from dataclasses import dataclass
32from pathlib import Path
43from sys import platform
54from typing import Any , Dict , List , Optional
87from qgis .core import QgsUserProfileManager
98from qgis .utils import iface
109
10+ from profile_manager .qdt_export .models import QdtPluginInformation
11+
1112
1213def qgis_profiles_path () -> Path :
1314 """Get QGIS profiles paths from current QGIS application
@@ -94,9 +95,11 @@ def get_installed_plugin_metadata(
9495 """
9596 ini_parser = RawConfigParser ()
9697 ini_parser .optionxform = str # str = case-sensitive option names
97- ini_parser .read (get_profile_plugin_metadata_path (profile_name , plugin_slug_name ))
98+ plg_metadata_path = get_profile_plugin_metadata_path (profile_name , plugin_slug_name )
99+ ini_parser .read (plg_metadata_path )
98100 try :
99101 metadata = dict (ini_parser .items ("general" ))
102+ metadata ["folder_name" ] = plg_metadata_path .parent .name
100103 except NoSectionError :
101104 metadata = {}
102105 return metadata
@@ -128,15 +131,6 @@ def get_profile_name_list() -> List[str]:
128131 return QgsUserProfileManager (qgis_profiles_path ()).allProfiles ()
129132
130133
131- @dataclass
132- class PluginInformation :
133- name : str
134- folder_name : str
135- official_repository : bool
136- plugin_id : Optional [int ]
137- version : str
138-
139-
140134def define_plugin_version_from_metadata (
141135 manager_metadata : Dict [str , Any ], plugin_metadata : Dict [str , Any ]
142136) -> str :
@@ -168,7 +162,7 @@ def define_plugin_version_from_metadata(
168162
169163def get_profile_plugin_information (
170164 profile_name : str , plugin_slug_name : str
171- ) -> Optional [PluginInformation ]:
165+ ) -> Optional [QdtPluginInformation ]:
172166 """Get plugin information from profile. Only official plugin are supported.
173167
174168 Args:
@@ -181,18 +175,27 @@ def get_profile_plugin_information(
181175 manager_metadata = get_plugin_info_from_qgis_manager (
182176 plugin_slug_name = plugin_slug_name
183177 )
178+
184179 plugin_metadata = get_installed_plugin_metadata (
185180 profile_name = profile_name , plugin_slug_name = plugin_slug_name
186181 )
187182
188- # For now we don't support unofficial plugins
189- if manager_metadata is None :
183+ if not all ([ manager_metadata , plugin_metadata ]):
184+ print ( f"Plugin { plugin_slug_name } not found in profile { profile_name } " )
190185 return None
191186
192- return PluginInformation (
193- name = manager_metadata ["name" ],
194- folder_name = plugin_slug_name ,
195- official_repository = True , # For now we only support official repository
187+ if manager_metadata is None :
188+ manager_metadata = {
189+ "name" : plugin_metadata .get ("name" , plugin_slug_name ),
190+ "download_url" : None ,
191+ "plugin_id" : None ,
192+ "folder_name" : plugin_metadata .get ("folder_name" , plugin_slug_name ),
193+ }
194+
195+ return QdtPluginInformation (
196+ name = manager_metadata .get ("name" , plugin_slug_name ),
197+ download_url = manager_metadata .get ("download_url" ),
198+ folder_name = plugin_metadata .get ("folder_name" , plugin_slug_name ),
196199 plugin_id = (
197200 int (manager_metadata ["plugin_id" ])
198201 if manager_metadata ["plugin_id" ]
@@ -207,7 +210,7 @@ def get_profile_plugin_information(
207210
208211def get_profile_plugin_list_information (
209212 profile_name : str , only_activated : bool = True
210- ) -> List [PluginInformation ]:
213+ ) -> List [QdtPluginInformation ]:
211214 """Get profile plugin information
212215
213216 Args:
@@ -220,12 +223,14 @@ def get_profile_plugin_list_information(
220223 plugin_list : List [str ] = get_installed_plugin_list (
221224 profile_name = profile_name , only_activated = only_activated
222225 )
223- # Get information about installed plugin
224- profile_plugin_list : List [PluginInformation ] = []
225226
227+ # Get information about installed plugin
228+ profile_plugin_list : List [QdtPluginInformation ] = []
226229 for plugin_name in plugin_list :
227230 plugin_info = get_profile_plugin_information (profile_name , plugin_name )
228231 if plugin_info and plugin_info .plugin_id :
229232 profile_plugin_list .append (plugin_info )
233+ elif plugin_info and not plugin_info .plugin_id :
234+ profile_plugin_list .append (plugin_info )
230235
231236 return profile_plugin_list
0 commit comments