Merged from trunk -r14567:14577
authorFabian Groffen <grobian@gentoo.org>
Wed, 14 Oct 2009 19:24:16 +0000 (19:24 -0000)
committerFabian Groffen <grobian@gentoo.org>
Wed, 14 Oct 2009 19:24:16 +0000 (19:24 -0000)
   | 14568    | Set EPYTHON variable as empty when calling portageq or      |
   | arfrever | dohtml to avoid using potentially unsupported version of    |
   |          | Python.                                                     |

   | 14570    | Add some more EPYTHON safety.                               |
   | zmedico  |                                                             |

   | 14573    | Fix python shebangs. s:/usr/bin/env python:/usr/bin/python: |
   | zmedico  |                                                             |

   | 14575    | Add a xpak-helper.py script, so that shell code always      |
   | zmedico  | calls python via a shebang.                                 |

   | 14577    | Bug #288551 - Fix portageq to handle                        |
   | zmedico  | portage.exception.AmbiguousPackageName instead of           |
   |          | ValueError.                                                 |

svn path=/main/branches/prefix/; revision=14603

bin/ebuild.sh
bin/misc-functions.sh
bin/portageq
bin/xpak-helper.py [new file with mode: 0755]

index 18c60b27e12265c1301159b6b3f45c84081c7ef0..42d23324b960dcb995e33949f5c34affa2e84e81 100755 (executable)
@@ -162,13 +162,16 @@ useq() {
        fi
 }
 
