From 51322aa86e90a87ef83d957fd1f44c6e614883a2 Mon Sep 17 00:00:00 2001 From: Esa Kataja Date: Wed, 15 Jan 2025 11:41:44 +0200 Subject: [PATCH] FIX Previous commit with writing of shell script --- src/lib/fs.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib/fs.py b/src/lib/fs.py index 4e9d67d..355a734 100644 --- a/src/lib/fs.py +++ b/src/lib/fs.py @@ -1,5 +1,19 @@ +from pathlib import Path +from os import chmod + + def sanitize_filename(filename: str) -> str: characters_not_allowed = ["<", ">", ":", '"', "/", "\\", "|", "?", "*", " ", "'"] for char in characters_not_allowed: filename = filename.replace(char, "") return filename + + +def write_shell_script(script: str, filename: Path): + if filename.exists(): + raise FileExistsError("encode.sh already exists") + with open(filename, "w") as f: + f.write("#!/bin/bash\n") + f.write(script) + + chmod(filename, 0o755)