1
0
mirror of https://github.com/gryf/pygtktalog.git synced 2025-12-17 11:30:19 +01:00

Generalize locale support with pavement script.

This commit is contained in:
2009-05-19 19:52:55 +00:00
parent ca7fdf15e8
commit e93b7291b8

View File

@@ -12,19 +12,27 @@ import shutil
from paver.easy import sh, dry, call_task from paver.easy import sh, dry, call_task
from paver.tasks import task, needs, help from paver.tasks import task, needs, help
from paver.setuputils import setup from paver.setuputils import setup
#import setuptools.command.sdist
from paver.misctasks import generate_setup, minilib from paver.misctasks import generate_setup, minilib
try: try:
from pylint import lint from pylint import lint
have_lint = True HAVE_LINT = True
except: except ImportError:
have_lint = False HAVE_LINT = False
REV = os.popen("svn info 2>/dev/null|grep ^Revis|cut -d ' ' -f 2").readlines()
if REV:
REV = "r" + REV[0].strip()
else:
REV = '0'
LOCALES = ('pl','en')
# distutil/setuptool setup method. # distutil/setuptool setup method.
setup( setup(
name='pyGTKtalog', name='pyGTKtalog',
version='1.99', version='1.99.%s' % REV,
long_description='pyGTKtalog is application similar to WhereIsIT, ' long_description='pyGTKtalog is application similar to WhereIsIT, '
'for collecting information on files from CD/DVD ' 'for collecting information on files from CD/DVD '
@@ -56,13 +64,13 @@ setup(
@task @task
@needs(['genpl', 'minilib', 'generate_setup']) @needs(['locale_gen', 'minilib', 'generate_setup'])
def sdist(): def sdist():
"""sdist with message catalogs""" """sdist with message catalogs"""
call_task("setuptools.command.sdist") call_task("setuptools.command.sdist")
@task @task
@needs(['genpl']) @needs(['locale_gen'])
def build(): def build():
"""build with message catalogs""" """build with message catalogs"""
call_task("setuptools.command.build") call_task("setuptools.command.build")
@@ -98,14 +106,9 @@ def distclean():
@task @task
def run(): def run():
"""run application""" """run application"""
sh("PYTHONPATH=%s:$PYTHONPATH bin/gtktalog.py" % _setup_env()) #sh("PYTHONPATH=%s:$PYTHONPATH bin/gtktalog.py" % _setup_env())
import gtktalog
@task gtktalog.run()
@needs(['genpl'])
def runpl():
"""run application with pl_PL localization"""
os.environ['LC_ALL'] = 'pl_PL.utf8'
run()
@task @task
def pot(): def pot():
@@ -116,26 +119,35 @@ def pot():
@task @task
@needs(['pot']) @needs(['pot'])
def mergepl(): def locale_merge():
"""create or merge if exists polish 'po' translation file""" """create or merge if exists 'po' translation files"""
if os.path.exists(os.path.join('locale', 'pl.po')): potfile = os.path.join('locale', 'pygtktalog.pot')
sh('msgmerge -U locale/pl.po locale/pygtktalog.pot') for lang in LOCALES:
else: msg_catalog = os.path.join('locale', "%s.po" % lang)
shutil.copy(os.path.join('locale', 'pygtktalog.pot'), if os.path.exists(msg_catalog):
os.path.join('locale', 'pl.po')) sh('msgmerge -U %s %s' % (msg_catalog, potfile))
else:
shutil.copy(pot, msg_catalog)
@task @task
@needs(['mergepl']) @needs(['locale_merge'])
def genpl(): def locale_gen():
"""generate message catalog file for polish locale""" """generate message catalog file for available locale files"""
if not os.path.exists(os.path.join('pygtktalog', 'locale')): full_path = os.path.join('pygtktalog', 'locale')
full_path = 'pygtktalog' if not os.path.exists(full_path):
for name in ['locale', 'pl', 'LC_MESSAGES']: os.mkdir(full_path)
full_path = os.path.join(full_path, name)
os.mkdir(full_path) for lang in LOCALES:
sh('msgfmt locale/pl.po -o pygtktalog/locale/pl/LC_MESSAGES/pygtktalog.mo') lang_path = full_path
for dirname in [lang, 'LC_MESSAGES']:
lang_path = os.path.join(lang_path, dirname)
if not os.path.exists(lang_path):
os.mkdir(lang_path)
catalog_file = os.path.join(lang_path, 'pygtktalog.mo')
msg_catalog = os.path.join('locale', "%s.po" % lang)
sh('msgfmt %s -o %s' % (msg_catalog, catalog_file))
if have_lint: if HAVE_LINT:
@task @task
def pylint(): def pylint():
'''Check the module you're building with pylint.''' '''Check the module you're building with pylint.'''
@@ -148,13 +160,21 @@ def test():
os.system("PYTHONPATH=%s:$PYTHONPATH nosetests -w test" % _setup_env()) os.system("PYTHONPATH=%s:$PYTHONPATH nosetests -w test" % _setup_env())
@task
@needs(['locale_gen'])
def runpl():
"""run application with pl_PL localization. This is just for my
convenience"""
os.environ['LC_ALL'] = 'pl_PL.utf8'
run()
def _setup_env(): def _setup_env():
"""Helper function to set up paths""" """Helper function to set up paths"""
# current directory # current directory
this_path = os.path.dirname(os.path.abspath(__file__)) this_path = os.path.dirname(os.path.abspath(__file__))
if this_path not in sys.path: if this_path not in sys.path:
sys.path.insert(0, this_path) sys.path.insert(0, this_path)
# return
return this_path return this_path