/usr/lib/python2.7/dist-packages/zope/i18n/compile.py is in python-zope.i18n 4.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import logging
import os
from os.path import join
from stat import ST_MTIME
HAS_PYTHON_GETTEXT = True
try:
from pythongettext.msgfmt import Msgfmt
from pythongettext.msgfmt import PoSyntaxError
except ImportError:
HAS_PYTHON_GETTEXT = False
logger = logging.getLogger('zope.i18n')
def compile_mo_file(domain, lc_messages_path):
"""Creates or updates a mo file in the locales folder."""
base = join(lc_messages_path, domain)
pofile = str(base + '.po')
mofile = str(base + '.mo')
if not HAS_PYTHON_GETTEXT:
#logger.critical("Unable to compile messages: Python `gettext` library missing.")
# 2015-06-22 barry@debian.org: Fall back to msgfmt(1).
from subprocess import check_call
check_call(['msgfmt', '-o', mofile, pofile])
return
po_mtime = 0
try:
po_mtime = os.stat(pofile)[ST_MTIME]
except (IOError, OSError):
return
mo_mtime = 0
if os.path.exists(mofile):
# Update mo file?
try:
mo_mtime = os.stat(mofile)[ST_MTIME]
except (IOError, OSError):
return
if po_mtime > mo_mtime:
try:
mo = Msgfmt(pofile, domain).getAsFile()
fd = open(mofile, 'wb')
fd.write(mo.read())
fd.close()
except (IOError, OSError, PoSyntaxError):
logger.warn('Error while compiling %s' % pofile)
|