From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1013680-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 676F71382C5
	for <garchives@archives.gentoo.org>; Fri, 30 Mar 2018 05:21:32 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 7E398E09BD;
	Fri, 30 Mar 2018 05:20:53 +0000 (UTC)
Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 4204FE09BD
	for <gentoo-commits@lists.gentoo.org>; Fri, 30 Mar 2018 05:20:53 +0000 (UTC)
Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 45894335D1E
	for <gentoo-commits@lists.gentoo.org>; Fri, 30 Mar 2018 05:20:52 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id AD52227E
	for <gentoo-commits@lists.gentoo.org>; Fri, 30 Mar 2018 05:20:47 +0000 (UTC)
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" <zmedico@gentoo.org>
Message-ID: <1522381880.3bffbc6150be9ee81d47547cbff113a8d45edb6d.zmedico@gentoo>
Subject: [gentoo-commits] proj/portage:repoman commit in: pym/portage/
X-VCS-Repository: proj/portage
X-VCS-Files: pym/portage/module.py
X-VCS-Directories: pym/portage/
X-VCS-Committer: zmedico
X-VCS-Committer-Name: Zac Medico
X-VCS-Revision: 3bffbc6150be9ee81d47547cbff113a8d45edb6d
X-VCS-Branch: repoman
Date: Fri, 30 Mar 2018 05:20:47 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: 51288f49-cca5-4c50-ade4-388bb151a89e
X-Archives-Hash: 4416eef836a16e63c058e993260d7169

commit:     3bffbc6150be9ee81d47547cbff113a8d45edb6d
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Thu Aug 17 01:50:21 2017 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Mar 30 03:51:20 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=3bffbc61

module.py: Extend the module loader for API version checking

If provided with an iterable of compatibility versions, The controller
will check the plugin modules module_spec 'version' variable is
compatible with the base application.

 pym/portage/module.py | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/pym/portage/module.py b/pym/portage/module.py
index c79e65518..bd7c94d4e 100644
--- a/pym/portage/module.py
+++ b/pym/portage/module.py
@@ -15,6 +15,10 @@ class InvalidModuleName(PortageException):
 	"""An invalid or unknown module name."""
 
 
+class ModuleVersionError(PortageException):
+	'''An incompatible module version'''
+
+
 class Module(object):
 	"""Class to define and hold our plug-in module
 
@@ -87,16 +91,17 @@ class Modules(object):
 	@param namepath: Python import path to the "modules" directory
 	"""
 
-	def __init__(self, path, namepath):
+	def __init__(self, path, namepath, compat_versions=None):
 		self._module_path = path
 		self._namepath = namepath
+		self.compat_versions = compat_versions
 		self.parents = []
 		self._modules = self._get_all_modules()
 		self.modules = ProtectedDict(self._modules)
 		self.module_names = sorted(self._modules)
 
 	def _get_all_modules(self):
-		"""scans the emaint modules dir for loadable modules
+		"""scans the _module_path dir for loadable modules
 
 		@rtype: dictionary of module_plugins
 		"""
@@ -117,6 +122,7 @@ class Modules(object):
 		kids = {}
 		for entry in importables:
 			new_module = Module(entry, self._namepath)
+			self._check_compat(new_module)
 			for module_name in new_module.kids:
 				kid = new_module.kids[module_name]
 				kid['parent'] = new_module
@@ -211,6 +217,8 @@ class Modules(object):
 
 		@type modname: string
 		@param modname: the module class name
+		@type var: string
+		@param var: the base level variable to return
 		@type dictionary
 		@return: the modules class exported options descriptions
 		"""
@@ -220,3 +228,13 @@ class Modules(object):
 			raise InvalidModuleName(
 				"Module name '%s' is invalid or not found" % modname)
 		return value
+
+	def _check_compat(self, module):
+		if self.compat_versions:
+			if not module.module_spec['version'] in self.compat_versions:
+				raise ModuleVersionError(
+					"Error loading '%s' plugin module: %s, version: %s\n"
+					"Module is not compatible with the current application version\n"
+					"Compatible module API versions are: %s"
+					% (self._namepath, module.module_spec['name'],
+						module.module_spec['version'], self.compat_versions))


