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

Return to bug 279915