FIX Previous commit with writing of shell script

This commit is contained in:
Esa Kataja
2025-01-15 11:41:44 +02:00
parent 3842cb4ae2
commit 51322aa86e
+14
View File
@@ -1,5 +1,19 @@
from pathlib import Path
from os import chmod
def sanitize_filename(filename: str) -> str: def sanitize_filename(filename: str) -> str:
characters_not_allowed = ["<", ">", ":", '"', "/", "\\", "|", "?", "*", " ", "'"] characters_not_allowed = ["<", ">", ":", '"', "/", "\\", "|", "?", "*", " ", "'"]
for char in characters_not_allowed: for char in characters_not_allowed:
filename = filename.replace(char, "") filename = filename.replace(char, "")
return filename 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)