From 1c4705253832041a7fc3824fdf3ea54a2ea63b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fatih=20A=C5=9F=C4=B1c=C4=B1?= Date: Tue, 19 Oct 2010 10:28:17 +0000 Subject: [PATCH] tree-wide: Remove redundant setlocale's This commit also fixes the confirm method to repeat asking until a valid input is given. --- pisi-cli | 2 -- pisi/cli/__init__.py | 19 +++++++++++++------ pisi/operations/build.py | 3 --- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/pisi-cli b/pisi-cli index b61e106f..4b5d4436 100755 --- a/pisi-cli +++ b/pisi-cli @@ -12,7 +12,6 @@ import sys import errno -import locale import traceback import exceptions import signal @@ -79,6 +78,5 @@ if __name__ == "__main__": signal.signal(signal.SIGTERM, sig_handler) - locale.setlocale(locale.LC_ALL, '') cli = pisicli.PisiCLI() cli.run_command() diff --git a/pisi/cli/__init__.py b/pisi/cli/__init__.py index d7935c59..87722c71 100644 --- a/pisi/cli/__init__.py +++ b/pisi/cli/__init__.py @@ -137,7 +137,6 @@ class CLI(pisi.ui.UI): def choose(self, msg, opts): msg = unicode(msg) - import re prompt = msg + pisi.util.colorize(' (%s)' % "/".join(opts), 'red') while True: s = raw_input(prompt.encode('utf-8')) @@ -149,17 +148,25 @@ class CLI(pisi.ui.UI): msg = unicode(msg) if ctx.config.options and ctx.config.options.yes_all: return True - while True: - import re, tty - yesexpr = re.compile(locale.nl_langinfo(locale.YESEXPR)) + import re, tty + + locale.setlocale(locale.LC_ALL, "") + yes_expr = re.compile(locale.nl_langinfo(locale.YESEXPR)) + no_expr = re.compile(locale.nl_langinfo(locale.NOEXPR)) + locale.setlocale(locale.LC_ALL, "C") + + while True: tty.tcflush(sys.stdin.fileno(), 0) prompt = msg + pisi.util.colorize(_(' (yes/no)'), 'red') s = raw_input(prompt.encode('utf-8')) - if yesexpr.search(s): + + if yes_expr.search(s): return True - return False + if no_expr.search(s): + return False + def display_progress(self, **ka): """ display progress of any operation """ diff --git a/pisi/operations/build.py b/pisi/operations/build.py index 02959400..d6195ee2 100644 --- a/pisi/operations/build.py +++ b/pisi/operations/build.py @@ -18,7 +18,6 @@ import glob import stat import pwd import grp -import locale import fnmatch import gettext @@ -910,7 +909,6 @@ class Builder: def file_actions(self): install_dir = self.pkg_install_dir() - locale.setlocale(locale.LC_ALL, 'C') import magic ms = magic.open(magic.MAGIC_NONE) ms.load() @@ -923,7 +921,6 @@ class Builder: exclude_special_files(filepath, fileinfo, self.actionGlobals) ms.close() - locale.setlocale(locale.LC_ALL, '') def build_packages(self): """Build each package defined in PSPEC file. After this process there