diff options
author | 2014-03-16 13:12:01 -0400 | |
---|---|---|
committer | 2014-03-16 13:12:01 -0400 | |
commit | 54f022c6c81281774400fb495b160caadd10bbb7 (patch) | |
tree | 03ad8f88e8f947b4873d103420d5f5e808c5e8dc | |
parent | Add a check for dev-python/python-exec rev-deps. (diff) | |
download | python-updater-54f022c6c81281774400fb495b160caadd10bbb7.tar.gz python-updater-54f022c6c81281774400fb495b160caadd10bbb7.tar.bz2 python-updater-54f022c6c81281774400fb495b160caadd10bbb7.zip |
Incorporate prefix support.
-rwxr-xr-x | python-updater | 77 |
1 files changed, 47 insertions, 30 deletions
diff --git a/python-updater b/python-updater index 2d44706..68c6ead 100755 --- a/python-updater +++ b/python-updater @@ -29,7 +29,7 @@ VERSION="0.11" OLD_PYTHON_VERSIONS="" OLD_PYTHON2_VERSIONS="" OLD_PYTHON3_VERSIONS="" -NEW_PYTHON_VERSION="$(/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" +NEW_PYTHON_VERSION="$("@GENTOO_PORTAGE_EPREFIX@"/usr/bin/python -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" NEW_PYTHON2_VERSION="" NEW_PYTHON3_VERSION="" @@ -62,10 +62,10 @@ CHECK_SHARED_LINKING="1" CHECK_STATIC_LINKING="1" # Load the Gentoo-style info macros, but hack to get around it thinking this is an rc script. -EBUILD="1" . /etc/init.d/functions.sh +EBUILD="1" . "@GENTOO_PORTAGE_EPREFIX@"/etc/init.d/functions.sh # Portage variables. -PKG_DBDIR="/var/db/pkg" +PKG_DBDIR="@GENTOO_PORTAGE_EPREFIX@/var/db/pkg" shopt -s expand_aliases @@ -146,7 +146,7 @@ has() { # has_version(cpv) has_version() { if [[ "${PMS_COMMAND[${PMS_INDEX}]}" == "emerge" ]]; then - /usr/bin/portageq has_version / "${1}" + "@GENTOO_PORTAGE_EPREFIX@"/usr/bin/portageq has_version "@GENTOO_PORTAGE_EPREFIX@"/ "${1}" elif [[ "${PMS_COMMAND[${PMS_INDEX}]}" == "pmerge" ]]; then pquery --vdb "${1}" else @@ -157,7 +157,7 @@ has_version() { # get_ebuild_path(CATEGORY, PN, SLOT) get_ebuild_path() { # These manual calls to Portage API are 2 times faster than 'portageq get_repo_path / "$(portageq metadata / ebuild "$(portageq best_visible / "${1}")" repository)"'. - /usr/bin/python -c " + "@GENTOO_PORTAGE_EPREFIX@"/usr/bin/python -c " import sys if '' in sys.path: @@ -165,7 +165,7 @@ if '' in sys.path: import portage -dbapi = portage.db['/']['porttree'].dbapi +dbapi = portage.db['@GENTOO_PORTAGE_EPREFIX@/']['porttree'].dbapi pkg_list = dbapi.match('${1}/${2}${3:+:}${3}') if pkg_list: best_visible = portage.best(pkg_list) @@ -241,7 +241,7 @@ unset_unless_changed() { local variable for variable in "$@"; do - if eval "[[ \${${variable}} == \$(env -u ${variable} /usr/bin/portageq envvar ${variable}) ]]"; then + if eval "[[ \${${variable}} == \$(env -u ${variable} "@GENTOO_PORTAGE_EPREFIX@"/usr/bin/portageq envvar ${variable}) ]]"; then unset ${variable} fi done @@ -253,14 +253,14 @@ global_USE_PYTHON="" get_USE_PYTHON() { if [[ "${PMS_COMMAND[${PMS_INDEX}]}" =~ ^(emerge|pmerge)$ ]]; then if [[ -z "${global_USE_PYTHON}" ]]; then - global_USE_PYTHON="$(/usr/bin/portageq envvar USE_PYTHON)" + global_USE_PYTHON="$("@GENTOO_PORTAGE_EPREFIX@"/usr/bin/portageq envvar USE_PYTHON)" fi USE_PYTHON="${global_USE_PYTHON}" - if [[ -f "/etc/portage/env/${1}/${2}" ]]; then - USE_PYTHON="$(. "/etc/portage/env/${1}/${2}"; echo "${USE_PYTHON}")" + if [[ -f "@GENTOO_PORTAGE_EPREFIX@/etc/portage/env/${1}/${2}" ]]; then + USE_PYTHON="$(. "@GENTOO_PORTAGE_EPREFIX@/etc/portage/env/${1}/${2}"; echo "${USE_PYTHON}")" fi - if [[ -f "/etc/portage/env/${1}/${2}:${3}" ]]; then - USE_PYTHON="$(. "/etc/portage/env/${1}/${2}:${3}"; echo "${USE_PYTHON}")" + if [[ -f "@GENTOO_PORTAGE_EPREFIX@/etc/portage/env/${1}/${2}:${3}" ]]; then + USE_PYTHON="$(. "@GENTOO_PORTAGE_EPREFIX@/etc/portage/env/${1}/${2}:${3}"; echo "${USE_PYTHON}")" fi else USE_PYTHON="$(cave print-id-environment-variable "${1}/${2}${3:+:}${3}::/?" --best --format %v --variable-name USE_PYTHON)" @@ -498,23 +498,23 @@ while (($#)); do done if [[ "${PMS_COMMAND[${PMS_INDEX}]}" == "emerge" ]]; then - sed="$(/usr/bin/python -c "import os; print(os.path.dirname(os.path.realpath('$(type -p emerge)')))")/ebuild-helpers/sed" + sed="$("@GENTOO_PORTAGE_EPREFIX@"/usr/bin/python -c "import os; print(os.path.dirname(os.path.realpath('$(type -p emerge)')))")/ebuild-helpers/sed" if [[ -x "${sed}" ]]; then alias sed="${sed}" fi fi if has_version "=dev-lang/python-2*"; then - if [[ "$(readlink /usr/bin/python2)" != "python2."* ]]; then - die "'/usr/bin/python2' is not valid symlink" + if [[ "$(readlink "@GENTOO_PORTAGE_EPREFIX@"/usr/bin/python2)" != "python2."* ]]; then + die "'@GENTOO_PORTAGE_EPREFIX@/usr/bin/python2' is not valid symlink" fi - NEW_PYTHON2_VERSION="$(/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" + NEW_PYTHON2_VERSION="$("@GENTOO_PORTAGE_EPREFIX@"/usr/bin/python2 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" fi if has_version "=dev-lang/python-3*"; then - if [[ "$(readlink /usr/bin/python3)" != "python3."* ]]; then - die "'/usr/bin/python3' is not valid symlink" + if [[ "$(readlink "@GENTOO_PORTAGE_EPREFIX@"/usr/bin/python3)" != "python3."* ]]; then + die "'@GENTOO_PORTAGE_EPREFIX@/usr/bin/python3' is not valid symlink" fi - NEW_PYTHON3_VERSION="$(/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" + NEW_PYTHON3_VERSION="$("@GENTOO_PORTAGE_EPREFIX@"/usr/bin/python3 -c 'from sys import version_info; print(".".join([str(x) for x in version_info[:2]]))')" fi if [[ -z "${NEW_PYTHON2_VERSION}" && -z "${NEW_PYTHON3_VERSION}" ]]; then die "Python 2 and Python 3 not installed" @@ -524,10 +524,15 @@ OLD_PYTHON_SHARED_LIBRARIES_REGEX="" for python_version in ${PYTHON_VERSIONS}; do if [[ "${python_version}" != "${NEW_PYTHON_VERSION}" ]]; then OLD_PYTHON_VERSIONS+="${OLD_PYTHON_VERSIONS:+ }${python_version}" - soname="$(readlink -n /usr/lib/libpython${python_version}.so)" + soname="$(readlink -n "@GENTOO_PORTAGE_EPREFIX@"/usr/lib/libpython${python_version}.so)" if [[ -z "${soname}" ]]; then # Use relatively safe, default value. - soname="libpython${python_version}.so.1.0" + if [[ -f "@GENTOO_PORTAGE_EPREFIX@"/usr/lib/libpython${python_version}.dylib ]] ; then + # there is no versioned dylib on Darwin + soname="libpython${python_version}.dylib" + else + soname="libpython${python_version}.so.1.0" + fi fi OLD_PYTHON_SHARED_LIBRARIES_REGEX+="${OLD_PYTHON_SHARED_LIBRARIES_REGEX:+|}${soname//./\.}" fi @@ -540,10 +545,15 @@ OLD_PYTHON2_SHARED_LIBRARIES_REGEX="" for python_version in ${PYTHON2_VERSIONS}; do if [[ "${python_version}" != "${NEW_PYTHON2_VERSION}" ]]; then OLD_PYTHON2_VERSIONS+="${OLD_PYTHON2_VERSIONS:+ }${python_version}" - soname="$(readlink -n /usr/lib/libpython${python_version}.so)" + soname="$(readlink -n "@GENTOO_PORTAGE_EPREFIX@"/usr/lib/libpython${python_version}.so)" if [[ -z "${soname}" ]]; then # Use relatively safe, default value. - soname="libpython${python_version}.so.1.0" + if [[ -f "@GENTOO_PORTAGE_EPREFIX@"/usr/lib/libpython${python_version}.dylib ]] ; then + # there is no versioned dylib on Darwin + soname="libpython${python_version}.dylib" + else + soname="libpython${python_version}.so.1.0" + fi fi OLD_PYTHON2_SHARED_LIBRARIES_REGEX+="${OLD_PYTHON2_SHARED_LIBRARIES_REGEX:+|}${soname//./\.}" fi @@ -556,10 +566,15 @@ OLD_PYTHON3_SHARED_LIBRARIES_REGEX="" for python_version in ${PYTHON3_VERSIONS}; do if [[ "${python_version}" != "${NEW_PYTHON3_VERSION}" ]]; then OLD_PYTHON3_VERSIONS+="${OLD_PYTHON3_VERSIONS:+ }${python_version}" - soname="$(readlink -n /usr/lib/libpython${python_version}.so)" + soname="$(readlink -n "@GENTOO_PORTAGE_EPREFIX@"/usr/lib/libpython${python_version}.so)" if [[ -z "${soname}" ]]; then # Use relatively safe, default value. - soname="libpython${python_version}.so.1.0" + if [[ -f "@GENTOO_PORTAGE_EPREFIX@"/usr/lib/libpython${python_version}.dylib ]] ; then + # there is no versioned dylib on Darwin + soname="libpython${python_version}.dylib" + else + soname="libpython${python_version}.so.1.0" + fi fi OLD_PYTHON3_SHARED_LIBRARIES_REGEX+="${OLD_PYTHON3_SHARED_LIBRARIES_REGEX:+|}${soname//./\.}" fi @@ -570,7 +585,7 @@ OLD_PYTHON3_SHARED_LIBRARIES_REGEX="(${OLD_PYTHON3_SHARED_LIBRARIES_REGEX})" declare -A PYTHON_GLOBALLY_SUPPORTED_ABIS if [[ "${PMS_COMMAND[${PMS_INDEX}]}" == "emerge" ]]; then - eval "$(/usr/bin/python -c \ + eval "$("@GENTOO_PORTAGE_EPREFIX@"/usr/bin/python -c \ "import re import sys @@ -589,7 +604,7 @@ variables = [ for variable in variables: exec('%(variable)s_regex = re.compile(r\'^%(variable)s=\((.*)\)\')' % {'variable': variable}) -dbapi = portage.db['/']['porttree'].dbapi +dbapi = portage.db['@GENTOO_PORTAGE_EPREFIX@/']['porttree'].dbapi python_eclass_locations = {} if hasattr(dbapi.repositories.mainRepo(), 'eclass_db'): @@ -849,7 +864,7 @@ for contents_file in $(find ${PKG_DBDIR}/ -name CONTENTS | sort); do fi if [[ "${CHECK_STATIC_LINKING}" -ne 0 ]]; then - binaries="$(scanelf -qs +Py_Initialize < <(grep -E "^obj" "${contents_file}" | cut -d" " -f2 | grep -Ev "^/usr/lib(32|64)?/debug/") | sed "s/.* //")" + binaries="$(scanelf -qs +Py_Initialize < <(grep -E "^obj" "${contents_file}" | cut -d" " -f2 | grep -Ev "^@GENTOO_PORTAGE_EPREFIX@/usr/lib(32|64)?/debug/") | sed "s/.* //")" if [[ -n "${binaries}" ]]; then PKGS_TO_REMERGE+=" ${CATPKGVER}" eindent @@ -908,7 +923,9 @@ for contents_file in $(find ${PKG_DBDIR}/ -name CONTENTS | sort); do fi if [[ "${CHECK_SHARED_LINKING}" -ne 0 ]]; then - binaries="$(scanelf -qF "%F %n" < <(grep -E "^obj" "${contents_file}" | cut -d" " -f2 | grep -Ev "^/usr/lib(32|64)?/debug/") | grep -E "( |,)$(get_OLD_PYTHON_SHARED_LIBRARIES_REGEX)(,|$)")" + binaries="$(scanelf -qF "%F %n" < <(grep -E "^obj" "${contents_file}" | cut -d" " -f2 | grep -Ev "^@GENTOO_PORTAGE_EPREFIX@/usr/lib(32|64)?/debug/") | grep -E "( |,)$(get_OLD_PYTHON_SHARED_LIBRARIES_REGEX)(,|$)")" + [[ -z ${binaries} ]] && \ + binaries="$(scanmacho -qF "%F %n" < <(grep -E "^obj" "${contents_file}" | cut -d" " -f2) | grep -E "( |,)$(get_OLD_PYTHON_SHARED_LIBRARIES_REGEX)(,|$)")" if [[ -n "${binaries}" ]]; then PKGS_TO_REMERGE+=" ${CATPKGVER}" eindent @@ -938,7 +955,7 @@ fi if [[ "${PMS_COMMAND[${PMS_INDEX}]}" == "emerge" ]] ; then # Filter out --getbinpkg, --getbinpkgonly, --usepkg and --usepkgonly options in EMERGE_DEFAULT_OPTS environment variable emerge_default_opts="" - for option in $(/usr/bin/portageq envvar EMERGE_DEFAULT_OPTS); do + for option in $("@GENTOO_PORTAGE_EPREFIX@"/usr/bin/portageq envvar EMERGE_DEFAULT_OPTS); do if [[ "${option}" == -[[:alnum:]]* ]]; then [[ "${option//[gGkK]/}" != "-" ]] && emerge_default_opts+=" ${option//[gGkK]/}" elif [[ "${option}" != "--getbinpkg" && "${option}" != "--getbinpkgonly" && "${option}" != "--usepkg" && "${option}" != "--usepkgonly" ]]; then |