]> arthur.barton.de Git - bup.git/blobdiff - lib/cmd/bup
save: make the py3 save commit message args match py2
[bup.git] / lib / cmd / bup
index c98d7e7eb62a368a6db7f826762dc9e903e50507..a23b595d35141a4fc5d766c08837811b29b5fa7f 100755 (executable)
@@ -1,6 +1,16 @@
 #!/bin/sh
-"""": # -*-python-*- # -*-python-*-
+"""": # -*-python-*-
 set -e
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
+# Find our directory
 top="$(pwd)"
 cmdpath="$0"
 # loop because macos doesn't have recursive readlink/realpath utils
@@ -11,25 +21,20 @@ while test -L "$cmdpath"; do
 done
 script_home="$(cd "$(dirname "$cmdpath")" && pwd -P)"
 cd "$top"
-exec "$script_home/bup-python" "$0" ${1+"$@"}
+exec "$script_home/../../config/bin/python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import, print_function
+
+import os, sys
+sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/..']
+
 import errno, getopt, os, re, select, signal, subprocess, sys
 from subprocess import PIPE
 
-from bup.compat import environ, restore_lc_env
+from bup.compat import environ, fsdecode
 from bup.io import path_msg
-
-if sys.version_info[0] != 2 \
-   and not environ.get(b'BUP_ALLOW_UNEXPECTED_PYTHON_VERSION') == b'true':
-    print('error: bup may crash with python versions other than 2, or eat your data',
-          file=sys.stderr)
-    sys.exit(2)
-
-restore_lc_env()
-
 from bup import compat, path, helpers
 from bup.compat import add_ex_tb, add_ex_ctx, argv_bytes, wrap_main
 from bup.helpers import atoi, columnate, debug1, log, merge_dict, tty_width
@@ -66,9 +71,9 @@ def usage(msg=""):
     cmds = []
     for c in sorted(os.listdir(cmdpath)):
         if c.startswith(b'bup-') and c.find(b'.') < 0:
-            cname = c[4:].decode('iso-8859-1')
+            cname = fsdecode(c[4:])
             if cname not in common:
-                cmds.append(c[4:])
+                cmds.append(c[4:].decode(errors='backslashreplace'))
     log(columnate(cmds, '    '))
     log('\n')
     
@@ -78,14 +83,14 @@ def usage(msg=""):
         log("\n%s\n" % msg)
     sys.exit(99)
 
-
-if len(sys.argv) < 2:
+argv = compat.argv
+if len(argv) < 2:
     usage()
 
 # Handle global options.
 try:
     optspec = ['help', 'version', 'debug', 'profile', 'bup-dir=']
-    global_args, subcmd = getopt.getopt(sys.argv[1:], '?VDd:', optspec)
+    global_args, subcmd = getopt.getopt(argv[1:], '?VDd:', optspec)
 except getopt.GetoptError as ex:
     usage('error: %s' % ex.msg)