diff options
author | John Dennis <jdennis@redhat.com> | 2011-08-24 22:48:30 -0400 |
---|---|---|
committer | Rob Crittenden <rcritten@redhat.com> | 2011-08-24 23:13:16 -0400 |
commit | 1b4eab0411cd4e669e3bd18541f5736c9aa81467 (patch) | |
tree | 55e54f7879165508f770adb9615b1b5bd8c4c885 /ipalib/plugins/dns.py | |
parent | 7746e22fe7da42d6e221770c93f1926e92343965 (diff) | |
download | freeipa-1b4eab0411cd4e669e3bd18541f5736c9aa81467.tar.gz freeipa-1b4eab0411cd4e669e3bd18541f5736c9aa81467.tar.xz freeipa-1b4eab0411cd4e669e3bd18541f5736c9aa81467.zip |
ticket 1669 - improve i18n docstring extraction
This patch reverts the use of pygettext for i18n string extraction. It
was originally introduced because the help documentation for commands
are in the class docstring and module docstring.
Docstrings are a Python construct whereby any string which immediately
follows a class declaration, function/method declaration or appears
first in a module is taken to be the documentation for that
object. Python automatically assigns that string to the __doc__
variable associated with the object. Explicitly assigning to the
__doc__ variable is equivalent and permitted.
We mark strings in the source for i18n translation by embedding them
in _() or ngettext(). Specialized extraction tools (e.g. xgettext)
scan the source code looking for strings with those markers and
extracts the string for inclusion in a translation catalog.
It was mistakingly assumed one could not mark for translation Python
docstrings. Since some docstrings are vital for our command help
system some method had to be devised to extract docstrings for the
translation catalog. pygettext has the ability to locate and extract
docstrings and it was introduced to acquire the documentation for our
commands located in module and class docstrings.
However pygettext was too large a hammer for this task, it lacked any
fined grained ability to extract only the docstrings we were
interested in. In practice it extracted EVERY docstring in each file
it was presented with. This caused a large number strings to be
extracted for translation which had no reason to be translated, the
string might have been internal code documentation never meant to be
seen by users. Often the superfluous docstrings were long, complex and
likely difficult to translate. This placed an unnecessary burden on
our volunteer translators.
Instead what is needed is some method to extract only those strings
intended for translation. We already have such a mechanism and it is
already widely used, namely wrapping strings intended for translation
in calls to _() or _negettext(), i.e. marking a string for i18n
translation. Thus the solution to the docstring translation problem is
to mark the docstrings exactly as we have been doing, it only requires
that instead of a bare Python docstring we instead assign the marked
string to the __doc__ variable. Using the hypothetical class foo as
an example.
class foo(Command):
'''
The foo command takes out the garbage.
'''
Would become:
class foo(Command):
__doc__ = _('The foo command takes out the garbage.')
But which docstrings need to be marked for translation? The makeapi
tool knows how to iterate over every command in our public API. It was
extended to validate every command's documentation and report if any
documentation is missing or not marked for translation. That
information was then used to identify each docstring in the code which
needed to be transformed.
In summary what this patch does is:
* Remove the use of pygettext (modification to install/po/Makefile.in)
* Replace every docstring with an explicit assignment to __doc__ where
the rhs of the assignment is an i18n marking function.
* Single line docstrings appearing in multi-line string literals
(e.g. ''' or """) were replaced with single line string literals
because the multi-line literals were introducing unnecessary
whitespace and newlines in the string extracted for translation. For
example:
'''
The foo command takes out the garbage.
'''
Would appear in the translation catalog as:
"\n
The foo command takes out the garbage.\n
"
The superfluous whitespace and newlines are confusing to translators
and requires us to strip leading and trailing whitespace from the
translation at run time.
* Import statements were moved from below the docstring to above
it. This was necessary because the i18n markers are imported
functions and must be available before the the doc is
parsed. Technically only the import of the i18n markers had to
appear before the doc but stylistically it's better to keep all the
imports together.
* It was observed during the docstring editing process that the
command documentation was inconsistent with respect to the use of
periods to terminate a sentence. Some doc had a trailing period,
others didn't. Consistency was enforced by adding a period to end of
every docstring if one was missing.
Diffstat (limited to 'ipalib/plugins/dns.py')
-rw-r--r-- | ipalib/plugins/dns.py | 92 |
1 files changed, 39 insertions, 53 deletions
diff --git a/ipalib/plugins/dns.py b/ipalib/plugins/dns.py index b4eee113..d922cdfb 100644 --- a/ipalib/plugins/dns.py +++ b/ipalib/plugins/dns.py @@ -17,7 +17,20 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -""" + +import netaddr +import time + +from ipalib import api, errors, output +from ipalib import Command +from ipalib import Flag, Int, List, Str, StrEnum +from ipalib.plugins.baseldap import * +from ipalib import _, ngettext +from ipapython import dnsclient +from ipapython.ipautil import valid_ip +from ldap import explode_dn + +__doc__ = _(""" Domain Name System (DNS) Manage DNS zone and resource records. @@ -98,19 +111,7 @@ EXAMPLES: if one is not included): ipa dns-resolve www.example.com ipa dns-resolve www -""" - -import netaddr -import time - -from ipalib import api, errors, output -from ipalib import Command -from ipalib import Flag, Int, List, Str, StrEnum -from ipalib.plugins.baseldap import * -from ipalib import _, ngettext -from ipapython import dnsclient -from ipapython.ipautil import valid_ip -from ldap import explode_dn +""") # supported resource record types _record_types = ( @@ -404,9 +405,8 @@ api.register(dnszone) class dnszone_add(LDAPCreate): - """ - Create new DNS zone (SOA record). - """ + __doc__ = _('Create new DNS zone (SOA record).') + takes_options = LDAPCreate.takes_options + ( Flag('force', label=_('Force'), @@ -461,17 +461,14 @@ api.register(dnszone_add) class dnszone_del(LDAPDelete): - """ - Delete DNS zone (SOA record). - """ + __doc__ = _('Delete DNS zone (SOA record).') api.register(dnszone_del) class dnszone_mod(LDAPUpdate): - """ - Modify DNS zone (SOA record). - """ + __doc__ = _('Modify DNS zone (SOA record).') + def pre_callback(self, ldap, dn, entry_attrs, *keys, **options): if 'name_from_ip' in entry_attrs: del entry_attrs['name_from_ip'] @@ -484,9 +481,8 @@ api.register(dnszone_mod) class dnszone_find(LDAPSearch): - """ - Search for DNS zones (SOA records). - """ + __doc__ = _('Search for DNS zones (SOA records).') + def args_options_2_entry(self, *args, **options): if 'name_from_ip' in options: if 'idnsname' not in options: @@ -517,17 +513,14 @@ api.register(dnszone_find) class dnszone_show(LDAPRetrieve): - """ - Display information about a DNS zone (SOA record). - """ + __doc__ = _('Display information about a DNS zone (SOA record).') api.register(dnszone_show) class dnszone_disable(LDAPQuery): - """ - Disable DNS Zone. - """ + __doc__ = _('Disable DNS Zone.') + has_output = output.standard_value msg_summary = _('Disabled DNS zone "%(value)s"') @@ -547,9 +540,8 @@ api.register(dnszone_disable) class dnszone_enable(LDAPQuery): - """ - Enable DNS Zone. - """ + __doc__ = _('Enable DNS Zone.') + has_output = output.standard_value msg_summary = _('Enabled DNS zone "%(value)s"') @@ -804,9 +796,8 @@ api.register(dnsrecord_add_record) class dnsrecord_add(LDAPCreate, dnsrecord_cmd_w_record_options): - """ - Add new DNS resource record. - """ + __doc__ = _('Add new DNS resource record.') + no_option_msg = 'No options to add a specific record provided.\n' \ "Command help may be consulted for all supported record types." takes_options = LDAPCreate.takes_options + ( @@ -866,9 +857,8 @@ api.register(dnsrecord_add) class dnsrecord_mod(dnsrecord_mod_record): - """ - Modify a DNS resource record. - """ + __doc__ = _('Modify a DNS resource record.') + no_option_msg = 'No options to modify a specific record provided.' def update_old_entry_callback(self, entry_attrs, old_entry_attrs): @@ -914,9 +904,8 @@ api.register(dnsrecord_delentry) class dnsrecord_del(dnsrecord_mod_record): - """ - Delete DNS resource record. - """ + __doc__ = _('Delete DNS resource record.') + no_option_msg = _('Neither --del-all nor options to delete a specific record provided.\n'\ "Command help may be consulted for all supported record types.") takes_options = ( @@ -1003,9 +992,8 @@ api.register(dnsrecord_del) class dnsrecord_show(LDAPRetrieve, dnsrecord_cmd_w_record_options): - """ - Display DNS resource. - """ + __doc__ = _('Display DNS resource.') + def has_output_params(self): for option in self.get_record_options(): yield option @@ -1019,9 +1007,8 @@ api.register(dnsrecord_show) class dnsrecord_find(LDAPSearch, dnsrecord_cmd_w_record_options): - """ - Search for DNS resources. - """ + __doc__ = _('Search for DNS resources.') + def get_options(self): for option in super(dnsrecord_find, self).get_options(): yield option @@ -1046,9 +1033,8 @@ class dnsrecord_find(LDAPSearch, dnsrecord_cmd_w_record_options): api.register(dnsrecord_find) class dns_resolve(Command): - """ - Resolve a host name in DNS - """ + __doc__ = _('Resolve a host name in DNS.') + has_output = output.standard_value msg_summary = _('Found \'%(value)s\'') |