aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2017-07-10 17:29:05 +0000
committerZac Medico <zmedico@gentoo.org>2018-03-29 20:51:14 -0700
commit2183c2eb0043688a7f523902cdb52e25b67e7283 (patch)
treeb1001d451b4ed6fa5096fc1f1c4319edb8f16367
parentrepoman: main.py: Remove unused InvalidStateError import (diff)
downloadportage-2183c2eb0043688a7f523902cdb52e25b67e7283.tar.gz
portage-2183c2eb0043688a7f523902cdb52e25b67e7283.tar.bz2
portage-2183c2eb0043688a7f523902cdb52e25b67e7283.zip
portage/module.py: Add a generic get_spec()
This new function gets any arbitrary spec value. The other get_* functions could be optimized to return the get_spec result instead. This would reduce code duplication. Replace 'was' with 'is' in error messages.
-rw-r--r--pym/portage/module.py27
1 files changed, 21 insertions, 6 deletions
diff --git a/pym/portage/module.py b/pym/portage/module.py
index f9828a518..c79e65518 100644
--- a/pym/portage/module.py
+++ b/pym/portage/module.py
@@ -63,7 +63,7 @@ class Module(object):
def get_class(self, name):
if not name or name not in self.kids_names:
- raise InvalidModuleName("Module name '%s' was invalid or not"
+ raise InvalidModuleName("Module name '%s' is invalid or not"
%name + "part of the module '%s'" %self.name)
kid = self.kids[name]
if kid['is_imported']:
@@ -142,7 +142,7 @@ class Modules(object):
if modname and modname in self.module_names:
mod = self._modules[modname]['parent'].get_class(modname)
else:
- raise InvalidModuleName("Module name '%s' was invalid or not"
+ raise InvalidModuleName("Module name '%s' is invalid or not"
%modname + "found")
return mod
@@ -157,7 +157,7 @@ class Modules(object):
if modname and modname in self.module_names:
mod = self._modules[modname]['description']
else:
- raise InvalidModuleName("Module name '%s' was invalid or not"
+ raise InvalidModuleName("Module name '%s' is invalid or not"
%modname + "found")
return mod
@@ -172,7 +172,7 @@ class Modules(object):
if modname and modname in self.module_names:
mod = self._modules[modname]['functions']
else:
- raise InvalidModuleName("Module name '%s' was invalid or not"
+ raise InvalidModuleName("Module name '%s' is invalid or not"
%modname + "found")
return mod
@@ -187,7 +187,7 @@ class Modules(object):
if modname and modname in self.module_names:
desc = self._modules[modname]['func_desc']
else:
- raise InvalidModuleName("Module name '%s' was invalid or not"
+ raise InvalidModuleName("Module name '%s' is invalid or not"
%modname + "found")
return desc
@@ -203,5 +203,20 @@ class Modules(object):
desc = self._modules[modname].get('opt_desc')
else:
raise InvalidModuleName(
- "Module name '%s' was invalid or not found" % modname)
+ "Module name '%s' is invalid or not found" % modname)
return desc
+
+ def get_spec(self, modname, var):
+ """Retrieves the module class exported spec variable
+
+ @type modname: string
+ @param modname: the module class name
+ @type dictionary
+ @return: the modules class exported options descriptions
+ """
+ if modname and modname in self.module_names:
+ value = self._modules[modname].get(var, None)
+ else:
+ raise InvalidModuleName(
+ "Module name '%s' is invalid or not found" % modname)
+ return value