On 09/20/12 03:24 AM, Erik Trauschke wrote:


On 09/20/12 01:51 PM, Tim Foster wrote:
On 09/20/12 08:43 PM, Erik Trauschke wrote:
According to this
http://pubs.opengroup.org/onlinepubs/007908799/xbd/envvar.html:

---
LC_ALL
This variable determines the values for all locale categories. The
value of the LC_ALL environment variable has precedence over any of the
other environment variables starting with LC_ (LC_COLLATE, LC_CTYPE,
LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME) and the LANG environment
variable.
---

Unless I'm reading this wrong, if you set LC_ALL, the setting of any
other LC_ variables should not matter.

That's correct, and straightforward to verify:

timf@igyo[330] export LC_ALL=fr_FR.UTF-8
timf@igyo[331] date
vendredi 21 septembre 2012 08:46:31 NZST
timf@igyo[332] unset LC_ALL
timf@igyo[333] export LC_TIME=ja_JP.UTF-8
timf@igyo[334] date
2012年09月21日 (金) 08時46分52秒 NZST
timf@igyo[335] export LC_ALL=fr_FR.UTF-8
timf@igyo[336] date
vendredi 21 septembre 2012 08:46:59 NZST
timf@igyo[337]

So I think I should be good by adding another elif statement testing for
LC_TIME:

if "LC_ALL" in os.environ and os.environ["LC_ALL"] != "C":
print_lc_warn()
elif "LC_TIME" in os.environ and if os.environ["LC_TIME"] != "C":
print_lc_warn()
elif "LANG" in os.environ and if os.environ["LANG"] != "C":
print_lc_warn()

I think that should be the correct sequence.

LGTM. (You could go to town, and check for "posix" as well as "C", but
I've never run into anyone actually using that locale name)

So you mean accepting posix and not print an error message in this case?

Turns out there were many more corner cases to consider. Pretty much any combination of LANG and LC_x variables might end up with something different. Then you have cases where LC_x is set but just to "". So I could have created a huge logical statement with 20+ ands and ors but I thought there must be a better way of doing this.

So what I do now is just calling /usr/bin/locale since this will give me the actual setting of each of the LC_x values depending on what LC_ALL and LANG are set to. If there is a way of doing this with Python magic, let me know. I tried and it didn't work.

Erik

PS: It also makes it easy to accept "POSIX" as valid locale. And I had to find out the hard way that "posix" is not a valid locale ;)

-----
diff -r 0358e521cc2d src/tests/run.py
--- a/src/tests/run.py  Fri Sep 14 10:29:11 2012 +0530
+++ b/src/tests/run.py  Mon Sep 24 05:23:10 2012 -0700
@@ -358,6 +358,25 @@
                 print >> sys.stderr, "-q cannot be used with -v or -p"
                 usage()

+        def print_lc_warn():
+                print >> sys.stderr, \
+                    "WARNING: You don't seem to use the C locale." \
+                    " Some tests may fail. \n" \
+                    "Set the C locale by setting LC_ALL=C"
+
+        p = subprocess.Popen(['/usr/bin/locale'], stdout=subprocess.PIPE,
+            stderr=subprocess.PIPE)
+        out, err = p.communicate()
+        warn = False
+        for line in out.split("\n"):
+                x = line.split("=")
+                if x[0] in ["LC_TIME", "LC_COLLATE", "LC_MESSAGES"]:
+                        loc = x[1].strip('"')
+                        if loc != "C" and loc != "POSIX":
+                                warn = True
+        if warn:
+                print_lc_warn()
+
         if output != OUTPUT_DOTS:
                 quiet = True
         if not onlyval:
-----

Erik


Erik


cheers,
tim

_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss

Reply via email to