[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    l10n-support/pology/scripts
From:       Chusslove Illich <caslav.ilic () gmx ! net>
Date:       2010-09-22 13:42:07
Message-ID: 20100922134207.132DFAC888 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1178241 by ilic:

Documentation moved to the user manual. Sorted option lists. Switched to common input file functionality.

 M  +16 -58    porewrap.py  
 M  +33 -35    poselfmerge.py  


--- trunk/l10n-support/pology/scripts/porewrap.py #1178240:1178241
@@ -2,49 +2,10 @@
 # -*- coding: UTF-8 -*-
 
 """
-Rewrap keyword text fields in PO files.
+Rewrap message strings in PO files.
 
-Keyword text fields (C{msgid}, C{msgstr}, etc.) in PO files may be wrapped
-in arbitrary fashion, without changing their semantics.
-(Unlike extracted or translator comments, where it is not safe to assume
-that line breaks are not significant.)
+Documented in C{doc/user/misctools.docbook#sec-mirewrap}.
 
-Pology can wrap keyword text fields on newline characters only,
-on certain column width, and on various logical breaks
-(e.g. paragraph tags in markup text).
-By default, this script applies all known wrapping types,
-but the wrapping policy can be controlled from several sources:
-  - command line options C{--wrap} and C{--no-wrap} enable or disable
-    wrapping on column, and C{--fine-wrap}/C{--no-fine-wrap} wrapping
-    on logical breaks;
-  - L{configuration fields<config>} C{[porewrap]/wrap}
-    and C{[porewrap]/fine-wrap} may be set to C{yes} or C{no},
-    corresponding to previous command line options;
-  - catalogs themselves may state what wrapping should be applied.
-
-Catalogs can state wrapping policy through C{Wrapping} or C{X-Wrapping}
-header fields. The value is a comma-separated list of wrapping type
-keywords, which currently can be: C{basic} (wrapping on column),
-C{fine} (wrapping on logical breaks).
-For example, not to wrap on column but to wrap on logical breaks::
-
-    msgid ""
-    msgstr ""
-    "..."
-    "X-Wrapping: fine\\n"
-    "..."
-
-To specify wrapping within the catalog is advantageous when more people
-may be working on it, so that it does not go through constant rewrappings.
-Unless told otherwise, all Pology tools will by default recognize and apply
-wrapping policy specified like this.
-
-In case when wrapping policies from different sources conflict,
-this script decides wrapping policy for a given catalog with following
-increasing priority: user configuration, catalog header
-(overrides configuration), command line (overrides both configuration
-and header).
-
 @author: Chusslove Illich (Часлав Илић) <caslav.ilic@gmx.net>
 @license: GPLv3
 """
@@ -59,8 +20,9 @@
 from pology.catalog import Catalog
 from pology.colors import ColorOptionParser
 import pology.config as pology_config
-from pology.fsops import collect_catalogs
+from pology.fsops import collect_paths_cmdline, collect_catalogs
 from pology.report import report, error
+from pology.stdcmdopt import add_cmdopt_filesfrom
 
 
 def main ():
@@ -75,7 +37,7 @@
         "%(cmd)s [options] POFILE...",
         cmd="%prog")
     desc = _("@info command description",
-        "Rewrap keyword text fields in PO files.")
+        "Rewrap message strings in PO files.")
     ver = _("@info command version",
         u"%(cmd)s (Pology) %(version)s\n"
         u"Copyright   2007, 2008, 2009, 2010 "
@@ -84,17 +46,12 @@
 
     opars = ColorOptionParser(usage=usage, description=desc, version=ver)
     opars.add_option(
-        "-f", "--files-from",
-        metavar=_("@info command line value placeholder", "FILE"),
-        dest="files_from",
-        help=_("@info command line option description",
-               "Get list of input files from a file (one path per line)."))
-    add_wrapping_options(opars)
-    opars.add_option(
         "-v", "--verbose",
         action="store_true", dest="verbose", default=False,
         help=_("@info command line option description",
-               "Output more detailed progress info."))
+               "More detailed progress information."))
+    add_wrapping_options(opars)
+    add_cmdopt_filesfrom(opars)
 
     (op, fargs) = opars.parse_args()
 
@@ -109,11 +66,10 @@
         pass
 
     # Assemble list of files.
-    file_or_dir_paths = fargs
-    if op.files_from:
-        flines = open(op.files_from, "r").readlines()
-        file_or_dir_paths.extend([f.rstrip("\n") for f in flines])
-    fnames = collect_catalogs(file_or_dir_paths)
+    fnames = collect_paths_cmdline(rawpaths=fargs,
+                                   filesfrom=op.files_from,
+                                   respathf=collect_catalogs,
+                                   abort=True)
 
     # Rewrap all catalogs.
     for fname in fnames:
@@ -125,6 +81,7 @@
         cat.sync(force=True)
 
 
+# FIXME: Move to pology.stdcmdopt.
 def add_wrapping_options (opars):
 
     opars.add_option(
@@ -149,10 +106,11 @@
                "No fine wrapping."))
 
 
+# FIXME: Move to pology.?.
 def select_field_wrapping (cfgsec=None, cat=None, cmlopt=None):
 
-    # Select maximum wrapping initially.
-    wrapping = ["basic", "fine"]
+    # Default wrapping.
+    wrapping = ["basic"]
 
     # Helper to remove and add wrapping types.
     def waddrem (add, wtype):
