Add a xpak-helper.py script, so that shell code always calls python via
authorZac Medico <zmedico@gentoo.org>
Sun, 11 Oct 2009 22:51:08 +0000 (22:51 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 11 Oct 2009 22:51:08 +0000 (22:51 -0000)
a shebang. (trunk r14575)

svn path=/main/branches/2.1.7/; revision=14576

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

index 671a0693502a66850549e2e54124ff8ed5751edd..ef8b0a54a5699feb50b96e37bddc548f5de15f6b 100755 (executable)
@@ -711,7 +711,8 @@ dyn_package() {
                bzip2 -cf > "$PORTAGE_BINPKG_TMPFILE"
        assert "failed to pack binary package: '$PORTAGE_BINPKG_TMPFILE'"
        EPYTHON= PYTHONPATH=${PORTAGE_PYM_PATH}${PYTHONPATH:+:}${PYTHONPATH} \
-       python -c "from portage import xpak; t=xpak.tbz2('${PORTAGE_BINPKG_TMPFILE}'); t.recompose('${PORTAGE_BUILDDIR}/build-info')"
+               "$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"
diff --git a/bin/xpak-helper.py b/bin/xpak-helper.py
new file mode 100755 (executable)
index 0000000..e6e8680
--- /dev/null
@@ -0,0 +1,69 @@
+#!/usr/bin/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)