setup: Refactor babel compile_catalog integration
This commit is contained in:
parent
a298022563
commit
25ce1b16e0
94
setup.py
94
setup.py
|
@ -16,8 +16,9 @@ import platform
|
||||||
|
|
||||||
from terminatorlib.version import APP_NAME, APP_VERSION
|
from terminatorlib.version import APP_NAME, APP_VERSION
|
||||||
|
|
||||||
PO_DIR = 'po'
|
GETTEXT_SOURCE = 'po'
|
||||||
MO_DIR = os.path.join('build', 'mo')
|
GETTEXT_DOMAIN = 'terminator'
|
||||||
|
GETTEXT_TARGET = os.path.join('share', 'locale')
|
||||||
CSS_DIR = os.path.join('terminatorlib', 'themes')
|
CSS_DIR = os.path.join('terminatorlib', 'themes')
|
||||||
|
|
||||||
if sys.version_info < (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
|
@ -32,38 +33,44 @@ class TerminatorDist(Distribution):
|
||||||
global_options = Distribution.global_options + [
|
global_options = Distribution.global_options + [
|
||||||
("build-documentation", None, "Build the documentation"),
|
("build-documentation", None, "Build the documentation"),
|
||||||
("install-documentation", None, "Install the documentation"),
|
("install-documentation", None, "Install the documentation"),
|
||||||
("without-gettext", None, "Don't build/install gettext .mo files"),
|
|
||||||
("without-icon-cache", None, "Don't attempt to run gtk-update-icon-cache")]
|
("without-icon-cache", None, "Don't attempt to run gtk-update-icon-cache")]
|
||||||
|
|
||||||
def __init__ (self, *args):
|
def __init__ (self, *args):
|
||||||
self.without_gettext = False
|
|
||||||
self.without_icon_cache = False
|
self.without_icon_cache = False
|
||||||
Distribution.__init__(self, *args)
|
Distribution.__init__(self, *args)
|
||||||
|
|
||||||
|
|
||||||
class BuildData(build):
|
class CustomBuild(build):
|
||||||
def run (self):
|
"""
|
||||||
build.run (self)
|
Custom build extensions to build
|
||||||
|
"""
|
||||||
|
|
||||||
if not self.distribution.without_gettext:
|
def run(self):
|
||||||
# Build the translations
|
build.run(self)
|
||||||
for po in glob.glob (os.path.join (PO_DIR, '*.po')):
|
self.build_i18n()
|
||||||
lang = os.path.basename(po[:-3])
|
|
||||||
mo = os.path.join(MO_DIR, lang, 'terminator.mo')
|
|
||||||
|
|
||||||
directory = os.path.dirname(mo)
|
def build_i18n(self):
|
||||||
if not os.path.exists(directory):
|
"""
|
||||||
info('creating %s' % directory)
|
Compiling files for gettext from *.po to *.mo with the proper target path
|
||||||
os.makedirs(directory)
|
"""
|
||||||
|
info('compiling i18n files')
|
||||||
|
from babel.messages.frontend import compile_catalog
|
||||||
|
compiler = compile_catalog(self.distribution)
|
||||||
|
compiler.domain = [GETTEXT_DOMAIN]
|
||||||
|
|
||||||
|
for po in glob.glob(os.path.join(GETTEXT_SOURCE, '*.po')):
|
||||||
|
lang = os.path.basename(po[:-3])
|
||||||
|
mo = os.path.join(self.build_base, GETTEXT_TARGET, lang, 'LC_MESSAGES', 'terminator.mo')
|
||||||
|
|
||||||
|
directory = os.path.dirname(mo)
|
||||||
|
if not os.path.exists(directory):
|
||||||
|
os.makedirs(directory)
|
||||||
|
|
||||||
|
if newer(po, mo):
|
||||||
|
compiler.input_file = po
|
||||||
|
compiler.output_file = mo
|
||||||
|
compiler.run()
|
||||||
|
|
||||||
if newer(po, mo):
|
|
||||||
info('compiling %s -> %s' % (po, mo))
|
|
||||||
from babel.messages.frontend import compile_catalog
|
|
||||||
compiler = compile_catalog(self.distribution)
|
|
||||||
compiler.domain = ['terminator']
|
|
||||||
compiler.input_file = po
|
|
||||||
compiler.output_file = mo
|
|
||||||
compiler.run()
|
|
||||||
|
|
||||||
class Uninstall(Command):
|
class Uninstall(Command):
|
||||||
description = "Attempt an uninstall from an install --record file"
|
description = "Attempt an uninstall from an install --record file"
|
||||||
|
@ -126,7 +133,7 @@ class Uninstall(Command):
|
||||||
class InstallData(install_data):
|
class InstallData(install_data):
|
||||||
def run (self):
|
def run (self):
|
||||||
self.data_files.extend (self._find_css_files ())
|
self.data_files.extend (self._find_css_files ())
|
||||||
self.data_files.extend (self._find_mo_files ())
|
self.data_files.extend(self._find_mo_files())
|
||||||
install_data.run (self)
|
install_data.run (self)
|
||||||
if not self.distribution.without_icon_cache:
|
if not self.distribution.without_icon_cache:
|
||||||
self._update_icon_cache ()
|
self._update_icon_cache ()
|
||||||
|
@ -139,14 +146,16 @@ class InstallData(install_data):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
warn("updating the GTK icon cache failed: %s" % str(e))
|
warn("updating the GTK icon cache failed: %s" % str(e))
|
||||||
|
|
||||||
def _find_mo_files (self):
|
def _find_mo_files(self):
|
||||||
|
"""
|
||||||
|
search for gettext files built during build step
|
||||||
|
"""
|
||||||
data_files = []
|
data_files = []
|
||||||
|
|
||||||
if not self.distribution.without_gettext:
|
build_base = self.distribution.command_obj['build'].build_base
|
||||||
for mo in glob.glob (os.path.join (MO_DIR, '*', 'terminator.mo')):
|
for mo in glob.glob(os.path.join(build_base, GETTEXT_TARGET, '*', 'LC_MESSAGES', '*.mo')):
|
||||||
lang = os.path.basename(os.path.dirname(mo))
|
dest = mo.lstrip(build_base + os.sep)
|
||||||
dest = os.path.join('share', 'locale', lang, 'LC_MESSAGES')
|
data_files.append((dest, [mo]))
|
||||||
data_files.append((dest, [mo]))
|
|
||||||
|
|
||||||
return data_files
|
return data_files
|
||||||
|
|
||||||
|
@ -161,6 +170,27 @@ class InstallData(install_data):
|
||||||
return data_files
|
return data_files
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateCatalogs(Command):
|
||||||
|
"""Update all gettext catalogs """
|
||||||
|
description = __doc__
|
||||||
|
user_options = []
|
||||||
|
|
||||||
|
def initialize_options(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def finalize_options(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
from babel.messages.frontend import update_catalog
|
||||||
|
updater = update_catalog(self.distribution)
|
||||||
|
updater.input_file = os.path.join(GETTEXT_SOURCE, 'terminator.pot')
|
||||||
|
|
||||||
|
for po in glob.glob(os.path.join(GETTEXT_SOURCE, '*.po')):
|
||||||
|
updater.output_file = po
|
||||||
|
updater.run()
|
||||||
|
|
||||||
|
|
||||||
if platform.system() in ['FreeBSD', 'OpenBSD']:
|
if platform.system() in ['FreeBSD', 'OpenBSD']:
|
||||||
man_dir = 'man'
|
man_dir = 'man'
|
||||||
else:
|
else:
|
||||||
|
@ -220,6 +250,6 @@ setup(name=APP_NAME,
|
||||||
tests_require=test_deps,
|
tests_require=test_deps,
|
||||||
extras_require={'test': test_deps},
|
extras_require={'test': test_deps},
|
||||||
package_data={'terminatorlib': ['preferences.glade', 'layoutlauncher.glade']},
|
package_data={'terminatorlib': ['preferences.glade', 'layoutlauncher.glade']},
|
||||||
cmdclass={'build': BuildData, 'install_data': InstallData, 'uninstall': Uninstall},
|
cmdclass={'build': CustomBuild, 'install_data': InstallData, 'uninstall': Uninstall},
|
||||||
distclass=TerminatorDist)
|
distclass=TerminatorDist)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue