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.tasks import task, needs, help
from paver.setuputils import setup
#import setuptools.command.sdist
from paver.misctasks import generate_setup, minilib
try:
from pylint import lint
have_lint = True
except:
have_lint = False
HAVE_LINT = True
except ImportError:
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.
setup(
name='pyGTKtalog',
version='1.99',
version='1.99.%s' % REV,
long_description='pyGTKtalog is application similar to WhereIsIT, '
'for collecting information on files from CD/DVD '
@@ -56,13 +64,13 @@ setup(
@task
@needs(['genpl', 'minilib', 'generate_setup'])
@needs(['locale_gen', 'minilib', 'generate_setup'])
def sdist():
"""sdist with message catalogs"""
call_task("setuptools.command.sdist")
@task
@needs(['genpl'])
@needs(['locale_gen'])
def build():
"""build with message catalogs"""
call_task("setuptools.command.build")
@@ -98,14 +106,9 @@ def distclean():
@task
def run():
"""run application"""
sh("PYTHONPATH=%s:$PYTHONPATH bin/gtktalog.py" % _setup_env())
@task
@needs(['genpl'])
def runpl():
"""run application with pl_PL localization"""
os.environ['LC_ALL'] = 'pl_PL.utf8'
run()
#sh("PYTHONPATH=%s:$PYTHONPATH bin/gtktalog.py" % _setup_env())
import gtktalog
gtktalog.run()
@task
def pot():
@@ -116,26 +119,35 @@ def pot():
@task
@needs(['pot'])
def mergepl():
"""create or merge if exists polish 'po' translation file"""
if os.path.exists(os.path.join('locale', 'pl.po')):
sh('msgmerge -U locale/pl.po locale/pygtktalog.pot')
def locale_merge():
"""create or merge if exists 'po' translation files"""
potfile = os.path.join('locale', 'pygtktalog.pot')
for lang in LOCALES:
msg_catalog = os.path.join('locale', "%s.po" % lang)
if os.path.exists(msg_catalog):
sh('msgmerge -U %s %s' % (msg_catalog, potfile))
else:
shutil.copy(os.path.join('locale', 'pygtktalog.pot'),
os.path.join('locale', 'pl.po'))
shutil.copy(pot, msg_catalog)
@task
@needs(['mergepl'])
def genpl():
"""generate message catalog file for polish locale"""
if not os.path.exists(os.path.join('pygtktalog', 'locale')):
full_path = 'pygtktalog'
for name in ['locale', 'pl', 'LC_MESSAGES']:
full_path = os.path.join(full_path, name)
@needs(['locale_merge'])
def locale_gen():
"""generate message catalog file for available locale files"""
full_path = os.path.join('pygtktalog', 'locale')
if not os.path.exists(full_path):
os.mkdir(full_path)
sh('msgfmt locale/pl.po -o pygtktalog/locale/pl/LC_MESSAGES/pygtktalog.mo')
if have_lint:
for lang in LOCALES:
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:
@task
def pylint():
'''Check the module you're building with pylint.'''
@@ -148,6 +160,15 @@ def test():
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():
"""Helper function to set up paths"""
# current directory
@@ -155,6 +176,5 @@ def _setup_env():
if this_path not in sys.path:
sys.path.insert(0, this_path)
# return
return this_path