Fix permissions and add option --mode

This commit is contained in:
Peter J. Holzer 2023-08-18 13:16:06 +02:00
parent c406d13ce8
commit 71565142ed
1 changed files with 5 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import sys
ap = argparse.ArgumentParser()
ap.add_argument("source")
ap.add_argument("destination")
ap.add_argument("--mode", "-m", type=lambda x: int(x, base=8))
args = ap.parse_args()
@ -22,6 +23,8 @@ with open(args.source) as inf:
outf.write(first_line)
for line in inf:
outf.write(line)
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)
shutil.copymode(args.source, args.destination)