install-python/install-python

31 lines
826 B
Plaintext
Raw Permalink Normal View History

#!/usr/bin/env python3
import argparse
import os
import shutil
import sys
ap = argparse.ArgumentParser()
ap.add_argument("source")
ap.add_argument("destination")
2023-08-18 13:16:06 +02:00
ap.add_argument("--mode", "-m", type=lambda x: int(x, base=8))
args = ap.parse_args()
with open(args.source) as inf:
tmp_dest = args.destination + "." + str(os.getpid())
with open(tmp_dest, "w") as outf:
first_line = inf.readline()
if first_line.startswith("#!"):
print("#!", sys.executable, file=outf)
else:
print("#!", sys.executable, file=outf)
outf.write(first_line)
for line in inf:
outf.write(line)
2023-08-18 13:16:06 +02:00
if args.mode is not None:
os.chmod(tmp_dest, args.mode)
else:
shutil.copymode(args.source, tmp_dest)
os.rename(tmp_dest, args.destination)