diff options
author | Jan Cholasta <jcholast@redhat.com> | 2016-05-30 09:40:07 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2016-06-03 09:00:34 +0200 |
commit | ed4c2d9252a995d01dc098e5b761ded8cd9373d8 (patch) | |
tree | 67740ac3ee8133a7bd49ffef5ee216762b25cc89 /ipalib | |
parent | fe18adb25839bf191aa748f13e75bfccb10f4a57 (diff) | |
download | freeipa-ed4c2d9252a995d01dc098e5b761ded8cd9373d8.tar.gz freeipa-ed4c2d9252a995d01dc098e5b761ded8cd9373d8.tar.xz freeipa-ed4c2d9252a995d01dc098e5b761ded8cd9373d8.zip |
plugable: turn Plugin attributes into properties
Implement the `name`, `doc` and `summary` Plugin attributes as properties
to allow them to be overriden in sub-classes.
Always use .doc rather than .__doc__ to access plugin documentation.
Remove the mostly unused `module`, `fullname`, `bases` and `label`
attributes.
https://fedorahosted.org/freeipa/ticket/4739
Reviewed-By: David Kupka <dkupka@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/plugable.py | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 0ed8f4fdb..e8b5eb9c6 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -39,7 +39,6 @@ import six from ipalib import errors from ipalib.config import Env -from ipalib import text from ipalib.text import _ from ipalib.base import ReadOnly, NameSpace, lock, islocked from ipalib.constants import DEFAULT_CONFIG @@ -127,38 +126,30 @@ class Plugin(ReadOnly): finalize_early = True - label = None - def __init__(self, api): assert api is not None self.__api = api self.__finalize_called = False self.__finalized = False self.__finalize_lock = threading.RLock() - cls = self.__class__ - self.name = cls.__name__ - self.module = cls.__module__ - self.fullname = '%s.%s' % (self.module, self.name) - self.bases = tuple( - '%s.%s' % (b.__module__, b.__name__) for b in cls.__bases__ - ) - self.doc = _(cls.__doc__) - if not self.doc.msg: - self.summary = '<%s>' % self.fullname - else: - self.summary = unicode(self.doc).split('\n\n', 1)[0].strip() log_mgr.get_logger(self, True) - if self.label is None: - self.label = text.FixMe(self.name + '.label') - if not isinstance(self.label, text.LazyText): - raise TypeError( - TYPE_ERROR % ( - self.fullname + '.label', - text.LazyText, - type(self.label), - self.label - ) - ) + + @property + def name(self): + return type(self).__name__ + + @property + def doc(self): + return type(self).__doc__ + + @property + def summary(self): + doc = self.doc + if not _(doc).msg: + cls = type(self) + return u'<%s.%s>' % (cls.__module__, cls.__name__) + else: + return unicode(doc).split('\n\n', 1)[0].strip() @property def api(self): |