[Zope3-checkins] SVN: Zope3/trunk/ Added a ``-x dir`` option to i18nextract. This patch was originally made

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Jan 4 09:52:50 EST 2006


Log message for revision 41131:
  Added a ``-x dir`` option to i18nextract. This patch was originally made 
  by Simon Michael, who asks on his site (http://zopewiki.org/I18nextract) 
  to incorporate the fix. The latest patch was produced by Encolpe Degoute. 
  
  I had to fix the tests and actually the script was not working with the 
  patch, so I fixed that as well.
  
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/app/locales/extract.py
  U   Zope3/trunk/utilities/i18nextract.py
  U   Zope3/trunk/zopeskel/bin/i18nextract.in

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2006-01-04 13:15:00 UTC (rev 41130)
+++ Zope3/trunk/doc/CHANGES.txt	2006-01-04 14:52:50 UTC (rev 41131)
@@ -10,14 +10,17 @@
 
     New features
 
-      - Added a new API for collating text.  You can now adapt 
-        a locale to zope.i18n.interfaces.ILocales.ICollator.  You can
+      - Added ``-x dirs`` option to i18nextract that allows to exclude
+        particular directories from being searched.
+
+      - Added a new API for collating text.  You can now adapt
+        a locale to ``zope.i18n.interfaces.ILocales.ICollator``.  You can
         then use that to sort strings, such as menu entries, in a
         locale-specific fashion.
 
     Restructuring
 
-      - Removed unused menus and made previous titles, the description, 
+      - Removed unused menus and made previous titles, the description,
 	since they were awefully long. Then I created new, short titles.
 
     Bug Fixes
@@ -27,10 +30,10 @@
       - Fixed a Gadfly DB Adapter bug that was reported, fixed and tested by
         Tadashi Matsumoto.
 
-      - zope.app.content_types is now the package zope.app.contenttypes
-        (code backported from Zope 2)
+      - ``zope.app.content_types`` is now the package
+        ``zope.app.contenttypes`` (code backported from Zope 2)
 
-      - Fixed a bug in the <viewlet> directive handler: extra string
+      - Fixed a bug in the ``<viewlet>`` directive handler: extra string
         attributes were ignored if you didn't explicitly specify a
         class for the viewlet.
 
@@ -41,7 +44,7 @@
 
       Jim Fulton, Marius Gedminas, Brian Sutherland, Stephan Richter, Dimitry
       Vasiliev, Tim Peters, Zachery Bir, Gary Poster, Egon Frerich, Zhiyun
-      (Simon) Hang, Tadashi Matsumoto
+      (Simon) Hang, Tadashi Matsumoto, Simon Michael, Encople Degoute
 
   ------------------------------------------------------------------
 
@@ -52,7 +55,7 @@
         Zope 3 on windows.
 
       - Input buffering failed and caused Zope to hang when uploading
-        large files and using the Twisted server. 
+        large files and using the Twisted server.
 
       - Make zopetest insert rather than append the library path
         (fix spurious test failures from packages in site-packages)
@@ -70,7 +73,7 @@
 
     Bug Fixes
 
-      - Added input buffering to the twisted integration      
+      - Added input buffering to the twisted integration
 
       - Fixed the plumbing in ZServer so that attempts to return large
         output efficiently using iterators can actually succeed.

Modified: Zope3/trunk/src/zope/app/locales/extract.py
===================================================================
--- Zope3/trunk/src/zope/app/locales/extract.py	2006-01-04 13:15:00 UTC (rev 41130)
+++ Zope3/trunk/src/zope/app/locales/extract.py	2006-01-04 14:52:50 UTC (rev 41131)
@@ -84,7 +84,7 @@
     >>> entry.write(FakeFile())
     # Some comment
     #: path/file:10
-    # Default: "default"
+    #. Default: "default"
     msgid "test"
     msgstr ""
     <BLANKLINE>
@@ -93,9 +93,9 @@
 
     >>> entry = POTEntry(Message("test", default="\nline1\n\tline2"))
     >>> entry.write(FakeFile())
-    # Default: ""
-    #  "line1\n"
-    #  "\tline2"
+    #. Default: ""
+    #.  "line1\n"
+    #.  "\tline2"
     msgid "test"
     msgstr ""
     <BLANKLINE>
@@ -123,9 +123,9 @@
                self.msgid.default is not None):
             default = self.msgid.default.strip()
             lines = normalize(default).split("\n")
