[yum-git] 3 commits - cli.py test/check-po-yes-no.py test/yum-release-i18n-test.sh yummain.py
James Antill
james at linux.duke.edu
Sat Apr 12 15:43:05 UTC 2008
cli.py | 17 ++++-
test/check-po-yes-no.py | 74 +++++++++++++++++++++++
test/yum-release-i18n-test.sh | 135 ++++++++++++++++++++++++++++++++++++++++++
yummain.py | 18 +++--
4 files changed, 235 insertions(+), 9 deletions(-)
New commits:
commit fbe610e34be1e92bef9e254ceb8265126851d302
Author: James Antill <james at and.org>
Date: Sat Apr 12 11:08:01 2008 -0400
Add auto testing for i18n issues
diff --git a/test/yum-release-i18n-test.sh b/test/yum-release-i18n-test.sh
new file mode 100755
index 0000000..aabc9ab
--- /dev/null
+++ b/test/yum-release-i18n-test.sh
@@ -0,0 +1,135 @@
+#!/bin/bash -e
+
+#######################################################
+### Settings ##########################################
+#######################################################
+
+# Change to true, to not perform the "root" commands
+SUDO_CMD=sudo
+
+# Do we want full info/list output (takes a while, and outputs a _lot_)
+FULL_PKG_OUTPUT=false
+
+# Do we want to play with the livna repo. includes install/remove
+LIVNA=true
+
+# Pkg to add/remove/etc. from livna
+PKG_LIVNA=amule
+
+# Pkg that doesn't exist
+PKG_BAD=pkg-no-exist-kthx-bai-OMGWTFBBQ
+
+# Run tests the "fail", like installing packages for which we don't have the
+# key. If you run these you need to look to see what the output is.
+# FIXME: need a more automated way to see if we are getting Unicode*Error
+RUN_FAILURES=true
+
+beg_hdr="
+==============================================================================="
+end_hdr="\
+-------------------------------------------------------------------------------
+"
+
+I18N="C \
+ da_DA da_DA.UTF-8 \
+ de_DE de_DE.UTF-8 \
+ fr_FR fr_FR.UTF-8 \
+ it_IT it_IT.UTF-8 \
+ ms_MS ms_MS.UTF-8 \
+ nb_NB nb_NB.UTF-8 \
+ pl_PL pl_PL.UTF-8 \
+ pt_PT pt_PT.UTF-8 \
+ pt_BR pt_BR.UTF-8 \
+ ru_RU ru_RU.UTF-8 \
+ sr_SR sr_SR.UTF-8 sr_SR at latin sr_SR at latin.UTF-8 \
+ en_US en_US.UTF-8 \
+ BAD_LOCALE"
+
+cmd()
+{
+ echo $beg_hdr
+ echo "Doing: LANG=$lang yum --enablerepo=development $@"
+ echo $end_hdr
+ LANG=$lang yum --enablerepo=development $@
+}
+scmd()
+{
+ echo $beg_hdr
+ echo "Doing: LANG=$lang $SUDO_CMD yum $@"
+ echo $end_hdr
+ LANG=$lang $SUDO_CMD yum $@
+}
+lcmd()
+{
+ $LIVNA echo $beg_hdr
+ $LIVNA echo "Doing: LANG=$lang yum --enablerepo=livna $@"
+ $LIVNA echo $end_hdr
+ $LIVNA LANG=$lang yum --enablerepo=livna $@
+}
+lscmd()
+{
+ $LIVNA echo $beg_hdr
+ $LIVNA echo "Doing: LANG=$lang $SUDO_CMD yum --enablerepo=livna $@"
+ $LIVNA echo $end_hdr
+ $LIVNA LANG=$lang $SUDO_CMD yum --enablerepo=livna $@
+}
+
+tst()
+{
+ # Using ¶ because it doesn't match anything
+ cmd search fedora linux ® $PKG_BAD ¶
+ cmd search fedora linux ® $PKG_BAD ¶ | cat
+
+ cmd list afflib libselinux linux $PKG_BAD ¶
+ cmd list afflib libselinux linux $PKG_BAD ¶ | cat
+ cmd info afflib libselinux linux $PKG_BAD ¶
+ cmd info afflib libselinux linux $PKG_BAD ¶ | cat
+
+ $FULL_PKG_OUTPUT && cmd list
+ $FULL_PKG_OUTPUT && cmd list | cat
+ $FULL_PKG_OUTPUT && cmd info
+ $FULL_PKG_OUTPUT && cmd info | cat
+
+ # This always fails, so we need to "look" if it does so with an encoding
+ # problem or the real one
+ ($RUN_FAILURES && cmd help) || true
+ $RUN_FAILURES && sleep 5
+ # This always fails, so we need to "look" if it does so with an encoding
+ # problem or the real one
+ ($RUN_FAILURES && (cmd help | cat)) || true
+ $RUN_FAILURES && sleep 5
+ for i in install remove check-update update list info provides; do
+ cmd help $i
+ cmd help $i | cat
+ done
+ cmd --help
+ cmd --help | cat
+ # This always fails, so we need to "look" if it does so with an encoding
+ # problem or the real one
+ ($RUN_FAILURES && cmd) || true
+ $RUN_FAILURES && sleep 5
+ # This always fails, so we need to "look" if it does so with an encoding
+ # problem or the real one
+ ($RUN_FAILURES && (cmd | cat)) || true
+ $RUN_FAILURES && sleep 5
+
+ scmd install bash
+ scmd install $PKG_BAD
+ scmd remove $PKG_BAD
+
+ # Test livna, missing keys and install/remove
+ $LIVNA && $SUDO_CMD mv /etc/pki/rpm-gpg/RPM-GPG-KEY-livna .
+ ($LIVNA && $SUDO_CMD rpm -e gpg-pubkey-a109b1ec-3f6e28d5) || true
+ # This always fails, so we need to "look" if it does so with an encoding
+ # problem or the real one
+ ($RUN_FAILURES && lcmd install $PKG_LIVNA) || true
+ $RUN_FAILURES && $LIVNA && sleep 2
+ $LIVNA && $SUDO_CMD mv RPM-GPG-KEY-livna /etc/pki/rpm-gpg/
+ lcmd install -y $PKG_LIVNA
+ lcmd remove -y $PKG_LIVNA
+}
+
+
+for lang in $I18N; do
+ tst
+done
commit 761e58a85937e9c56c7387c4d535e77db1b27c7b
Author: James Antill <james at and.org>
Date: Sat Apr 12 11:05:04 2008 -0400
Move locale, so we don't die on unsupported locale's in getpreferredencoding
Override optparses print_help() from --help, as it screws up the encoding.
diff --git a/cli.py b/cli.py
index d10e50c..46a5a8e 100644
--- a/cli.py
+++ b/cli.py
@@ -1091,6 +1091,10 @@ class YumOptionParser(OptionParser):
root = '/'
return root
+ def _wrapOptParseUsage(self, opt, value, parser, *args, **kwargs):
+ self.base.usage()
+ self.exit()
+
def _addYumBasicOptions(self):
def repo_optcb(optobj, opt, value, parser):
'''Callback for the enablerepo and disablerepo option.
@@ -1101,7 +1105,16 @@ class YumOptionParser(OptionParser):
dest = eval('parser.values.%s' % optobj.dest)
dest.append((opt, value))
-
+
+ # Note that we can't use the default action="help" because of the
+ # fact that print_help() unconditionally does .encode() ... which is
+ # bad on unicode input.
+ self.conflict_handler = "resolve"
+ self.add_option("-h", "--help", action="callback",
+ callback=self._wrapOptParseUsage,
+ help=_("show this help message and exit"))
+ self.conflict_handler = "error"
+
self.add_option("-t", "--tolerant", action="store_true",
help=_("be tolerant of errors"))
self.add_option("-C", dest="cacheonly", action="store_true",
@@ -1122,7 +1135,7 @@ class YumOptionParser(OptionParser):
self.add_option("-q", "--quiet", dest="quiet", action="store_true",
help=_("quiet operation"))
self.add_option("-v", "--verbose", dest="verbose", action="store_true",
- help="verbose operation")
+ help=_("verbose operation"))
self.add_option("-y", dest="assumeyes", action="store_true",
help=_("answer yes for all questions"))
self.add_option("--version", action="store_true",
diff --git a/yummain.py b/yummain.py
index c949982..9421d02 100755
--- a/yummain.py
+++ b/yummain.py
@@ -33,6 +33,17 @@ import cli
def main(args):
"""This does all the real work"""
+
+ # This test needs to be before locale.getpreferredencoding() as that
+ # does setlocale(LC_CTYPE, "")
+ try:
+ locale.setlocale(locale.LC_ALL, '')
+ except locale.Error, e:
+ # default to C locale if we get a failure.
+ print >> sys.stderr, 'Failed to set locale, defaulting to C'
+ os.environ['LC_ALL'] = 'C'
+ locale.setlocale(locale.LC_ALL, 'C')
+
if True: # not sys.stdout.isatty():
import codecs
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
@@ -76,13 +87,6 @@ def main(args):
logger = logging.getLogger("yum.main")
verbose_logger = logging.getLogger("yum.verbose.main")
- try:
- locale.setlocale(locale.LC_ALL, '')
- except locale.Error, e:
- # default to C locale if we get a failure.
- print >> sys.stderr, 'Failed to set locale, defaulting to C'
- locale.setlocale(locale.LC_ALL, 'C')
-
# our core object for the cli
base = cli.YumBaseCli()
commit 337ccc844e5d48498c6ca196c165d39f17f7affc
Author: James Antill <james at and.org>
Date: Sat Apr 12 10:30:23 2008 -0400
Add an automatic checker for the dependant yes/no translations
diff --git a/test/check-po-yes-no.py b/test/check-po-yes-no.py
new file mode 100755
index 0000000..735a3ca
--- /dev/null
+++ b/test/check-po-yes-no.py
@@ -0,0 +1,74 @@
+#! /usr/bin/python -tt
+
+# This is a simple command to check that "Is this ok [y/N]: " and yes and no
+# have either all been translated or none have been translated.
+
+import sys
+import glob
+
+for fname in glob.glob("po/*.po"):
+ next = None
+ is_this_ok = None
+ yes = None
+ y = None
+ no = None
+ n = None
+ for line in file(fname):
+ if next is not None:
+ if next == 'is_this_ok':
+ if line == 'msgstr ""\n' or line.find('[y/N]') != -1:
+ is_this_ok = False
+ else:
+ is_this_ok = True
+ if next == 'yes':
+ yes = line != 'msgstr ""\n'
+ if next == 'y':
+ y = line != 'msgstr ""\n'
+ if next == 'no':
+ no = line != 'msgstr ""\n'
+ if next == 'n':
+ n = line != 'msgstr ""\n'
+ next = None
+ continue
+ if line == 'msgid "Is this ok [y/N]: "\n':
+ next = 'is_this_ok'
+ if line == 'msgid "yes"\n':
+ next = 'yes'
+ if line == 'msgid "y"\n':
+ next = 'y'
+ if line == 'msgid "no"\n':
+ next = 'no'
+ if line == 'msgid "n"\n':
+ next = 'n'
+ if (is_this_ok is None or
+ yes is None or
+ y is None or
+ no is None or
+ n is None):
+ print >>sys.stderr, """\
+ERROR: Can't find all the msg id's in %s
+is_this_ok %s
+yes %s
+y %s
+no %s
+n %s
+""" % (fname,
+ is_this_ok is None,
+ yes is None,
+ y is None,
+ no is None,
+ n is None)
+ sys.exit(1)
+ if (is_this_ok != yes or
+ is_this_ok != y or
+ is_this_ok != no or
+ is_this_ok != n):
+ print >>sys.stderr, """\
+ERROR: yes/no translations don't match in: %s
+is_this_ok %s
+yes %s
+y %s
+no %s
+n %s
+""" % (fname,
+ is_this_ok, yes, y, no, n)
More information about the Yum-cvs-commits
mailing list