[Checkins] SVN: van.potomo/ Yet another method of compiling .mo to .po files.
Brian Sutherland
jinty at web.de
Tue Mar 10 11:34:05 EDT 2009
Log message for revision 97804:
Yet another method of compiling .mo to .po files.
Changed:
A van.potomo/
A van.potomo/trunk/
A van.potomo/trunk/CHANGES.txt
A van.potomo/trunk/ZopePublicLicense.txt
A van.potomo/trunk/setup.py
A van.potomo/trunk/van/
A van.potomo/trunk/van/__init__.py
A van.potomo/trunk/van/potomo/
A van.potomo/trunk/van/potomo/README.txt
A van.potomo/trunk/van/potomo/__init__.py
-=-
Added: van.potomo/trunk/CHANGES.txt
===================================================================
--- van.potomo/trunk/CHANGES.txt (rev 0)
+++ van.potomo/trunk/CHANGES.txt 2009-03-10 15:34:04 UTC (rev 97804)
@@ -0,0 +1,12 @@
+Changes
+=======
+
+1.0.1 (unknown)
+------------------
+
+- New Feature XXX
+
+1.0.0 (2008-11-21)
+------------------
+
+- Initial Release
Property changes on: van.potomo/trunk/CHANGES.txt
___________________________________________________________________
Added: svn:eol-style
+ native
Added: van.potomo/trunk/ZopePublicLicense.txt
===================================================================
--- van.potomo/trunk/ZopePublicLicense.txt (rev 0)
+++ van.potomo/trunk/ZopePublicLicense.txt 2009-03-10 15:34:04 UTC (rev 97804)
@@ -0,0 +1,54 @@
+Zope Public License (ZPL) Version 2.1
+-------------------------------------
+
+A copyright notice accompanies this license document that
+identifies the copyright holders.
+
+This license has been certified as open source. It has also
+been designated as GPL compatible by the Free Software
+Foundation (FSF).
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the
+following conditions are met:
+
+1. Redistributions in source code must retain the
+ accompanying copyright notice, this list of conditions,
+ and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the accompanying
+ copyright notice, this list of conditions, and the
+ following disclaimer in the documentation and/or other
+ materials provided with the distribution.
+
+3. Names of the copyright holders must not be used to
+ endorse or promote products derived from this software
+ without prior written permission from the copyright
+ holders.
+
+4. The right to distribute this software or to use it for
+ any purpose does not give you the right to use
+ Servicemarks (sm) or Trademarks (tm) of the copyright
+ holders. Use of them is covered by separate agreement
+ with the copyright holders.
+
+5. If any files are modified, you must cause the modified
+ files to carry prominent notices stating that you changed
+ the files and the date of any change.
+
+Disclaimer
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS''
+ AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT
+ NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
+ NO EVENT SHALL THE COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ DAMAGE.
Property changes on: van.potomo/trunk/ZopePublicLicense.txt
___________________________________________________________________
Added: svn:eol-style
+ native
Added: van.potomo/trunk/setup.py
===================================================================
--- van.potomo/trunk/setup.py (rev 0)
+++ van.potomo/trunk/setup.py 2009-03-10 15:34:04 UTC (rev 97804)
@@ -0,0 +1,41 @@
+import os
+from setuptools import setup, find_packages
+
+long_description = (
+ '.. contents::\n\n'
+ + open(os.path.join('van', 'potomo', 'README.txt')).read()
+ + '\n\n'
+ + open(os.path.join('CHANGES.txt')).read()
+ )
+
+
+setup(name="van.potomo",
+ version='1.0.1dev',
+ license='ZPL 2.1',
+ url='http://pypi.python.org/pypi/van.potomo',
+ author_email='zope-dev at zope.org',
+ packages=find_packages(),
+ author="Vanguardistas LLC",
+ description="PO to MO build time compiler",
+ long_description=long_description,
+ namespace_packages=["van"],
+ install_requires = [
+ 'setuptools',
+ 'python-gettext'],
+ classifiers=[
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Zope Public License',
+ 'Framework :: Setuptools Plugin',
+ 'Programming Language :: Python',
+ 'Development Status :: 4 - Beta',
+ 'Operating System :: OS Independent',
+ 'Topic :: Software Development :: Build Tools',
+ ],
+
+ entry_points = """
+ [distutils.commands]
+ van_build_i18n = van.potomo:van_build_i18n
+ """,
+ include_package_data = True,
+ zip_safe = True,
+ )
Property changes on: van.potomo/trunk/setup.py
___________________________________________________________________
Added: svn:eol-style
+ native
Added: van.potomo/trunk/van/__init__.py
===================================================================
--- van.potomo/trunk/van/__init__.py (rev 0)
+++ van.potomo/trunk/van/__init__.py 2009-03-10 15:34:04 UTC (rev 97804)
@@ -0,0 +1,3 @@
+# this is a namespace package
+import pkg_resources
+pkg_resources.declare_namespace(__name__)
Property changes on: van.potomo/trunk/van/__init__.py
___________________________________________________________________
Added: svn:eol-style
+ native
Added: van.potomo/trunk/van/potomo/README.txt
===================================================================
--- van.potomo/trunk/van/potomo/README.txt (rev 0)
+++ van.potomo/trunk/van/potomo/README.txt 2009-03-10 15:34:04 UTC (rev 97804)
@@ -0,0 +1,59 @@
+Purpose
+=======
+
+This package integrates pure-python gettext translation compilation (msgfmt)
+into the setup.py "build" and "develop" commands.
+
+These commands are extended so that every "data file" identified by setuptools
+with the .po extension is compiled to a .mo file in the same directory as the
+.po file.
+
+This integrates very well if you use z3c.recipe.i18n (and hopefully others as
+well) to manage .po files.
+
+Usage
+=====
+
+You need to override the "build" and "develop" commands in your setup.py, for example::
+
+ from setuptools import setup, find_packages
+ from van.potomo import develop, build
+
+ setup(
+ name = "HelloWorld",
+ cmdclass={'build': build,
+ 'develop': develop},
+ setup_requires=["van.potomo"],
+ version = "0.1",
+ packages = find_packages(),
+ )
+
+Why
+===
+
+This package exists because the author believes that:
+
+* Compiled translations should not be stored under revision control, they are not source
+* Compiled translations should not be distributed in tarballs, they are not source
+* Compiled translations should not be "lazily compiled" unless you take into account that
+ filesystems on production machines are often read-only.
+* The process of compiling translations should not require an extra step/options during
+ the build/install or build/develop cycle.
+
+The options available at the time offered all of this:
+
+* Babel: Not integrated into the "build" distutils command.
+* cc.gettext: Depends on buildout, not useful for deployments by other means.
+* zope.i18n lazy compilation: Very nice for development, but not on some
+ production environments.
+
+
+Caveats
+=======
+
+van.potomo makes your setup.py depend on van.potomo. But outside tools cannot
+tell this because they need to run the setup.py to figure out the dependencies.
+
+Basically this means your developers/users will need to install van.potomo
+manually before anything else. If anyone knows a robust/good way to get around
+this limitation, please let the author know.
Property changes on: van.potomo/trunk/van/potomo/README.txt
___________________________________________________________________
Added: svn:eol-style
+ native
Added: van.potomo/trunk/van/potomo/__init__.py
===================================================================
--- van.potomo/trunk/van/potomo/__init__.py (rev 0)
+++ van.potomo/trunk/van/potomo/__init__.py 2009-03-10 15:34:04 UTC (rev 97804)
@@ -0,0 +1,78 @@
+##############################################################################
+#
+# Copyright (c) 2009 Vanguardistas LLC.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+import os
+
+from distutils.command.build import build as build_
+from setuptools.command.develop import develop as develop_
+from distutils.core import Command
+from pythongettext.msgfmt import Msgfmt
+
+class build(build_):
+
+ sub_commands = build_.sub_commands[:]
+ sub_commands.append(('van_build_i18n', None))
+
+
+class develop(develop_):
+
+ def install_for_development(self):
+ ei = self.get_finalized_command("egg_info")
+ sources = os.path.join(ei.egg_info, 'SOURCES.txt')
+ sources = open(sources, 'r').read().splitlines()
+ _compile_pofiles([s for s in sources if _is_pofile(s)])
+ return develop_.install_for_development(self)
+
+
+class van_build_i18n(Command):
+
+ def initialize_options(self):
+ pass
+
+ def finalize_options(self):
+ pass
+
+ def run(self):
+ build_py = self.get_finalized_command("build_py")
+ sources = []
+ for package, src_dir, build_dir, filenames in build_py.data_files:
+ for filename in filenames:
+ filename = os.path.join(build_dir, filename)
+ if _is_pofile(filename):
+ sources.append(filename)
+ _compile_pofiles(sources)
+
+def _is_pofile(filename):
+ if filename.endswith('.po'):
+ assert os.path.exists(filename)
+ return True
+ return False
+
+def _compile_pofiles(files):
+ for src in files:
+ dest = '%smo' % src[:-2]
+ if not os.path.exists(dest):
+ _compile(src, dest)
+ else:
+ src_mtime = os.stat(src)[8]
+ dest_mtime = os.stat(dest)[8]
+ if src_mtime > dest_mtime:
+ _compile(src, dest)
+
+def _compile(src, dest):
+ print 'Compiling %s to %s' % (src, dest)
+ f = open(dest, 'w')
+ try:
+ f.write(Msgfmt(src).get())
+ finally:
+ f.close()
Property changes on: van.potomo/trunk/van/potomo/__init__.py
___________________________________________________________________
Added: svn:eol-style
+ native
More information about the Checkins
mailing list