-            lines[0] = "# Default: %s\n" % lines[0]
+            lines[0] = "#. Default: %s\n" % lines[0]
             for i in range(1, len(lines)):
-                lines[i] = "#  %s\n" % lines[i]
+                lines[i] = "#.  %s\n" % lines[i]
             file.write("".join(lines))
         file.write('msgid %s\n' % normalize(self.msgid))
         file.write('msgstr ""\n')
@@ -341,6 +341,7 @@
     files = []
 
     def visit(files, dirname, names):
+        names[:] = filter(lambda x:x not in exclude, names)
         files += [os.path.join(dirname, name)
                   for name in fnmatch.filter(names, pattern)
                   if name not in exclude]
@@ -348,13 +349,13 @@
     os.path.walk(dir, visit, files)
     return files
 
-def py_strings(dir, domain="zope"):
+def py_strings(dir, domain="zope", exclude=()):
     """Retrieve all Python messages from `dir` that are in the `domain`.
     """
     eater = TokenEater()
     make_escapes(0)
-    for filename in find_files(dir, '*.py',
-                               exclude=('extract.py', 'pygettext.py')):
+    for filename in find_files(
+            dir, '*.py', exclude=('extract.py', 'pygettext.py')+tuple(exclude)):
         fp = open(filename)
         try:
             eater.set_filename(filename)
@@ -384,7 +385,7 @@
     context = config(site_zcml, features=("devmode",), execute=False)
     return context.i18n_strings.get(domain, {})
 
-def tal_strings(dir, domain="zope", include_default_domain=False):
+def tal_strings(dir, domain="zope", include_default_domain=False, exclude=()):
     """Retrieve all TAL messages from `dir` that are in the `domain`.
     """
     # We import zope.tal.talgettext here because we can't rely on the
@@ -397,7 +398,7 @@
         def write(self, s):
             pass
 
-    for filename in find_files(dir, '*.pt'):
+    for filename in find_files(dir, '*.pt', exclude=tuple(exclude)):
         try:
             engine.file = filename
             p = HTMLTALParser()

Modified: Zope3/trunk/utilities/i18nextract.py
===================================================================
--- Zope3/trunk/utilities/i18nextract.py	2006-01-04 13:15:00 UTC (rev 41130)
+++ Zope3/trunk/utilities/i18nextract.py	2006-01-04 14:52:50 UTC (rev 41131)
@@ -40,6 +40,9 @@
     -o dir
         Specifies a directory, relative to the package in which to put the
         output translation template.