From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1013644-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 421CA1382C5
	for <garchives@archives.gentoo.org>; Fri, 30 Mar 2018 04:23:49 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 80EBEE0975;
	Fri, 30 Mar 2018 04:23:45 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 4A78FE0975
	for <gentoo-commits@lists.gentoo.org>; Fri, 30 Mar 2018 04:23:45 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id CBA37335D3D
	for <gentoo-commits@lists.gentoo.org>; Fri, 30 Mar 2018 04:23:43 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id CC01927C
	for <gentoo-commits@lists.gentoo.org>; Fri, 30 Mar 2018 04:23:40 +0000 (UTC)
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" <zmedico@gentoo.org>
Message-ID: <1522381880.3bffbc6150be9ee81d47547cbff113a8d45edb6d.zmedico@gentoo>
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/
X-VCS-Repository: proj/portage
X-VCS-Files: pym/portage/module.py
X-VCS-Directories: pym/portage/
X-VCS-Committer: zmedico
X-VCS-Committer-Name: Zac Medico
X-VCS-Revision: 3bffbc6150be9ee81d47547cbff113a8d45edb6d
X-VCS-Branch: master
Date: Fri, 30 Mar 2018 04:23:40 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: b0e2f47d-7fde-487b-b2c1-2af08afce11f
X-Archives-Hash: fc980a1101be6803db8da6030ce09955
Message-ID: <20180330042340.BvxwAVoDNZipB4lYaei57BVDQK-LmaE5ajBQ3m8O3KE@z>

commit:     3bffbc6150be9ee81d47547cbff113a8d45edb6d
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Thu Aug 17 01:50:21 2017 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Mar 30 03:51:20 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=3bffbc61

module.py: Extend the module loader for API version checking

If provided with an iterable of compatibility versions, The controller
will check the plugin modules module_spec 'version' variable is
compatible with the base application.

 pym/portage/module.py | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/pym/portage/module.py b/pym/portage/module.py
index c79e65518..bd7c94d4e 100644
--- a/pym/portage/module.py
+++ b/pym/portage/module.py
@@ -15,6 +15,10 @@ class InvalidModuleName(PortageException):
 	"""An invalid or unknown module name."""
 
 
+class ModuleVersionError(PortageException):
+	'''An incompatible module version'''
+
+
 class Module(object):
 	"""Class to define and hold our plug-in module
 
@@ -87,16 +91,17 @@ class Modules(object):
 	@param namepath: Python import path to the "modules" directory
 	"""
 
-	def __init__(self, path, namepath):
+	def __init__(self, path, namepath, compat_versions=None):
 		self._module_path = path
 		self._namepath = namepath
+		self.compat_versions = compat_versions
 		self.parents = []
 		self._modules = self._get_all_modules()
 		self.modules = ProtectedDict(self._modules)
 		self.module_names = sorted(self._modules)
 
 	def _get_all_modules(self):
-		"""scans the emaint modules dir for loadable modules
+		"""scans the _module_path dir for loadable modules
 
 		@rtype: dictionary of module_plugins
 		"""
@@ -117,6 +122,7 @@ class Modules(object):
 		kids = {}
 		for entry in importables:
 			new_module = Module(entry, self._namepath)
+			self._check_compat(new_module)
 			for module_name in new_module.kids:
 				kid = new_module.kids[module_name]
 				kid['parent'] = new_module
@@ -211,6 +217,8 @@ class Modules(object):
 
 		@type modname: string
 		@param modname: the module class name
+		@type var: string
+		@param var: the base level variable to return
 		@type dictionary
 		@return: the modules class exported options descriptions
 		"""
@@ -220,3 +228,13 @@ class Modules(object):
 			raise InvalidModuleName(
 				"Module name '%s' is invalid or not found" % modname)
 		return value
+
+	def _check_compat(self, module):
+		if self.compat_versions:
+			if not module.module_spec['version'] in self.compat_versions:
+				raise ModuleVersionError(
+					"Error loading '%s' plugin module: %s, version: %s\n"
+					"Module is not compatible with the current application version\n"
+					"Compatible module API versions are: %s"
+					% (self._namepath, module.module_spec['name'],
+						module.module_spec['version'], self.compat_versions))