Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH 3/4] EAPI 6: Enforce posixish LC_CTYPE
Date: Sun, 15 Nov 2015 21:17:58
Message-Id: 1447622247-9347-3-git-send-email-mgorny@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 1/4] Warn if LC_CTYPE does not transform ASCII chars like POSIX by "Michał Górny"
1 ---
2 pym/portage/package/ebuild/config.py | 13 ++++++++++++-
3 pym/portage/util/locale.py | 23 ++++++++++++++++++++---
4 2 files changed, 32 insertions(+), 4 deletions(-)
5
6 diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py
7 index 095de37..1827043 100644
8 --- a/pym/portage/package/ebuild/config.py
9 +++ b/pym/portage/package/ebuild/config.py
10 @@ -24,7 +24,7 @@ portage.proxy.lazyimport.lazyimport(globals(),
11 'portage.dep.soname.SonameAtom:SonameAtom',
12 'portage.dbapi.vartree:vartree',
13 'portage.package.ebuild.doebuild:_phase_func_map',
14 - 'portage.util.locale:split_LC_ALL',
15 + 'portage.util.locale:check_locale,split_LC_ALL',
16 )
17 from portage import bsd_chflags, \
18 load_mod, os, selinux, _unicode_decode
19 @@ -2773,6 +2773,17 @@ class config(object):
20 if eapi_attrs.posixish_locale:
21 split_LC_ALL(mydict)
22 mydict["LC_COLLATE"] = "C"
23 + if not check_locale(silent=True, env=mydict):
24 + # try another locale
25 + for l in ("C.UTF-8", "en_US.UTF-8", "en_GB.UTF-8", "C"):
26 + mydict["LC_CTYPE"] = l
27 + if check_locale(silent=True, env=mydict):
28 + # TODO: output the following only once
29 +# writemsg(_("!!! LC_CTYPE unsupported, using %s instead\n")
30 +# % mydict["LC_CTYPE"])
31 + break
32 + else:
33 + raise AssertionError("C locale did not pass the test!")
34
35 return mydict
36
37 diff --git a/pym/portage/util/locale.py b/pym/portage/util/locale.py
38 index 7b13ec7..93f8c32 100644
39 --- a/pym/portage/util/locale.py
40 +++ b/pym/portage/util/locale.py
41 @@ -9,6 +9,7 @@ get_ro_checker().
42 """
43 from __future__ import unicode_literals
44
45 +import locale
46 import logging
47 import os
48 import textwrap
49 @@ -27,7 +28,7 @@ locale_categories = (
50 )
51
52
53 -def _check_locale():
54 +def _check_locale(silent):
55 """
56 The inner locale check function.
57 """
58 @@ -45,6 +46,9 @@ def _check_locale():
59 ruc = [libc.toupper(c) for c in lc]
60
61 if lc != rlc or uc != ruc:
62 + if silent:
63 + return False
64 +
65 msg = ("WARNING: The LC_CTYPE variable is set to a locale " +
66 "that specifies transformation between lowercase " +
67 "and uppercase ASCII characters that is different than " +
68 @@ -72,7 +76,7 @@ def _check_locale():
69 return True
70
71
72 -def check_locale():
73 +def check_locale(silent=False, env=None):
74 """
75 Check whether the locale is sane. Returns True if it is, prints
76 warning and returns False if it is not. Returns None if the check
77 @@ -82,7 +86,20 @@ def check_locale():
78 pid = os.fork()
79 if pid == 0:
80 try:
81 - ret = _check_locale()
82 + if env is not None:
83 + for v in ("LC_ALL", "LC_CTYPE", "LANG"):
84 + if v in env:
85 + mylocale = env[v]
86 + break
87 + else:
88 + mylocale = "C"
89 +
90 + try:
91 + locale.setlocale(locale.LC_CTYPE, mylocale)
92 + except locale.Error:
93 + os._exit(2)
94 +
95 + ret = _check_locale(silent)
96 if ret is None:
97 os._exit(2)
98 else:
99 --
100 2.6.3

Replies