+# Return true if given package is installed. Otherwise return false.
+# Takes single depend-type atoms.
 has_version() {
        if [ "${EBUILD_PHASE}" == "depend" ]; then
                die "portageq calls (has_version calls portageq) are not allowed in the global scope"
        fi
-       # return shell-true/shell-false if exists.
-       # Takes single depend-type atoms.
-       PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
+
+       # Set EPYTHON variable as empty so that portageq doesn't try
+       # to use potentially unsupported version of Python.
+       EPYTHON= PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
        "${PORTAGE_BIN_PATH}"/portageq has_version "${ROOT}" "$1"
        local retval=$?
        case "${retval}" in
@@ -188,7 +191,10 @@ portageq() {
        if [ "${EBUILD_PHASE}" == "depend" ]; then
                die "portageq calls are not allowed in the global scope"
        fi
-       PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
+
+       # Set EPYTHON variable as empty so that portageq doesn't try
+       # to use potentially unsupported version of Python.
+       EPYTHON= PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
        "${PORTAGE_BIN_PATH}/portageq" "$@"
 }
 
@@ -198,13 +204,16 @@ portageq() {
 # ----------------------------------------------------------------------------
 
 
+# Returns the best/most-current match.
+# Takes single depend-type atoms.
 best_version() {
        if [ "${EBUILD_PHASE}" == "depend" ]; then
                die "portageq calls (best_version calls portageq) are not allowed in the global scope"
        fi
-       # returns the best/most-current match.
-       # Takes single depend-type atoms.
-       PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
+
+       # Set EPYTHON variable as empty so that portageq doesn't try
+       # to use potentially unsupported version of Python.
+       EPYTHON= PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
        "${PORTAGE_BIN_PATH}/portageq" 'best_version' "${ROOT}" "$1"
        local retval=$?
        case "${retval}" in
@@ -220,6 +229,13 @@ best_version() {
        esac
 }
 
+dohtml() {
+       # Set EPYTHON variable as empty so that dohtml doesn't try
+       # to use potentially unsupported version of Python.
+       EPYTHON= PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
+       "${PORTAGE_BIN_PATH}/ebuild-helpers/dohtml" "$@"
+}
+
 use_with() {
        if [ -z "$1" ]; then
                echo "!!! use_with() called without a parameter." >&2
@@ -1637,7 +1653,7 @@ filter_readonly_variables() {
                "
        fi
 
-       "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}"
+       EPYTHON= "${PORTAGE_BIN_PATH}"/filter-bash-environment.py "${filtered_vars}"
 }
 
 # @FUNCTION: preprocess_ebuild_env
index 3ef1d0b21a669f20169a885165731efa3bdd0823..8e658f408db1260388daa63fceb4e6bc54dab085 100644 (file)
@@ -736,7 +736,7 @@ install_qa_check() {
                done
                [[ $reset_debug = 1 ]] && set -x
                f=$(cat "${PORTAGE_LOG_FILE}" | \
-                       "$PORTAGE_BIN_PATH"/check-implicit-pointer-usage.py)
+                       EPYTHON= "$PORTAGE_BIN_PATH"/check-implicit-pointer-usage.py)
                if [[ -n ${f} ]] ; then
 
                        # In the future this will be a forced "die". In preparation,
@@ -1005,8 +1005,9 @@ dyn_package() {
        tar $tar_options -cf - $PORTAGE_BINPKG_TAR_OPTS -C "${D}" . | \
                bzip2 -cf > "$PORTAGE_BINPKG_TMPFILE"
        assert "failed to pack binary package: '$PORTAGE_BINPKG_TMPFILE'"
-       PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
-       python -c "from portage import xpak; t=xpak.tbz2('${PORTAGE_BINPKG_TMPFILE}'); t.recompose('${PORTAGE_BUILDDIR}/build-info')"
+       EPYTHON= PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
+               "$PORTAGE_BIN_PATH"/xpak-helper.py recompose \
+               "$PORTAGE_BINPKG_TMPFILE" "$PORTAGE_BUILDDIR/build-info"
        if [ $? -ne 0 ]; then
                rm -f "${PORTAGE_BINPKG_TMPFILE}"
                die "Failed to append metadata to the tbz2 file"
index f6c2ae590d17165b84b16b1ae1952ae2de4aa972..eb0b150a7896453ac67e7a3b087a207283ffbd10 100755 (executable)
@@ -630,11 +630,7 @@ def main():
        except portage.exception.ParseError as e:
                sys.stderr.write("%s\n" % str(e))
                sys.exit(1)
-       except ValueError as e:
-               if not e.args or \
-                       not hasattr(e.args[0], "__len__") or \
-                       len(e.args[0]) < 2:
-                       raise
+       except portage.exception.AmbiguousPackageName as e:
                # Multiple matches thrown from cpv_expand
                pkgs = e.args[0]
                # An error has occurred so we writemsg to stderr and exit nonzero.
diff --git a/bin/xpak-helper.py b/bin/xpak-helper.py
new file mode 100755 (executable)
index 0000000..a9b24a6
--- /dev/null
@@ -0,0 +1,69 @@
+#!@PORTAGE_PYTHON@
+# Copyright 2009 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+import optparse
+import sys
+import portage
+from portage import os
+
+def command_recompose(args):
+
+       usage = "usage: recompose <binpkg_path> <metadata_dir>\n"
+
+       if len(args) != 2:
+               sys.stderr.write(usage)
+               sys.stderr.write("2 arguments are required, got %s\n" % len(args))
+               return 1
+
+       binpkg_path, metadata_dir = args
+
+       if not os.path.isfile(binpkg_path):
+               sys.stderr.write(usage)
+               sys.stderr.write("Argument 1 is not a regular file: '%s'\n" % \
+                       binpkg_path)
+               return 1
+
+       if not os.path.isdir(metadata_dir):
+               sys.stderr.write(usage)
+               sys.stderr.write("Argument 2 is not a directory: '%s'\n" % \
+                       metadata_dir)
+               return 1
+
+       t = portage.xpak.tbz2(binpkg_path)
+       t.recompose(metadata_dir)
+       return os.EX_OK
+
+def main(argv):
+
+       if argv and sys.hexversion < 0x3000000 and not isinstance(argv[0], unicode):
+               for i, x in enumerate(argv):
+                       argv[i] = portage._unicode_decode(x, errors='strict')
+
+       valid_commands = ('recompose',)
+       description = "Perform metadata operations on a binary package."
+       usage = "usage: %s COMMAND [args]" % \
+               os.path.basename(argv[0])
+
+       parser = optparse.OptionParser(description=description, usage=usage)
+       options, args = parser.parse_args(argv[1:])
+
+       if not args:
+               parser.error("missing command argument")
+
+       command = args[0]
+
+       if command not in valid_commands:
+               parser.error("invalid command: '%s'" % command)
+
+       if command == 'recompose':
+               rval = command_recompose(args[1:])
+       else:
+               raise AssertionError("invalid command: '%s'" % command)
+
+       return rval
+
+if __name__ == "__main__":
+       rval = main(sys.argv[:])
+       sys.exit(rval)