--- trunk/l10n-support/pology/scripts/poselfmerge.py #1178240:1178241
@@ -2,8 +2,11 @@
 # -*- coding: UTF-8 -*-
 
 """
-Merge PO file with itself, to produce fuzzy matches on similar messages.
+Merge PO file with itself or compendium,
+to produce fuzzy matches on similar messages.
 
+Documented in C{doc/user/misctools.docbook#sec-miselfmerge}.
+
 @author: Chusslove Illich (Часлав Илић) <caslav.ilic@gmx.net>
 @license: GPLv3
 """
@@ -20,9 +23,10 @@
 from pology.message import MessageUnsafe
 from pology.colors import ColorOptionParser
 import pology.config as pology_config
-from pology.fsops import collect_catalogs
+from pology.fsops import collect_paths_cmdline, collect_catalogs
 from pology.merge import merge_pofile
 from pology.report import report, error
+from pology.stdcmdopt import add_cmdopt_filesfrom
 
 import porewrap as REW
 
@@ -53,12 +57,21 @@
 
     opars = ColorOptionParser(usage=usage, description=desc, version=ver)
     opars.add_option(
-        "-f", "--files-from",
-        metavar=_("@info command line value placeholder", "FILE"),
-        dest="files_from",
+        "-A", "--min-adjsim-fuzzy",
+        metavar=_("@info command line value placeholder", "RATIO"),
+        action="store", dest="min_adjsim_fuzzy", default=def_minasfz,
         help=_("@info command line option description",
-               "Get list of input files from a file (one path per line)."))
+               "On fuzzy matches, the minimum adjusted similarity "
+               "to accept the match, or else the message is left untranslated. "
+               "Range is 0.0-1.0, where 0 means always to accept the match, "
+               "and 1 never to accept; a practical range is 0.6-0.8."))
     opars.add_option(
+        "-b", "--rebase-fuzzies",
+        action="store_true", dest="rebase_fuzzies", default=def_refuzz,
+        help=_("@info command line option description",
+               "Before merging, clear those fuzzy messages whose predecessor "
+               "(determined by previous fields) is still in the catalog."))
+    opars.add_option(
         "-C", "--compendium",
         metavar=_("@info command line value placeholder", "POFILE"),
         action="append", dest="compendiums", default=[],
@@ -66,6 +79,11 @@
                "Catalog with existing translations, to additionally use for "
                "direct and fuzzy matches. Can be repeated."))
     opars.add_option(
+        "-v", "--verbose",
+        action="store_true", dest="verbose", default=False,
+        help=_("@info command line option description",
+               "More detailed progress information."))
+    opars.add_option(
         "-W", "--min-words-exact",
         metavar=_("@info command line value placeholder", "NUMBER"),
         action="store", dest="min_words_exact", default=def_minwnex,
@@ -75,31 +93,12 @@
                "to accept translation without making it fuzzy. "
                "Zero means to always accept an exact match."))
     opars.add_option(
-        "-A", "--min-adjsim-fuzzy",
-        metavar=_("@info command line value placeholder", "NUMBER"),
-        action="store", dest="min_adjsim_fuzzy", default=def_minasfz,
-        help=_("@info command line option description",
-               "When using compendium, in case of fuzzy match, "
-               "minimum adjusted similarity to accept the match. "
-               "Range is 0.0-1.0, where 0 means always to accept the match, "
-               "and 1 never to accept; a convenient range is 0.6-0.8."))
-    opars.add_option(
         "-x", "--fuzzy-exact",
         action="store_true", dest="fuzzy_exact", default=def_fuzzex,
         help=_("@info command line option description",
                "When using compendium, make all exact matches fuzzy."))
-    opars.add_option(
-        "-b", "--rebase-fuzzies",
-        action="store_true", dest="rebase_fuzzies", default=def_refuzz,
-        help=_("@info command line option description",
-               "Before merging, clear those fuzzy messages whose predecessor "
-               "(determined by previous fields) is still in the catalog."))
-    opars.add_option(
-        "-v", "--verbose",
-        action="store_true", dest="verbose", default=False,
-        help=_("@info command line option description",
-               "Output more detailed progress info."))
     REW.add_wrapping_options(opars)
+    add_cmdopt_filesfrom(opars)
 
     (op, fargs) = opars.parse_args()
 
@@ -113,29 +112,28 @@
     except ImportError:
         pass
 
-    # Assemble list of files.
-    file_or_dir_paths = fargs
-    if op.files_from:
-        flines = open(op.files_from, "r").readlines()
-        file_or_dir_paths.extend([f.rstrip("\n") for f in flines])
-    fnames = collect_catalogs(file_or_dir_paths)
-
     # Convert non-string options to needed types.
     try:
         op.min_words_exact = int(op.min_words_exact)
     except:
         error(_("@info",
                 "Value to option %(opt)s must be an integer number, "
-                "given '%(val)s' instead).",
+                "given '%(val)s' instead.",
                 opt="--min-words-exact", val=op.min_words_exact))
     try:
         op.min_adjsim_fuzzy = float(op.min_adjsim_fuzzy)
     except:
         error(_("@info",
                 "Value to option %(opt)s must be a real number, "
-                "given '%(val)s' instead).",
+                "given '%(val)s' instead.",
                 opt="--min-adjsim-fuzzy", val=op.min_ajdsim_fuzzy))
 
+    # Assemble list of files.
+    fnames = collect_paths_cmdline(rawpaths=fargs,
+                                   filesfrom=op.files_from,
+                                   respathf=collect_catalogs,
+                                   abort=True)
+
     # Self-merge all catalogs.
     for fname in fnames:
         if op.verbose:
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic