From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/
Date: Fri, 30 Mar 2018 04:23:40 +0000 (UTC) [thread overview]
Message-ID: <1522381880.3bffbc6150be9ee81d47547cbff113a8d45edb6d.zmedico@gentoo> (raw)
Message-ID: <20180330042340.BvxwAVoDNZipB4lYaei57BVDQK-LmaE5ajBQ3m8O3KE@z> (raw)
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))
next reply other threads:[~2018-03-30 4:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-30 5:20 Zac Medico [this message]
2018-03-30 4:23 ` [gentoo-commits] proj/portage:master commit in: pym/portage/ Zac Medico
-- strict thread matches above, loose matches on Subject: below --
2018-03-30 0:48 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2018-03-29 21:35 Brian Dolbec
2017-12-06 0:16 Brian Dolbec
2017-12-05 18:32 Brian Dolbec
2017-11-26 17:46 Brian Dolbec
2017-09-11 21:43 Brian Dolbec
2017-08-17 1:59 Brian Dolbec
2017-07-10 22:31 Brian Dolbec
2017-07-10 17:52 Brian Dolbec
2017-06-27 20:06 Brian Dolbec
2017-06-27 20:06 Brian Dolbec
2016-04-30 0:12 [gentoo-commits] proj/portage:master " Brian Dolbec
2016-05-03 6:11 ` [gentoo-commits] proj/portage:repoman " Brian Dolbec
2016-04-29 23:16 [gentoo-commits] proj/portage:master " Brian Dolbec
2016-05-03 6:11 ` [gentoo-commits] proj/portage:repoman " Brian Dolbec
2015-12-30 23:38 Brian Dolbec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1522381880.3bffbc6150be9ee81d47547cbff113a8d45edb6d.zmedico@gentoo \
--to=zmedico@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox