Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 279915 | Differences between
and this patch

Collapse All | Expand All

(-)python.eselect (-16 / +58 lines)
Lines 24-43 find_targets() { Link Here
24
	done
24
	done
25
}
25
}
26
26
27
set_python_script() {
27
set_python() {
28
	local script="${INTERPRETER_PATH}${1}" target="${2}"
28
	local program="${INTERPRETER_PATH}python" target="${1}"
29
	cat << EOF > "${script}"
29
	cat << EOF > /tmp/python.c
30
#!/bin/bash
30
#include <limits.h>
31
# Gentoo Python wrapper script
31
#include <stdlib.h>
32
#include <string.h>
33
#include <unistd.h>
32
34
33
[[ "\${EPYTHON}" =~ (/|^python\$) ]] && EPYTHON="${target}"
35
const char* name = "### Gentoo Python wrapper for ${target} program ###";
34
"\${0%/*}/\${EPYTHON:-${target}}" "\$@"
36
37
int main(int argc, char** argv)
38
{
39
  if (strlen(name) == 0)
40
    {
41
      abort();
42
    }
43
44
  char* EPYTHON = getenv("EPYTHON");
45
  if (! EPYTHON || (strcmp(EPYTHON, "python") == 0) || strchr(EPYTHON, '/'))
46
    {
47
      EPYTHON = "${target}";
48
    }
49
50
  char buf[PATH_MAX + 1];
51
  if (readlink("/proc/self/exe", buf, sizeof(buf) - 1) != -1)
52
    {
53
      char* last_path_sep = strrchr(buf, '/');
54
      if (last_path_sep)
55
        {
56
          *last_path_sep = 0;
57
        }
58
      char* absolute_python_path = strcat(strcat(buf, "/"), EPYTHON);
59
      execv(absolute_python_path, argv);
60
    }
61
  else
62
    {
63
      execvp(EPYTHON, argv);
64
    }
65
66
  return 1;
67
}
35
EOF
68
EOF
36
	chmod +x "${script}"
69
	${CC:-gcc} ${CFLAGS} ${LDFLAGS} /tmp/python.c -o "${program}"
70
	rm -f /tmp/python.c
37
}
71
}
38
72
39
set_python_config_script() {
73
set_python_config() {
40
	local script="${INTERPRETER_PATH}${1}" target="${2}"
74
	local script="${INTERPRETER_PATH}python-config" target="${1}"
41
	cat << EOF > "${script}"
75
	cat << EOF > "${script}"
42
#!/bin/bash
76
#!/bin/bash
43
# Gentoo python-config wrapper script
77
# Gentoo python-config wrapper script
Lines 100-110 set_scripts_and_symlinks() { Link Here
100
	if [[ -f "${INTERPRETER_PATH}${target}" ]]; then
134
	if [[ -f "${INTERPRETER_PATH}${target}" ]]; then
101
		remove_symlinks
135
		remove_symlinks
102
		set_man_symlink "${target}"
136
		set_man_symlink "${target}"
103
	
137
104
		pushd "${INTERPRETER_PATH}" 1>/dev/null
138
		pushd "${INTERPRETER_PATH}" 1>/dev/null
105
		set_python_script "python" "${target}"
139
		set_python "${target}"
106
		ln -nfs "${target}" "${target%.*}"
140
		ln -nfs "${target}" "${target%.*}"
107
		set_python_config_script "python-config" "${target/python/python-config-}"
141
		set_python_config "${target/python/python-config-}"
108
		ln -nfs "${target/python/pydoc}" pydoc
142
		ln -nfs "${target/python/pydoc}" pydoc
109
		ln -nfs "${target/python/idle}" idle
143
		ln -nfs "${target/python/idle}" idle
110
		# 2to3 for >=2.6
144
		# 2to3 for >=2.6
Lines 138-145 describe_show() { Link Here
138
}
172
}
139
173
140
do_show() {
174
do_show() {
141
	active=$(canonicalise "${INTERPRETER_PATH}python")
175
	active=$(< "${INTERPRETER_PATH}python")
142
	echo ${active#${INTERPRETER_PATH}}
176
	active=$(echo "${active}" | grep -Eo "### Gentoo Python wrapper for [^[:space:]]+ program ###" | sed -e "s/.*### Gentoo Python wrapper for \([^[:space:]]\+\) program ###.*/\1/")
177
	echo "${active}"
143
}
178
}
144
179
145
### list action ###
180
### list action ###
Lines 178-183 do_set() { Link Here
178
	elif [[ -n "${2}" ]]; then
213
	elif [[ -n "${2}" ]]; then
179
		die -q "Too many parameters"
214
		die -q "Too many parameters"
180
	else
215
	else
216
		if [[ -z "${CFLAGS}" && -f /etc/make.conf ]]; then
217
			CFLAGS="$(. /etc/make.conf; echo "${CFLAGS}")"
218
		fi
219
		if [[ -z "${LDFLAGS}" && -f /etc/make.conf ]]; then
220
			LDFLAGS="$(. /etc/make.conf; echo "${LDFLAGS}")"
221
		fi
222
181
		if ! remove_symlinks; then
223
		if ! remove_symlinks; then
182
			die -q "Can't remove existing provider"
224
			die -q "Can't remove existing provider"
183
		elif ! set_scripts_and_symlinks "${1}"; then
225
		elif ! set_scripts_and_symlinks "${1}"; then
Lines 220-226 do_update() { Link Here
220
	fi
262
	fi
221
263
222
	local targets=( $(cd "${INTERPRETER_PATH}"; ls python?.?|sort -r) ) target
264
	local targets=( $(cd "${INTERPRETER_PATH}"; ls python?.?|sort -r) ) target
223
	
265
224
	# Ignore slots
266
	# Ignore slots
225
	for slot in ${ignored_slots[@]}; do
267
	for slot in ${ignored_slots[@]}; do
226
		targets=( ${targets[@]/python${slot}/} )
268
		targets=( ${targets[@]/python${slot}/} )

Return to bug 279915