Search for a "reasonable" python in ./configure (or respect PYTHON), and
use that to create a source tree cmd/python-cmd.sh that all
of the relevant invocations in the source tree respect.
During install, rewrite all of the relevant #! lines to refer to the
./configure selected Python.
(NOTE: this patch is unfinished. At a minimum, it doesn't cover the
test tools yet.)
Signed-off-by: Rob Browning <
r...@defaultvalue.org>
---
Plausible approach (roughly speaking)?
Makefile | 18 +++++++++++++-----
README.md | 6 ++++++
cmd/bloom-cmd.py | 7 ++++++-
cmd/cat-file-cmd.py | 7 ++++++-
cmd/daemon-cmd.py | 7 ++++++-
cmd/damage-cmd.py | 7 ++++++-
cmd/drecurse-cmd.py | 7 ++++++-
cmd/fsck-cmd.py | 7 ++++++-
cmd/ftp-cmd.py | 7 ++++++-
cmd/fuse-cmd.py | 7 ++++++-
cmd/help-cmd.py | 7 ++++++-
cmd/import-duplicity-cmd.py | 7 ++++++-
cmd/index-cmd.py | 7 ++++++-
cmd/init-cmd.py | 7 ++++++-
cmd/join-cmd.py | 7 ++++++-
cmd/list-idx-cmd.py | 7 ++++++-
cmd/ls-cmd.py | 7 ++++++-
cmd/margin-cmd.py | 7 ++++++-
cmd/memtest-cmd.py | 7 ++++++-
cmd/meta-cmd.py | 7 ++++++-
cmd/midx-cmd.py | 7 ++++++-
cmd/mux-cmd.py | 7 ++++++-
cmd/newliner-cmd.py | 7 ++++++-
cmd/on--server-cmd.py | 7 ++++++-
cmd/on-cmd.py | 7 ++++++-
cmd/random-cmd.py | 7 ++++++-
cmd/restore-cmd.py | 7 ++++++-
cmd/save-cmd.py | 7 ++++++-
cmd/server-cmd.py | 7 ++++++-
cmd/split-cmd.py | 7 ++++++-
cmd/tag-cmd.py | 7 ++++++-
cmd/tick-cmd.py | 7 ++++++-
cmd/version-cmd.py | 7 ++++++-
cmd/web-cmd.py | 7 ++++++-
cmd/xstat-cmd.py | 7 ++++++-
config/configure | 12 +++++++++++-
main.py | 8 +++++++-
37 files changed, 235 insertions(+), 40 deletions(-)
diff --git a/Makefile b/Makefile
index 988a9cc..6260553 100644
--- a/Makefile
+++ b/Makefile
@@ -30,8 +30,15 @@ Documentation/all: $(bup_deps)
$(current_sampledata):
t/configure-sampledata --setup
+PYTHON = $(shell cmd/bup-python -c 'import sys; print sys.executable')
+
+define install-python-bin
+ set -e; \
+ sed -e '1 s|.*|#!$(PYTHON)|; 2,/^# End preamble\.$$/d' $1 > $2; \
+ chmod 0755 $2;
+endef
+
INSTALL=install
-PYTHON=python
PREFIX=/usr
MANDIR=$(DESTDIR)$(PREFIX)/share/man
DOCDIR=$(DESTDIR)$(PREFIX)/share/doc/bup
@@ -49,10 +56,11 @@ install: all
$(INSTALL) -m 0644 \
Documentation/*.html \
$(DOCDIR)
- $(INSTALL) -pm 0755 bup $(BINDIR)
- $(INSTALL) -pm 0755 \
- cmd/bup-* \
- $(LIBDIR)/cmd
+ $(call install-python-bin,bup,"$(BINDIR)/bup")
+ set -e; \
+ for cmd in $$(ls cmd/bup-* | grep -v cmd/bup-python); do \
+ $(call install-python-bin,"$$cmd","$(LIBDIR)/$$cmd") \
+ done
$(INSTALL) -pm 0644 \
lib/bup/*.py \
$(LIBDIR)/bup
diff --git a/README.md b/README.md
index 7eb4c2d..01c2e5d 100644
--- a/README.md
+++ b/README.md
@@ -154,6 +154,12 @@ From source
make install DESTDIR=/opt/bup PREFIX=''
+ - The Python executable that bup will use is chosen by ./configure,
+ which will search for a reasonable version unless PYTHON is set in
+ the environment, in which case, bup will use that path. You can
+ see which Python executable was chosen by looking at the
+ configure output, or examining cmd/python-cmd.sh, and you can
+ change the selection by re-running ./configure.
From binary packages
--------------------
diff --git a/cmd/bloom-cmd.py b/cmd/bloom-cmd.py
index cd4506d..7e208cc 100755
--- a/cmd/bloom-cmd.py
+++ b/cmd/bloom-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, glob, tempfile
from bup import options, git, bloom
from bup.helpers import *
diff --git a/cmd/cat-file-cmd.py b/cmd/cat-file-cmd.py
index 8948ff2..9489429 100755
--- a/cmd/cat-file-cmd.py
+++ b/cmd/cat-file-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, stat
from bup import options, git, vfs
from bup.helpers import *
diff --git a/cmd/daemon-cmd.py b/cmd/daemon-cmd.py
index c90e3e4..c9f4493 100755
--- a/cmd/daemon-cmd.py
+++ b/cmd/daemon-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, getopt, socket, subprocess, fcntl
from bup import options, path
from bup.helpers import *
diff --git a/cmd/damage-cmd.py b/cmd/damage-cmd.py
index 49dbed0..8bf5bdc 100755
--- a/cmd/damage-cmd.py
+++ b/cmd/damage-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, os, random
from bup import options
from bup.helpers import *
diff --git a/cmd/drecurse-cmd.py b/cmd/drecurse-cmd.py
index cdf6680..504a63c 100755
--- a/cmd/drecurse-cmd.py
+++ b/cmd/drecurse-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
from os.path import relpath
from bup import options, drecurse
diff --git a/cmd/fsck-cmd.py b/cmd/fsck-cmd.py
index 794c755..d985647 100755
--- a/cmd/fsck-cmd.py
+++ b/cmd/fsck-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, os, glob, subprocess
from bup import options, git
from bup.helpers import *
diff --git a/cmd/ftp-cmd.py b/cmd/ftp-cmd.py
index baa1e08..fa6304b 100755
--- a/cmd/ftp-cmd.py
+++ b/cmd/ftp-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, os, stat, fnmatch
from bup import options, git, shquote, vfs, ls
from bup.helpers import *
diff --git a/cmd/fuse-cmd.py b/cmd/fuse-cmd.py
index 30776cb..577c4e4 100755
--- a/cmd/fuse-cmd.py
+++ b/cmd/fuse-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, os, errno
from bup import options, git, vfs, xstat
from bup.helpers import *
diff --git a/cmd/help-cmd.py b/cmd/help-cmd.py
index 56a4148..9dd9036 100755
--- a/cmd/help-cmd.py
+++ b/cmd/help-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, os, glob
from bup import options, path
diff --git a/cmd/import-duplicity-cmd.py b/cmd/import-duplicity-cmd.py
index 163d4fa..fc815b9 100755
--- a/cmd/import-duplicity-cmd.py
+++ b/cmd/import-duplicity-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
from calendar import timegm
from pipes import quote
diff --git a/cmd/index-cmd.py b/cmd/index-cmd.py
index 6f2adf4..e1349cb 100755
--- a/cmd/index-cmd.py
+++ b/cmd/index-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, stat, time, os, errno, re
from bup import metadata, options, git, index, drecurse, hlinkdb
diff --git a/cmd/init-cmd.py b/cmd/init-cmd.py
index 2e4a151..d3796b4 100755
--- a/cmd/init-cmd.py
+++ b/cmd/init-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys
from bup import git, options, client
diff --git a/cmd/join-cmd.py b/cmd/join-cmd.py
index 042b402..e7c83fd 100755
--- a/cmd/join-cmd.py
+++ b/cmd/join-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys
from bup import git, options, client
from bup.helpers import *
diff --git a/cmd/list-idx-cmd.py b/cmd/list-idx-cmd.py
index a3e3dc9..5d3c030 100755
--- a/cmd/list-idx-cmd.py
+++ b/cmd/list-idx-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, os
from bup import git, options
from bup.helpers import *
diff --git a/cmd/ls-cmd.py b/cmd/ls-cmd.py
index 94a7131..0b02519 100755
--- a/cmd/ls-cmd.py
+++ b/cmd/ls-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys
from bup import git, vfs, ls
from bup.helpers import *
diff --git a/cmd/margin-cmd.py b/cmd/margin-cmd.py
index 9b7fd60..0f4380e 100755
--- a/cmd/margin-cmd.py
+++ b/cmd/margin-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, struct, math
from bup import options, git, _helpers
from bup.helpers import *
diff --git a/cmd/memtest-cmd.py b/cmd/memtest-cmd.py
index 0e3cf0c..38fd7a9 100755
--- a/cmd/memtest-cmd.py
+++ b/cmd/memtest-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, re, struct, time, resource
from bup import git, bloom, midx, options, _helpers
from bup.helpers import *
diff --git a/cmd/meta-cmd.py b/cmd/meta-cmd.py
index cac26b5..bf96b29 100755
--- a/cmd/meta-cmd.py
+++ b/cmd/meta-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
# Copyright (C) 2010 Rob Browning
#
diff --git a/cmd/midx-cmd.py b/cmd/midx-cmd.py
index 6876751..8f7604e 100755
--- a/cmd/midx-cmd.py
+++ b/cmd/midx-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, math, struct, glob, resource
import tempfile
from bup import options, git, midx, _helpers, xstat
diff --git a/cmd/mux-cmd.py b/cmd/mux-cmd.py
index b70c0a8..7a7d8e4 100755
--- a/cmd/mux-cmd.py
+++ b/cmd/mux-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import os, sys, subprocess, struct
from bup import options
from bup.helpers import *
diff --git a/cmd/newliner-cmd.py b/cmd/newliner-cmd.py
index 68d327b..f95decc 100755
--- a/cmd/newliner-cmd.py
+++ b/cmd/newliner-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, os, re
from bup import options
from bup import _helpers # fixes up sys.argv on import
diff --git a/cmd/on--server-cmd.py b/cmd/on--server-cmd.py
index a6f3e21..fbdc86a 100755
--- a/cmd/on--server-cmd.py
+++ b/cmd/on--server-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, os, struct
from bup import options, helpers
diff --git a/cmd/on-cmd.py b/cmd/on-cmd.py
index 9d6f683..e5b1d6b 100755
--- a/cmd/on-cmd.py
+++ b/cmd/on-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, os, struct, getopt, subprocess, signal
from subprocess import PIPE
from bup import options, ssh, path
diff --git a/cmd/random-cmd.py b/cmd/random-cmd.py
index 4be3660..9ff30ee 100755
--- a/cmd/random-cmd.py
+++ b/cmd/random-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys
from bup import options, _helpers
from bup.helpers import *
diff --git a/cmd/restore-cmd.py b/cmd/restore-cmd.py
index d527489..fa532c5 100755
--- a/cmd/restore-cmd.py
+++ b/cmd/restore-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import copy, errno, sys, stat, re
from bup import options, git, metadata, vfs
from bup.helpers import *
diff --git a/cmd/save-cmd.py b/cmd/save-cmd.py
index fc93408..f7d8c5d 100755
--- a/cmd/save-cmd.py
+++ b/cmd/save-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, stat, time, math
from cStringIO import StringIO
from errno import EACCES
diff --git a/cmd/server-cmd.py b/cmd/server-cmd.py
index 43a3fce..12f6a69 100755
--- a/cmd/server-cmd.py
+++ b/cmd/server-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import os, sys, struct
from bup import options, git
from bup.helpers import *
diff --git a/cmd/split-cmd.py b/cmd/split-cmd.py
index 70daf7c..c724694 100755
--- a/cmd/split-cmd.py
+++ b/cmd/split-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import os, sys, time
from bup import hashsplit, git, options, client
from bup.helpers import *
diff --git a/cmd/tag-cmd.py b/cmd/tag-cmd.py
index f33855e..e29bdfb 100755
--- a/cmd/tag-cmd.py
+++ b/cmd/tag-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys
import os
diff --git a/cmd/tick-cmd.py b/cmd/tick-cmd.py
index 4d462ad..f86455e 100755
--- a/cmd/tick-cmd.py
+++ b/cmd/tick-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, time
from bup import options
diff --git a/cmd/version-cmd.py b/cmd/version-cmd.py
index 645f25f..1f8c38c 100755
--- a/cmd/version-cmd.py
+++ b/cmd/version-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys
from bup import options
from bup import _version
diff --git a/cmd/web-cmd.py b/cmd/web-cmd.py
index 1c515e2..0a61f90 100755
--- a/cmd/web-cmd.py
+++ b/cmd/web-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
import sys, stat, urllib, mimetypes, posixpath, time, webbrowser
import urllib
from bup import options, git, vfs
diff --git a/cmd/xstat-cmd.py b/cmd/xstat-cmd.py
index 85071d2..472a797 100755
--- a/cmd/xstat-cmd.py
+++ b/cmd/xstat-cmd.py
@@ -1,4 +1,9 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0"):$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
# Copyright (C) 2010 Rob Browning
#
# This code is covered under the terms of the GNU Library General
diff --git a/config/configure b/config/configure
index 8003241..a2afb83 100755
--- a/config/configure
+++ b/config/configure
@@ -56,8 +56,18 @@ if [ -z "$MAKE_VERSION" ]; then
fi
expr "$MAKE_VERSION" '>=' '3.81' || AC_FAIL "ERROR: $MAKE must be >= version 3.81"
-if test -z "$(bup_find_prog python '')"; then
+bup_python="$PYTHON"
+test -z "$bup_python" && bup_python="$(bup_find_prog python2.7 '')"
+test -z "$bup_python" && bup_python="$(bup_find_prog python2.6 '')"
+test -z "$bup_python" && bup_python="$(bup_find_prog python2 '')"
+test -z "$bup_python" && bup_python="$(bup_find_prog python '')"
+if test -z "$bup_python"; then
AC_FAIL "ERROR: unable to find python"
+else
+ echo "#!/bin/sh" > ../cmd/python-cmd.sh
+ printf "exec %q \"\$@\"" "$bup_python" >> ../cmd/python-cmd.sh
+ chmod u+x ../cmd/python-cmd.sh
+ cd ../cmd && ln -sf python-cmd.sh bup-python
fi
if test -z "$(bup_find_prog git '')"; then
diff --git a/main.py b/main.py
index 45a0e8a..c6d77ce 100755
--- a/main.py
+++ b/main.py
@@ -1,4 +1,10 @@
-#!/usr/bin/env python
+#!/bin/sh
+"""":
+export PATH="$(dirname "$0")/cmd:$PATH"
+exec bup-python $0 ${1+"$@"}
+"""
+# End preamble.
+
import sys, os, subprocess, signal, getopt
argv = sys.argv
--
2.1.4