[Checkins] SVN: z3c.recipe.i18n/trunk/ - added new 'headerTemplate' option
Yvo Schubbe
y.2009 at wcm-solutions.de
Sun Jul 19 10:25:20 EDT 2009
Log message for revision 102019:
- added new 'headerTemplate' option
Changed:
U z3c.recipe.i18n/trunk/CHANGES.txt
U z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/README.txt
U z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18n.py
U z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18nextract.py
-=-
Modified: z3c.recipe.i18n/trunk/CHANGES.txt
===================================================================
--- z3c.recipe.i18n/trunk/CHANGES.txt 2009-07-19 14:19:07 UTC (rev 102018)
+++ z3c.recipe.i18n/trunk/CHANGES.txt 2009-07-19 14:25:20 UTC (rev 102019)
@@ -5,6 +5,9 @@
0.5.5 (unreleased)
------------------
+- Feature: Added new 'headerTemplate' option that allows to specify the path
+ of a customized pot header template.
+
- Makers are now called with additional keyword arguments.
- Fixed dependencies: The 'extract' extra of zope.app.locales is required.
Modified: z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/README.txt
===================================================================
--- z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/README.txt 2009-07-19 14:19:07 UTC (rev 102018)
+++ z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/README.txt 2009-07-19 14:25:20 UTC (rev 102019)
@@ -67,6 +67,9 @@
Allows to specify one or more directory name, relative to the package, to
exclude. (None if not used)
+headerTemplate (optional, default=None)
+ The path of the pot header template relative to the buildout directory.
+
environment
A section name defining a set of environment variables that should be
exported before starting the tests. Can be used for set product
@@ -238,6 +241,7 @@
... pythonOnly = true
... exludeDirectoryName = foo
... bar
+ ... headerTemplate = pot_header.txt
... environment = testenv
... ''' % globals())
@@ -282,7 +286,7 @@
import z3c.recipe.i18n.i18nextract
<BLANKLINE>
if __name__ == '__main__':
- z3c.recipe.i18n.i18nextract.main(['i18nextract', '-d', 'recipe', '-s', '/sample-buildout/parts/i18n/configure.zcml', '-o', '/sample-buildout/outputDir', '--exclude-default-domain', '--python-only', '-m', 'z3c.csvvocabulary.csvStrings', '-p', 'demo1', '-x', 'foo', '-x', 'bar'])
+ z3c.recipe.i18n.i18nextract.main(['i18nextract', '-d', 'recipe', '-s', '/sample-buildout/parts/i18n/configure.zcml', '-o', '/sample-buildout/outputDir', '--exclude-default-domain', '--python-only', '-m', 'z3c.csvvocabulary.csvStrings', '-p', 'demo1', '-x', 'foo', '-x', 'bar', '-t', '/sample-buildout/pot_header.txt'])
i18nmergeall
------------
Modified: z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18n.py
===================================================================
--- z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18n.py 2009-07-19 14:19:07 UTC (rev 102018)
+++ z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18n.py 2009-07-19 14:25:20 UTC (rev 102019)
@@ -12,7 +12,7 @@
#
##############################################################################
"""
-$Id:$
+$Id$
"""
__docformat__ = 'restructuredtext'
@@ -124,6 +124,13 @@
for x in exludeDirNames:
arguments.extend(['-x', x])
+ header_template = self.options.get('headerTemplate', None)
+ if header_template is not None:
+ header_template = os.path.normpath(
+ os.path.join(self.buildout['buildout']['directory'],
+ header_template.strip()))
+ arguments.extend(['-t', header_template])
+
initialization = initialization_template % this_loc
env_section = self.options.get('environment', '').strip()
if env_section:
Modified: z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18nextract.py
===================================================================
--- z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18nextract.py 2009-07-19 14:19:07 UTC (rev 102018)
+++ z3c.recipe.i18n/trunk/src/z3c/recipe/i18n/i18nextract.py 2009-07-19 14:25:20 UTC (rev 102019)
@@ -53,13 +53,61 @@
May be used more than once.
--python-only
Only extract message ids from Python
+ -t <path>
+ Specifies the file path of the header template.
-$Id:$
+$Id$
"""
+import os, sys, getopt
+import time
+
+from zope.app.locales.extract import DEFAULT_CHARSET
+from zope.app.locales.extract import DEFAULT_ENCODING
+from zope.app.locales.extract import pot_header as _DEFAULT_POT_HEADER
+from zope.app.locales.extract import POTMaker
+from zope.app.locales.extract import py_strings
+from zope.app.locales.extract import tal_strings
from zope.configuration.name import resolve
-import os, sys, getopt
+
+class POTMaker(POTMaker):
+ """This class inserts sets of strings into a POT file.
+ """
+
+ def __init__ (self, output_fn, path, header_template=None):
+ self._output_filename = output_fn
+ self.path = path
+ if header_template is not None and os.path.exists(header_template):
+ file = open(header_template, 'r')
+ try:
+ self._pot_header = file.read()
+ finally:
+ file.close()
+ else:
+ self._pot_header = _DEFAULT_POT_HEADER
+ self.catalog = {}
+
+ def write(self):
+ pot_header = self._pot_header
+
+ file = open(self._output_filename, 'w')
+ file.write(pot_header % {'time': time.ctime(),
+ 'version': self._getProductVersion(),
+ 'charset': DEFAULT_CHARSET,
+ 'encoding': DEFAULT_ENCODING})
+
+ # Sort the catalog entries by filename
+ catalog = self.catalog.values()
+ catalog.sort()
+
+ # Write each entry to the file
+ for entry in catalog:
+ entry.write(file)
+
+ file.close()
+
+
def usage(code, msg=''):
# Python 2.1 required
print >> sys.stderr, __doc__
@@ -101,7 +149,7 @@
try:
opts, args = getopt.getopt(
argv[1:],
- 'hed:s:i:m:p:o:x:',
+ 'hed:s:i:m:p:o:x:t:',
['help', 'domain=', 'site_zcml=', 'path=', 'python-only',
'exclude-default-domain'])
except getopt.error, msg:
@@ -115,6 +163,7 @@
site_zcml = None
makers = []
eggPaths = []
+ header_template = None
for opt, arg in opts:
if opt in ('-h', '--help'):
usage(0)
@@ -138,6 +187,10 @@
if not os.path.exists(path):
usage(1, 'The specified path does not exist.')
eggPaths.append((arg, path))
+ elif opt in ('-t', ):
+ if not os.path.exists(arg):
+ usage(1, 'The specified header template does not exist.')
+ header_template = arg
# setup output file
output_file = domain+'.pot'
@@ -151,15 +204,12 @@
"exclude dirs: %r\n" \
"include default domain: %r\n" \
"python only: %r\n" \
+ "header template: %r\n" \
% (domain, site_zcml, exclude_dirs, include_default_domain,
- python_only)
+ python_only, header_template)
- from zope.app.locales.extract import POTMaker
- from zope.app.locales.extract import py_strings
- from zope.app.locales.extract import tal_strings
-
# setup pot maker
- maker = POTMaker(output_file, '')
+ maker = POTMaker(output_file, '', header_template)
# add maker for each given path
for pkgName, path in eggPaths:
More information about the Checkins
mailing list