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