summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArfrever Frehtes Taifersar Arahesis <arfrever.fta@gmail.com>2011-12-24 23:22:29 +0000
committerArfrever Frehtes Taifersar Arahesis <arfrever.fta@gmail.com>2011-12-24 23:22:29 +0000
commitebe69e3688f568c075f6eeb7e9728a6ee04d0b65 (patch)
treec3038d5ede26e908b542368928fa8e05820d28da
parentImprove PATH. (diff)
downloadpython-updater-ebe69e3688f568c075f6eeb7e9728a6ee04d0b65.tar.gz
python-updater-ebe69e3688f568c075f6eeb7e9728a6ee04d0b65.tar.bz2
python-updater-ebe69e3688f568c075f6eeb7e9728a6ee04d0b65.zip
Add support for updating of USE flags in IUSE in packages supporting installation for multiple Python ABIs in EAPI >= 4-python.
-rwxr-xr-xpython-updater136
1 files changed, 120 insertions, 16 deletions
diff --git a/python-updater b/python-updater
index cd3803c..3af7a5e 100755
--- a/python-updater
+++ b/python-updater
@@ -128,6 +128,19 @@ die() {
exit 1
}
+# has(checked_element, list)
+has() {
+ local checked_element="${1}"
+ shift
+
+ local argument
+ for argument in "${@}"; do
+ [[ "${checked_element}" == "${argument}" ]] && return 0
+ done
+
+ return 1
+}
+
# has_version(cpv)
has_version() {
if [[ "${PMS_COMMAND[${PMS_INDEX}]}" == "emerge" ]]; then
@@ -241,9 +254,9 @@ if pkg_list:
if best_visible:
repository = dbapi.aux_get(best_visible, ['repository'])
if repository:
- repository_path = dbapi.getRepositoryPath(repository[0])
- if repository_path:
- print(repository_path + '/${1}/${2}/' + best_visible.split('/')[1] + '.ebuild')"
+ repository_location = dbapi.getRepositoryPath(repository[0])
+ if repository_location:
+ print(repository_location + '/${1}/${2}/' + best_visible.split('/')[1] + '.ebuild')"
}
# get_RESTRICT_PYTHON_ABIS(CATEGORY, PN, SLOT)
@@ -311,7 +324,7 @@ check_python_abi_matching() {
patterns="${2// /$'\n'}"
while read pattern; do
- if _python_check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
+ if check_python_abi_matching "${PYTHON_ABI}" "${pattern}"; then
return 0
fi
done <<< "${patterns}"
@@ -526,10 +539,79 @@ OLD_PYTHON3_VERSIONS_REGEX="(${OLD_PYTHON3_VERSIONS// /|})"
OLD_PYTHON3_VERSIONS_REGEX="${OLD_PYTHON3_VERSIONS_REGEX//./\.}"
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 \
+"import re
+import sys
+
+if '' in sys.path:
+ sys.path.remove('')
+
+import portage
+
+variables = [
+ '_CPYTHON2_GLOBALLY_SUPPORTED_ABIS',
+ '_CPYTHON3_GLOBALLY_SUPPORTED_ABIS',
+ '_JYTHON_GLOBALLY_SUPPORTED_ABIS',
+ '_PYPY_GLOBALLY_SUPPORTED_ABIS'
+]
+
+for variable in variables:
+ exec('%(variable)s_regex = re.compile(r\'^%(variable)s=\((.*)\)\')' % {'variable': variable})
+
+dbapi = portage.db['/']['porttree'].dbapi
+python_eclass_locations = {}
+
+if hasattr(dbapi.repositories.mainRepo(), 'eclass_db'):
+ # Portage >=2.1.10.40 or >=2.2.0_alpha80.
+ for repository in dbapi.repositories:
+ python_eclass_location = repository.eclass_db.eclasses['python'].location
+ python_eclass_locations[repository.name] = python_eclass_location
+else:
+ for repository_location in dbapi._repo_info:
+ repository = dbapi._repo_info[repository_location].name
+ python_eclass_location = dbapi._repo_info[repository_location].eclass_db.eclasses['python'].location
+ python_eclass_locations[repository] = python_eclass_location
+
+for repository, python_eclass_location in python_eclass_locations.items():
+ for variable in variables:
+ exec('%s = []' % variable)
+ python_eclass = open(python_eclass_location)
+ python_eclass_lines = python_eclass.readlines()
+ python_eclass.close()
+ for python_eclass_line in python_eclass_lines:
+ for variable in variables:
+ exec(
+ '%(variable)s_matched = %(variable)s_regex.match(python_eclass_line)\n'
+ 'if %(variable)s_matched is not None:\n'
+ ' %(variable)s = %(variable)s_matched.group(1).split(\' \')'
+ % {'variable': variable}
+ )
+ python_globally_supported_abis = []
+ for variable in variables:
+ exec('python_globally_supported_abis.extend(%s)' % variable)
+ print('PYTHON_GLOBALLY_SUPPORTED_ABIS[%s]=\"%s\"' % (repository, ' '.join(python_globally_supported_abis)))")"
+fi
+
+for repository in "${!PYTHON_GLOBALLY_SUPPORTED_ABIS[@]}"; do
+ USE_flags=""
+ for PYTHON_ABI in ${PYTHON_GLOBALLY_SUPPORTED_ABIS[${repository}]}; do
+ USE_flags+="${USE_flags:+ }python_abis_${PYTHON_ABI}"
+ done
+ PYTHON_GLOBALLY_SUPPORTED_USE_FLAGS[${repository}]="${USE_flags}"
+done
+
einfo $'\e[1;34mStarting Python Updater...\e[0m'
-einfo $'\e[1;36m'"Main active version of Python: ${NEW_PYTHON_VERSION}"$'\e[0m'
-einfo $'\e[1;36m'"Active version of Python 2: ${NEW_PYTHON2_VERSION:-(None)}"$'\e[0m'
-einfo $'\e[1;36m'"Active version of Python 3: ${NEW_PYTHON3_VERSION:-(None)}"$'\e[0m'
+einfo $'\e[1;36m'"Main active version of Python: ${NEW_PYTHON_VERSION}"$'\e[0m'
+einfo $'\e[1;36m'"Active version of Python 2: ${NEW_PYTHON2_VERSION:-(None)}"$'\e[0m'
+einfo $'\e[1;36m'"Active version of Python 3: ${NEW_PYTHON3_VERSION:-(None)}"$'\e[0m'
+einfo $'\e[1;36m'"Globally supported Python ABIs in installed repositories:"$'\e[0m'
+eindent
+for repository in $(echo "${!PYTHON_GLOBALLY_SUPPORTED_ABIS[@]}" | sed -e "s/ /\n/g" | sort); do
+ einfo $'\e[1;36m'"${repository}: $(for ((i = 0; i < 30 - ${#repository}; i++)); do echo -n " "; done)${PYTHON_GLOBALLY_SUPPORTED_ABIS[${repository}]}"$'\e[0m'
+done
+eoutdent
if [[ CHECK_SHARED_LINKING -ne 0 ]]; then
if ! type -P scanelf >/dev/null 2>&1; then
@@ -565,8 +647,8 @@ fi
# Iterate through the contents of all the installed packages.
# ${PKG_DBDIR} must be followed by '/' to avoid problems when ${PKG_DBDIR} is a symlink.
-for content in $(find ${PKG_DBDIR}/ -name CONTENTS | sort); do
- environment_file="${content/CONTENTS/environment.bz2}"
+for contents_file in $(find ${PKG_DBDIR}/ -name CONTENTS | sort); do
+ environment_file="${contents_file%CONTENTS}environment.bz2"
# Extract some variables. EAPI, PYTHON_MULTIPLE_ABIS/SUPPORT_PYTHON_ABIS, PYTHON_ABIS and PYTHON_REQUESTED_ACTIVE_VERSION are optional.
get_vdb_variable PVR "${environment_file}" || die "Missing metadata in '${environment_file}' file. Manually reinstall corresponding package."
@@ -580,8 +662,8 @@ for content in $(find ${PKG_DBDIR}/ -name CONTENTS | sort); do
CATEGORY="$(echo "${environment_file#${PKG_DBDIR}/}" | sed -e "s:/.*::")"
PF="$(echo "${environment_file#${PKG_DBDIR}/${CATEGORY}/}" | sed -e "s:/.*::")"
PN="${PF%-${PVR}}"
- if [[ -f "${content/CONTENTS/SLOT}" ]]; then
- SLOT="$(<"${content/CONTENTS/SLOT}")"
+ if [[ -f "${contents_file%CONTENTS}SLOT" ]]; then
+ SLOT="$(<"${contents_file%CONTENTS}SLOT")"
else
get_vdb_variable SLOT "${environment_file}"
fi
@@ -630,9 +712,31 @@ for content in $(find ${PKG_DBDIR}/ -name CONTENTS | sort); do
continue
fi
+ if [[ -n "${PYTHON_MULTIPLE_ABIS}" && "${EAPI}" =~ ^4-python$ ]]; then
+ # Potentially update USE flags in IUSE in EAPI >= 4-python.
+ if [[ "${PRETEND}" -eq 0 && -f "${contents_file%CONTENTS}IUSE" && -f "${contents_file%CONTENTS}USE" && -f "${contents_file%CONTENTS}repository" ]]; then
+ IUSE="$(<"${contents_file%CONTENTS}IUSE")"
+ USE="$(<"${contents_file%CONTENTS}USE")"
+ repository="$(<"${contents_file%CONTENTS}repository")"
+ [[ "${repository}" == "python" ]] && repository="progress"
+ if [[ -n "${#PYTHON_GLOBALLY_SUPPORTED_USE_FLAGS[${repository}]}" ]]; then
+ for USE_flag in ${IUSE}; do
+ if ! has "${USE_flag}" ${PYTHON_GLOBALLY_SUPPORTED_USE_FLAGS[${repository}]} && ! has "${USE_flag}" ${USE}; then
+ sed -e "s/\(^\| \)${USE_flag}\($\| \)/\1\2/;s/^ //;s/ / /g;s/ $//" -i "${contents_file%CONTENTS}IUSE"
+ fi
+ done
+ for USE_flag in ${PYTHON_GLOBALLY_SUPPORTED_USE_FLAGS[${repository}]}; do
+ if ! has "${USE_flag}" ${IUSE}; then
+ sed -e "s/$/ ${USE_flag}/" -i "${contents_file%CONTENTS}IUSE"
+ fi
+ done
+ fi
+ fi
+ # Don't run any checks in EAPI >= 4-python.
+ continue
+ fi
+
if [[ CHECK_PYTHON_ABIS -ne 0 ]]; then
- # Don't run PYTHON_ABIS check in EAPI >= 4-python.
- [[ "${EAPI}" =~ ^(0|1|2|3|4)?$ ]] || continue
if [[ -n "${PYTHON_MULTIPLE_ABIS}" || -n "${SUPPORT_PYTHON_ABIS}" ]]; then
new_PYTHON_ABIS=""
RESTRICT_PYTHON_ABIS="$(get_RESTRICT_PYTHON_ABIS "${CATEGORY}" "${PN}" "${SLOT}")"
@@ -668,7 +772,7 @@ for content in $(find ${PKG_DBDIR}/ -name CONTENTS | sort); do
fi
if [[ CHECK_STATIC_LINKING -ne 0 ]]; then
- binaries="$(scanelf -qs +Py_Initialize < <(grep -E "^obj" "${content}" | 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 "^/usr/lib(32|64)?/debug/") | sed "s/.* //")"
if [[ -n "${binaries}" ]]; then
PKGS_TO_REMERGE+=" ${CATPKGVER}"
eindent
@@ -715,7 +819,7 @@ for content in $(find ${PKG_DBDIR}/ -name CONTENTS | sort); do
# /usr/lib/python$old
# /usr/lib32/python$old
# /usr/lib64/python$old
- if grep -qE "/usr/(include|lib(32|64)?)/python$(get_OLD_PYTHON_VERSIONS_REGEX)" "${content}"; then
+ if grep -qE "/usr/(include|lib(32|64)?)/python$(get_OLD_PYTHON_VERSIONS_REGEX)" "${contents_file}"; then
PKGS_TO_REMERGE+=" ${CATPKGVER}"
eindent
einfo "Adding to list: ${CATPKGVER}"
@@ -727,7 +831,7 @@ for content in $(find ${PKG_DBDIR}/ -name CONTENTS | sort); do
fi
if [[ CHECK_SHARED_LINKING -ne 0 ]]; then
- binaries="$(scanelf -qF "%F %n" < <(grep -E "^obj" "${content}" | 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 "^/usr/lib(32|64)?/debug/") | grep -E "( |,)$(get_OLD_PYTHON_SHARED_LIBRARIES_REGEX)(,|$)")"
if [[ -n "${binaries}" ]]; then
PKGS_TO_REMERGE+=" ${CATPKGVER}"
eindent