+    -x dir
+        Specifies a directory, relative to the package, to exclude.
+        May be used more than once.
 
 $Id$
 """
@@ -81,7 +84,7 @@
     try:
         opts, args = getopt.getopt(
             sys.argv[1:],
-            'hd:p:o:',
+            'hd:p:o:x:',
             ['help', 'domain=', 'path=', 'python-only'])
     except getopt.error, msg:
         usage(1, msg)
@@ -90,6 +93,7 @@
     path = app_dir()
     include_default_domain = True
     output_dir = None
+    exclude_dirs = []
     python_only = None
     for opt, arg in opts:
         if opt in ('-h', '--help'):
@@ -99,6 +103,8 @@
             include_default_domain = False
         elif opt in ('-o', ):
             output_dir = arg
+        elif opt in ('-x', ):
+            exclude_dirs.append(arg)
         elif opt in ('--python-only',):
             python_only = True
         elif opt in ('-p', '--path'):
@@ -125,17 +131,22 @@
             os.mkdir(output_dir)
         output_file = os.path.join(output_dir, output_file)
 
-    print "base path: %r\nsearch path: %r\ndomain: %r\noutput file: %r" \
-        % (base_dir, path, domain, output_file)
+    print "base path: %r\n" \
+          "search path: %s\n" \
+          "exclude dirs: %r\n" \
+          "domain: %r\n" \
+          "output file: %r" \
+          % (base_dir, path, exclude_dirs, domain, output_file)
 
     from zope.app.locales.extract import POTMaker, \
          py_strings, tal_strings, zcml_strings
 
     maker = POTMaker(output_file, path)
-    maker.add(py_strings(path, domain), base_dir)
+    maker.add(py_strings(path, domain, exclude=exclude_dirs), base_dir)
     if not python_only:
         maker.add(zcml_strings(path, domain), base_dir)
-        maker.add(tal_strings(path, domain, include_default_domain), base_dir)
+        maker.add(tal_strings(path, domain, include_default_domain,
+                              exclude=exclude_dirs), base_dir)
     maker.write()
 
 if __name__ == '__main__':

Modified: Zope3/trunk/zopeskel/bin/i18nextract.in
===================================================================
--- Zope3/trunk/zopeskel/bin/i18nextract.in	2006-01-04 13:15:00 UTC (rev 41130)
+++ Zope3/trunk/zopeskel/bin/i18nextract.in	2006-01-04 14:52:50 UTC (rev 41131)
@@ -40,6 +40,9 @@
     -o dir
         Specifies a directory, relative to the package in which to put the
         output translation template.
+    -x dir
+        Specifies a directory, relative to the package, to exclude.
+        May be used more than once.
 
 $Id$
 """
@@ -83,7 +86,7 @@
     try:
         opts, args = getopt.getopt(
             sys.argv[1:],
-            'hd:p:o:',
+            'hd:p:o:x:',
             ['help', 'domain=', 'path=', 'python-only'])
     except getopt.error, msg:
         usage(1, msg)
@@ -92,6 +95,7 @@
     path = app_dir()
     include_default_domain = True
     output_dir = None
+    exclude_dirs = []
     python_only = None
     for opt, arg in opts:
         if opt in ('-h', '--help'):
@@ -101,6 +105,8 @@
             include_default_domain = False
         elif opt in ('-o', ):
             output_dir = arg
+        elif opt in ('-x', ):
+            exclude_dirs.append(arg)
         elif opt in ('--python-only',):
             python_only = True
         elif opt in ('-p', '--path'):
@@ -127,18 +133,18 @@
             os.mkdir(output_dir)
         output_file = os.path.join(output_dir, output_file)
 
-    print "base path: %r\nsearch path: %r\ndomain: %r\noutput file: %r" \
-        % (base_dir, path, domain, output_file)
+    print "base path: %r\nsearch path: %s\nexclude dirs: %r\ndomain: %r\noutput file: %r" \
+        % (base_dir, path, exclude_dirs, domain, output_file)
 
     from zope.app.locales.extract import POTMaker, \
          py_strings, tal_strings, zcml_strings
 
     maker = POTMaker(output_file, path)
-    maker.add(py_strings(path, domain), base_dir)
+    maker.add(py_strings(path, domain, exclude=exclude_dirs), base_dir)
     if not python_only:
         site_zcml = os.path.join(INSTANCE_HOME, 'etc', 'site.zcml')
         maker.add(zcml_strings(path, domain, site_zcml), base_dir)
-        maker.add(tal_strings(path, domain, include_default_domain), base_dir)
+        maker.add(tal_strings(path, domain, include_default_domain, exclude=exclude_dirs), base_dir)
     maker.write()
 
 



More information about the Zope3-Checkins mailing list