]> arthur.barton.de Git - bup.git/blob - dev/install-python-script
83d8861a22ca58988127785e0bd02f37c7c9e388
[bup.git] / dev / install-python-script
1 #!/bin/sh
2 """": # -*-python-*-
3 export LC_CTYPE=iso-8859-1
4 exec "$(dirname "$0")/../config/bin/python" "$0" "$@"
5 """
6
7 from __future__ import absolute_import, print_function
8 from tempfile import NamedTemporaryFile
9 import os, shutil, sys
10
11 if sys.version_info[0] >= 3:
12     from shlex import quote
13 else:
14     from pipes import quote
15
16 src_path, dest_path = sys.argv[1:]
17
18 with open(b'config/config.var/bup-python', 'rb') as src:
19     python = src.read()
20
21 with NamedTemporaryFile() as tmp:
22     # Replace the section between "Here to end..." and the end of the
23     # preamble with the correct 'exec PYTHON "$0"'.
24     with open(src_path, 'rb') as src:
25         for line in src:
26             if line.startswith(b'# Here to end of preamble replaced during install'):
27                 break
28             tmp.write(line)
29         for line in src:
30             if line == b'"""\n':
31                 break
32         tmp.write(b'exec %s "$0"\n' % python)
33         tmp.write(b'"""\n')
34         for line in src:
35             tmp.write(line)
36     tmp.flush()
37     shutil.copy(tmp.name, dest_path)
38     os.chmod(dest_path, 0o755)