diff --git a/ipalib/__init__.py b/ipalib/__init__.py index 595ab4c50..16d7db761 100644 --- a/ipalib/__init__.py +++ b/ipalib/__init__.py @@ -118,7 +118,7 @@ False >>> hasattr(api.Command, 'my_command') True >>> api.Command.my_command.doc -'My example plugin.' +Gettext('My example plugin.', domain='ipa', localedir=None) Notice that your plugin instance is accessed through an attribute named ``my_command``, the same name as your plugin class name. diff --git a/ipalib/parameters.py b/ipalib/parameters.py index daec1d6a9..47d532227 100644 --- a/ipalib/parameters.py +++ b/ipalib/parameters.py @@ -302,7 +302,7 @@ class Param(ReadOnly): ('cli_name', str, None), ('cli_short_name', str, None), ('label', (str, Gettext), None), - ('doc', (str, Gettext), None), + ('doc', (basestring, Gettext), None), ('required', bool, True), ('multivalue', bool, False), ('primary_key', bool, False), @@ -384,7 +384,7 @@ class Param(ReadOnly): elif type(value) is str: value = frozenset([value]) if ( - type(kind) is type and type(value) is not kind + type(kind) is type and not isinstance(value, kind) or type(kind) is tuple and not isinstance(value, kind) ): diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 26ce366f3..da02d87f4 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -38,6 +38,7 @@ import errors from config import Env import util import text +from text import _ from base import ReadOnly, NameSpace, lock, islocked, check_name from constants import DEFAULT_CONFIG, FORMAT_STDERR, FORMAT_FILE @@ -181,11 +182,12 @@ class Plugin(ReadOnly): self.bases = tuple( '%s.%s' % (b.__module__, b.__name__) for b in cls.__bases__ ) - self.doc = _(inspect.getdoc(cls)) - if self.doc is None: + doc = inspect.getdoc(cls) + self.doc = _(doc) + if doc is None: self.summary = '<%s>' % self.fullname else: - self.summary = self.doc.split('\n\n', 1)[0] + self.summary = unicode(self.doc).split('\n\n', 1)[0] log = logging.getLogger(self.fullname) for name in ('debug', 'info', 'warning', 'error', 'critical', 'exception'): if hasattr(self, name): diff --git a/ipalib/plugins/automount.py b/ipalib/plugins/automount.py index 9c2c0ad13..2835204c9 100644 --- a/ipalib/plugins/automount.py +++ b/ipalib/plugins/automount.py @@ -329,7 +329,9 @@ class automountlocation_import(LDAPQuery): fp.close() except IOError, e: if e.errno == 2: - raise errors.NotFound(reason=_('File %(file)s not found' % {'file':filename})) + raise errors.NotFound( + reason=_('File %(file)s not found') % {'file': filename} + ) else: raise e return map diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py index 4441e7960..02c839cf5 100644 --- a/ipalib/plugins/baseldap.py +++ b/ipalib/plugins/baseldap.py @@ -759,9 +759,12 @@ class LDAPUpdate(LDAPQuery, crud.Update): def _get_rename_option(self): rdnparam = getattr(self.obj.params, self.obj.rdnattr) - return rdnparam.clone_rename('rename', cli_name='rename', - required=False, label=_('Rename'), - doc=_('Rename the %s object' % self.obj.object_name)) + return rdnparam.clone_rename('rename', + cli_name='rename', required=False, label=_('Rename'), + doc=_('Rename the %(ldap_obj_name)s object') % dict( + ldap_obj_name=self.obj.object_name + ) + ) def get_options(self): for option in super(LDAPUpdate, self).get_options(): diff --git a/ipalib/plugins/batch.py b/ipalib/plugins/batch.py index 5455340b2..10277ceba 100644 --- a/ipalib/plugins/batch.py +++ b/ipalib/plugins/batch.py @@ -74,8 +74,8 @@ class batch(Command): ) has_output = ( - Output('count', int, doc=_('')), - Output('results', list, doc=_('')) + Output('count', int, doc=''), + Output('results', list, doc='') ) def execute(self, *args, **options): diff --git a/ipalib/plugins/delegation.py b/ipalib/plugins/delegation.py index 8ea0af9cf..c3b5e4825 100644 --- a/ipalib/plugins/delegation.py +++ b/ipalib/plugins/delegation.py @@ -221,7 +221,7 @@ class delegation_find(crud.Search): """ msg_summary = ngettext( - '%(count)d delegation matched', '%(count)d delegations matched' + '%(count)d delegation matched', '%(count)d delegations matched', 0 ) def execute(self, term, **kw): diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py index a18940b3a..1c03b5320 100644 --- a/ipalib/plugins/dns.py +++ b/ipalib/plugins/dns.py @@ -201,7 +201,9 @@ def is_ns_rec_resolvable(name): try: return api.Command['dns_resolve'](name) except errors.NotFound: - raise errors.NotFound(reason=_('Nameserver \'%(host)s\' does not have a corresponding A/AAAA record' % {'host':name})) + raise errors.NotFound( + reason=_('Nameserver \'%(host)s\' does not have a corresponding A/AAAA record') % {'host': name} + ) def add_forward_record(zone, name, str_address): addr = netaddr.IPAddress(str_address) @@ -816,7 +818,9 @@ class dns_resolve(Command): break if not found: - raise errors.NotFound(reason=_('Host \'%(host)s\' not found' % {'host':query})) + raise errors.NotFound( + reason=_('Host \'%(host)s\' not found') % {'host': query} + ) return dict(result=True, value=query) diff --git a/ipalib/plugins/host.py b/ipalib/plugins/host.py index f5f5157b0..53846cd33 100644 --- a/ipalib/plugins/host.py +++ b/ipalib/plugins/host.py @@ -316,7 +316,9 @@ class host_add(LDAPCreate): match = True break if not match: - raise errors.NotFound(reason=_('DNS zone %(zone)s not found' % dict(zone=domain))) + raise errors.NotFound( + reason=_('DNS zone %(zone)s not found') % dict(zone=domain) + ) if not options.get('no_reverse', False): # we prefer lookup of the IP through the reverse zone revzone, revname = get_reverse_zone(options['ip_address']) @@ -327,7 +329,9 @@ class host_add(LDAPCreate): match = True break if not match: - raise errors.NotFound(reason=_('Reverse DNS zone %(zone)s not found' % dict(zone=revzone))) + raise errors.NotFound( + reason=_('Reverse DNS zone %(zone)s not found') % dict(zone=revzone) + ) try: reverse = api.Command['dnsrecord_find'](revzone, idnsname=revname) if reverse['count'] > 0: @@ -395,7 +399,9 @@ class host_add(LDAPCreate): # context, don't crash. pass if exc: - raise errors.NonFatalError(reason=_('The host was added but the DNS update failed with: %(exc)s' % dict(exc=exc))) + raise errors.NonFatalError( + reason=_('The host was added but the DNS update failed with: %(exc)s') % dict(exc=exc) + ) set_certificate_attrs(entry_attrs) return dn @@ -457,7 +463,9 @@ class host_del(LDAPDelete): match = True break if not match: - raise errors.NotFound(reason=_('DNS zone %(zone)s not found' % dict(zone=domain))) + raise errors.NotFound( + reason=_('DNS zone %(zone)s not found') % dict(zone=domain) + ) # Get all forward resources for this host records = api.Command['dnsrecord_find'](domain, idnsname=parts[0])['result'] for record in records: @@ -602,7 +610,7 @@ class host_find(LDAPSearch): has_output_params = LDAPSearch.has_output_params + host_output_params msg_summary = ngettext( - '%(count)d host matched', '%(count)d hosts matched' + '%(count)d host matched', '%(count)d hosts matched', 0 ) member_attributes = ['memberof', 'enrolledby', 'managedby'] diff --git a/ipalib/plugins/hostgroup.py b/ipalib/plugins/hostgroup.py index f661a2ff5..715523440 100644 --- a/ipalib/plugins/hostgroup.py +++ b/ipalib/plugins/hostgroup.py @@ -126,7 +126,7 @@ class hostgroup_find(LDAPSearch): """ member_attributes = ['member', 'memberof'] msg_summary = ngettext( - '%(count)d hostgroup matched', '%(count)d hostgroups matched' + '%(count)d hostgroup matched', '%(count)d hostgroups matched', 0 ) api.register(hostgroup_find) diff --git a/ipalib/plugins/internal.py b/ipalib/plugins/internal.py index ef1326265..f25e429e9 100644 --- a/ipalib/plugins/internal.py +++ b/ipalib/plugins/internal.py @@ -379,11 +379,7 @@ class i18n_messages(Command): "validation_error":_("Text does not match field pattern"), }, "ajax":{ - "401":_("Your kerberos ticket is no longer valid. "+ - "Please run kinit and then click 'Retry'. "+ - "If this is your first time running the IPA Web UI "+ - ""+ - "follow these directions to configure your browser.") + "401":_("Your kerberos ticket is no longer valid. Please run kinit and then click 'Retry'. If this is your first time running the IPA Web UI follow these directions to configure your browser.") }, "dirty":_("This page has unsaved changes. Please save or revert."), } diff --git a/ipalib/plugins/migration.py b/ipalib/plugins/migration.py index 4e3a4b00e..54e58273d 100644 --- a/ipalib/plugins/migration.py +++ b/ipalib/plugins/migration.py @@ -413,7 +413,9 @@ can use their Kerberos accounts.''') ) except errors.NotFound: if not options.get('continue',False): - raise errors.NotFound(reason=_('Container for %(container)s not found' % {'container':ldap_obj_name})) + raise errors.NotFound( + reason=_('Container for %(container)s not found') % {'container': ldap_obj_name} + ) else: truncated = False entries = [] diff --git a/ipalib/plugins/misc.py b/ipalib/plugins/misc.py index 6bb2fc0e7..32457ffbf 100644 --- a/ipalib/plugins/misc.py +++ b/ipalib/plugins/misc.py @@ -106,7 +106,7 @@ class plugins(LocalOrRemote): """Show all loaded plugins""" msg_summary = ngettext( - '%(count)d plugin loaded', '%(count)d plugins loaded' + '%(count)d plugin loaded', '%(count)d plugins loaded', 0 ) takes_options = LocalOrRemote.takes_options + ( diff --git a/ipalib/plugins/netgroup.py b/ipalib/plugins/netgroup.py index 610eb02c3..eeb6de65f 100644 --- a/ipalib/plugins/netgroup.py +++ b/ipalib/plugins/netgroup.py @@ -183,7 +183,7 @@ class netgroup_find(LDAPSearch): member_attributes = ['member', 'memberuser', 'memberhost', 'memberof'] has_output_params = LDAPSearch.has_output_params + output_params msg_summary = ngettext( - '%(count)d netgroup matched', '%(count)d netgroups matched' + '%(count)d netgroup matched', '%(count)d netgroups matched', 0 ) takes_options = LDAPSearch.takes_options + ( diff --git a/ipalib/plugins/permission.py b/ipalib/plugins/permission.py index db063334f..af25f8112 100644 --- a/ipalib/plugins/permission.py +++ b/ipalib/plugins/permission.py @@ -353,7 +353,7 @@ class permission_find(LDAPSearch): """ msg_summary = ngettext( - '%(count)d permission matched', '%(count)d permissions matched' + '%(count)d permission matched', '%(count)d permissions matched', 0 ) has_output_params = LDAPSearch.has_output_params + output_params diff --git a/ipalib/plugins/privilege.py b/ipalib/plugins/privilege.py index 3be466483..24398002f 100644 --- a/ipalib/plugins/privilege.py +++ b/ipalib/plugins/privilege.py @@ -117,7 +117,7 @@ class privilege_find(LDAPSearch): """ msg_summary = ngettext( - '%(count)d privilege matched', '%(count)d privileges matched' + '%(count)d privilege matched', '%(count)d privileges matched', 0 ) api.register(privilege_find) diff --git a/ipalib/plugins/role.py b/ipalib/plugins/role.py index 3324dba8c..8b084c83d 100644 --- a/ipalib/plugins/role.py +++ b/ipalib/plugins/role.py @@ -134,7 +134,7 @@ class role_find(LDAPSearch): """ msg_summary = ngettext( - '%(count)d role matched', '%(count)d roles matched' + '%(count)d role matched', '%(count)d roles matched', 0 ) api.register(role_find) diff --git a/ipalib/plugins/selfservice.py b/ipalib/plugins/selfservice.py index 557304241..53dd1f8da 100644 --- a/ipalib/plugins/selfservice.py +++ b/ipalib/plugins/selfservice.py @@ -183,7 +183,7 @@ class selfservice_find(crud.Search): """ msg_summary = ngettext( - '%(count)d selfservice matched', '%(count)d selfservices matched' + '%(count)d selfservice matched', '%(count)d selfservices matched', 0 ) def execute(self, term, **kw): diff --git a/ipalib/plugins/service.py b/ipalib/plugins/service.py index 21889aa69..d39486c43 100644 --- a/ipalib/plugins/service.py +++ b/ipalib/plugins/service.py @@ -432,7 +432,7 @@ class service_find(LDAPSearch): Search for IPA services. """ msg_summary = ngettext( - '%(count)d service matched', '%(count)d services matched' + '%(count)d service matched', '%(count)d services matched', 0 ) member_attributes = ['managedby'] takes_options = LDAPSearch.takes_options diff --git a/ipalib/plugins/sudocmd.py b/ipalib/plugins/sudocmd.py index 528d79079..117865ea7 100644 --- a/ipalib/plugins/sudocmd.py +++ b/ipalib/plugins/sudocmd.py @@ -127,7 +127,7 @@ class sudocmd_find(LDAPSearch): """ msg_summary = ngettext( - '%(count)d sudo command matched', '%(count)d sudo command matched' + '%(count)d sudo command matched', '%(count)d sudo command matched', 0 ) api.register(sudocmd_find) diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py index ae730125d..aedcf4469 100644 --- a/ipalib/plugins/user.py +++ b/ipalib/plugins/user.py @@ -271,10 +271,9 @@ class user_add(LDAPCreate): if 'ipamaxusernamelength' in config: if len(keys[-1]) > int(config.get('ipamaxusernamelength')[0]): raise errors.ValidationError( - name=self.obj.primary_key.cli_name, error=_( - 'can be at most %(len)d characters' % dict( - len = int(config.get('ipamaxusernamelength')[0]) - ) + name=self.obj.primary_key.cli_name, + error=_('can be at most %(len)d characters') % dict( + len = int(config.get('ipamaxusernamelength')[0]) ) ) entry_attrs.setdefault('loginshell', config.get('ipadefaultloginshell')) diff --git a/ipalib/text.py b/ipalib/text.py index 060a6ddf5..a910cc5fb 100644 --- a/ipalib/text.py +++ b/ipalib/text.py @@ -488,10 +488,11 @@ class NGettextFactory(GettextFactory): *domain* (likely needed for 3rd-party plugins). """ - def __call__(self, singular, plural, count=0): + def __call__(self, singular, plural, count): return NGettext(singular, plural, self.domain, self.localedir) # Process wide factories: _ = GettextFactory() ngettext = NGettextFactory() +ugettext = _