blob: e00070926b1bb7f72815e34dc0e7b42077060997 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# Copyright 2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
from portage import os
from portage.process import find_binary
from portage.util import shlex_split
def validate_cmd_var(v):
"""
Validate an environment variable value to see if it
contains an executable command as the first token.
returns (valid, token_list) where 'valid' is boolean and 'token_list'
is the (possibly empty) list of tokens split by shlex.
"""
invalid = False
v_split = shlex_split(v)
if not v_split:
invalid = True
elif os.path.isabs(v_split[0]):
invalid = not os.access(v_split[0], os.EX_OK)
elif find_binary(v_split[0]) is None:
invalid = True
return (not invalid, v_split)
|