1 |
2010-07-31 21:49:50 Alec Warner napisał(a): |
2 |
> On Sat, Jul 31, 2010 at 7:44 AM, Arfrever Frehtes Taifersar Arahesis |
3 |
> <Arfrever@g.o> wrote: |
4 |
> > 2010-07-30 04:36:22 Brian Harring napisał(a): |
5 |
> >> On Fri, Jul 30, 2010 at 01:16:42AM +0200, Arfrever Frehtes Taifersar Arahesis wrote: |
6 |
> >> > --- python.eclass |
7 |
> >> > +++ python.eclass |
8 |
> >> > @@ -355,6 +355,8 @@ |
9 |
> >> > # Check if phase is pkg_setup(). |
10 |
> >> > [[ "${EBUILD_PHASE}" != "setup" ]] && die "${FUNCNAME}() can be used only in pkg_setup() phase" |
11 |
> >> > |
12 |
> >> > + local locale |
13 |
> >> > + |
14 |
> >> > if [[ "$#" -ne 0 ]]; then |
15 |
> >> > die "${FUNCNAME}() does not accept arguments" |
16 |
> >> > fi |
17 |
> >> > @@ -407,6 +409,16 @@ |
18 |
> >> > unset -f python_pkg_setup_check_USE_flags |
19 |
> >> > fi |
20 |
> >> > |
21 |
> >> > + locale="$(python -c 'import os; print(os.environ.get("LC_ALL", os.environ.get("LC_CTYPE", os.environ.get("LANG", "POSIX"))))')" |
22 |
> >> |
23 |
> >> You're using python to get the exported env. Don't. Use bash (you're |
24 |
> >> invoking python from freaking bash after all)... |
25 |
> > |
26 |
> > Given variable can be set, but not exported. |
27 |
> |
28 |
> If the variable is set but not exported then it is local to the shell |
29 |
> env. When bash goes to exec() python the local shell variables are |
30 |
> not in the env; so os.environ() will not contain them. |
31 |
> |
32 |
> antarus@kyoto ~ $ foo=BAR |
33 |
> antarus@kyoto ~ $ echo $foo |
34 |
> BAR |
35 |
> antarus@kyoto ~ $ python -c 'import os; print os.environ.get("foo")' |
36 |
> None |
37 |
> antarus@kyoto ~ $ export foo |
38 |
> antarus@kyoto ~ $ python -c 'import os; print os.environ.get("foo")' |
39 |
> BAR |
40 |
|
41 |
I want only variables exported to Python processes. |
42 |
|
43 |
> so how is this any different than: |
44 |
> |
45 |
> [[ -n $LC_TYPE ]] && locale=$LC_TYPE |
46 |
> [[ -n $LC_ALL ]] && locale=$LC_ALL |
47 |
> locale=${locale:-POSIX} |
48 |
|
49 |
This code uses non-exported variables. |
50 |
|
51 |
> if you want to keep it short; or the longer version with more ifs and |
52 |
> less shell magic. Normally I'm not a big performance man myself; but |
53 |
> this is in an eclass used by lots of packages; not just one ebuild. |
54 |
|
55 |
python_pkg_setup() is a rarely called function. |
56 |
|
57 |
-- |
58 |
Arfrever Frehtes Taifersar Arahesis |