from __future__ import annotations
import os
import sys
from pathlib import Path
import pyenprot
EXTS = {".ept", ".txt", ".toml", ".yaml", ".yml", ".md", ".rs", ".py", ".go", ".ts"}
def main(argv: list[str]) -> int:
if len(argv) != 3:
print(f"usage: {argv[0]} <dir> <password>", file=sys.stderr)
return 2
directory = Path(argv[1])
password = argv[2]
if not directory.is_dir():
print(f"not a directory: {directory}", file=sys.stderr)
return 2
print(f"enprot {pyenprot.version()}")
casdir = directory / ".cas"
n = 0
for path in sorted(directory.rglob("*")):
if path.suffix.lower() not in EXTS or not path.is_file():
continue
try:
pyenprot.encrypt(path, words={"SECRET": password}, casdir=casdir)
print(f" encrypted: {path}")
n += 1
except pyenprot.EnprotError as e:
print(f" skip {path}: [{e.category}] {e}", file=sys.stderr)
print(f"\n{n} file(s) processed")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))