gettext: Use argparse to handle arguments

pull/987/head
Patrick Griffis 8 years ago committed by Jussi Pakkanen
parent 3650669874
commit 314eb5110e
  1. 41
      mesonbuild/modules/i18n.py
  2. 54
      mesonbuild/scripts/gettext.py

@ -26,29 +26,36 @@ class I18nModule:
raise coredata.MesonException('List of languages empty.')
datadirs = mesonlib.stringlistify(kwargs.get('data_dirs', []))
extra_args = mesonlib.stringlistify(kwargs.get('args', []))
potargs = [state.environment.get_build_command(), '--internal', 'gettext', 'pot', packagename]
pkg_arg = '--pkgname=' + packagename
lang_arg = '--langs=' + '@@'.join(languages)
datadirs = '--datadirs=' + ':'.join(datadirs) if datadirs else None
extra_args = '--extra-args=' + '@@'.join(extra_args) if extra_args else None
potargs = [state.environment.get_build_command(), '--internal', 'gettext', 'pot', pkg_arg]
if datadirs:
potargs.append('--datadirs=' + ':'.join(datadirs))
potargs += extra_args
potargs.append(datadirs)
if extra_args:
potargs.append(extra_args)
pottarget = build.RunTarget(packagename + '-pot', sys.executable, potargs, [], state.subdir)
gmoargs = [state.environment.get_build_command(), '--internal', 'gettext', 'gen_gmo'] + languages
gmoargs = [state.environment.get_build_command(), '--internal', 'gettext', 'gen_gmo', lang_arg]
gmotarget = build.RunTarget(packagename + '-gmo', sys.executable, gmoargs, [], state.subdir)
updatepoargs = [state.environment.get_build_command(), '--internal', 'gettext', 'update_po', packagename]
updatepoargs.append('@@'.join(languages))
updatepoargs = [state.environment.get_build_command(), '--internal', 'gettext', 'update_po', pkg_arg, lang_arg]
if datadirs:
updatepoargs.append('--datadirs=' + ':'.join(datadirs))
updatepoargs += extra_args
updatepoargs.append(datadirs)
if extra_args:
updatepoargs.append(extra_args)
updatepotarget = build.RunTarget(packagename + '-update-po', sys.executable, updatepoargs, [], state.subdir)
installcmd = [sys.executable,
state.environment.get_build_command(),
'--internal',
'gettext',
'install',
state.subdir,
packagename,
state.environment.coredata.get_builtin_option('localedir'),
] + languages
installcmd = [sys.executable, state.environment.get_build_command(),
'--internal', 'gettext', 'install',
'--subdir=' + state.subdir,
'--localedir=' + state.environment.coredata.get_builtin_option('localedir'),
pkg_arg, lang_arg]
iscript = build.InstallScript(installcmd)
return [pottarget, gmotarget, iscript, updatepotarget]
def initialize():

@ -12,9 +12,21 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os, subprocess, shutil
import os
import shutil
import argparse
import subprocess
from mesonbuild.scripts import destdir_join
parser = argparse.ArgumentParser()
parser.add_argument('command')
parser.add_argument('--pkgname', default='')
parser.add_argument('--datadirs', default='')
parser.add_argument('--langs', default='')
parser.add_argument('--localedir', default='')
parser.add_argument('--subdir', default='')
parser.add_argument('--extra-args', default='')
def run_potgen(src_sub, pkgname, datadirs, args):
listfile = os.path.join(src_sub, 'POTFILES')
if not os.path.exists(listfile):
@ -57,39 +69,29 @@ def do_install(src_sub, bld_sub, dest, pkgname, langs):
return 0
def run(args):
subcmd = args[0]
options = parser.parse_args(args)
subcmd = options.command
langs = options.langs.split('@@')
extra_args = options.extra_args.split('@@')
subdir = os.environ.get('MESON_SUBDIR', options.subdir)
src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], subdir)
bld_sub = os.path.join(os.environ['MESON_BUILD_ROOT'], subdir)
if subcmd == 'pot':
pkgname = args[1]
datadirs = args[2][11:] if args[2].startswith('--datadirs=') else None
extra_args = args[3:] if datadirs is not None else args[2:]
src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])
bld_sub = os.path.join(os.environ['MESON_BUILD_ROOT'], os.environ['MESON_SUBDIR'])
return run_potgen(src_sub, pkgname, datadirs, extra_args)
return run_potgen(src_sub, options.pkgname, options.datadirs, extra_args)
elif subcmd == 'gen_gmo':
src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])
bld_sub = os.path.join(os.environ['MESON_BUILD_ROOT'], os.environ['MESON_SUBDIR'])
return gen_gmo(src_sub, bld_sub, args[1:])
return gen_gmo(src_sub, bld_sub, langs)
elif subcmd == 'update_po':
pkgname = args[1]
langs = args[2].split('@@')
datadirs = args[3][11:] if args[3].startswith('--datadirs=') else None
extra_args = args[4:] if datadirs is not None else args[3:]
src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])
if run_potgen(src_sub, pkgname, datadirs, extra_args) != 0:
if run_potgen(src_sub, options.pkgname, options.datadirs, extra_args) != 0:
return 1
return update_po(src_sub, pkgname, langs)
return update_po(src_sub, options.pkgname, langs)
elif subcmd == 'install':
subdir = args[1]
pkgname = args[2]
instsubdir = args[3]
langs = args[4:]
src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], subdir)
bld_sub = os.path.join(os.environ['MESON_BUILD_ROOT'], subdir)
destdir = os.environ.get('DESTDIR', '')
dest = destdir_join(destdir, os.path.join(os.environ['MESON_INSTALL_PREFIX'], instsubdir))
dest = destdir_join(destdir, os.path.join(os.environ['MESON_INSTALL_PREFIX'],
options.localedir))
if gen_gmo(src_sub, bld_sub, langs) != 0:
return 1
do_install(src_sub, bld_sub, dest, pkgname, langs)
do_install(src_sub, bld_sub, dest, options.pkgname, langs)
else:
print('Unknown subcommand.')
return 1

Loading…
Cancel
Save