3030import six
3131
3232from xcp import version , xmlunwrap
33+ from xcp import logger
3334
3435if TYPE_CHECKING :
3536 from xml .dom .minidom import Element # pytype: disable=pyi-error
@@ -151,6 +152,19 @@ def getProductVersion(cls, access):
151152 return YumRepository .getProductVersion (access )
152153 return None
153154
155+ #pylint: disable=invalid-name
156+ @classmethod
157+ def getRequiredUpgradePluginVersion (cls , access ):
158+ """Returns the required upgrade plugin version of the repository."""
159+ access .start ()
160+ is_yum = YumRepository .isRepo (access , "" )
161+ access .finish ()
162+
163+ if is_yum :
164+ return YumRepository .getRequiredUpgradePluginVersion (access )
165+ return None
166+
167+
154168class YumRepository (BaseRepository ):
155169 """ Represents a Yum repository containing packages and associated meta data. """
156170 REPOMD_FILENAME = "repodata/repomd.xml"
@@ -177,7 +191,8 @@ def isRepo(cls, access, base):
177191
178192 @classmethod
179193 def _getVersion (cls , access , category ):
180- category_map = {'platform' : 'platform_version' , 'branding' : 'product_version' }
194+ category_map = {'platform' : 'platform_version' , 'branding' : 'product_version' ,
195+ 'required_upgrade_plugin' : 'required_minimal_upgrade_plugin_version' }
181196
182197 access .start ()
183198 try :
@@ -186,11 +201,15 @@ def _getVersion(cls, access, category):
186201 with access .openText (cls .TREEINFO_FILENAME ) as fp :
187202 treeinfo .read_file (fp )
188203
189- if treeinfo .has_section ('system-v1' ):
190- ver_str = treeinfo .get ('system-v1' , category_map [category ])
191- else :
192- ver_str = treeinfo .get (category , 'version' )
193- repo_ver = version .Version .from_string (ver_str )
204+ try :
205+ if treeinfo .has_section ('system-v1' ):
206+ ver_str = treeinfo .get ('system-v1' , category_map [category ])
207+ else :
208+ ver_str = treeinfo .get (category , 'version' )
209+ repo_ver = version .Version .from_string (ver_str )
210+ except configparser .NoOptionError as e :
211+ logger .debug (e )
212+ repo_ver = None
194213
195214 except Exception as e :
196215 six .raise_from (RepoFormatError ("Failed to open %s: %s" %
@@ -210,6 +229,13 @@ def getProductVersion(cls, access):
210229
211230 return cls ._getVersion (access , 'branding' )
212231
232+ @classmethod
233+ def getRequiredUpgradePluginVersion (cls , access ):
234+ """Returns the required upgrade plugin version of the repository."""
235+
236+ return cls ._getVersion (access , 'required_upgrade_plugin' )
237+
238+
213239class Repository (BaseRepository ):
214240 """ Represents a XenSource repository containing packages and associated
215241 meta data. """
0 commit comments