Enforce session workspace boundaries

This commit is contained in:
武阳
2026-05-08 17:09:07 +08:00
parent 5b14f55736
commit 0bbba2b936
13 changed files with 509 additions and 52 deletions
+11 -2
View File
@@ -76,8 +76,13 @@ def read_sql(args: argparse.Namespace) -> str:
def default_output_path(query_id: str) -> Path:
"""Default: ~/Downloads/data_factory_<timestamp>.csv"""
"""Default to current session output when python_exec exposes it."""
ts = time.strftime("%Y%m%d_%H%M%S")
scratchpad = os.environ.get("PYTHON_EXEC_SCRATCHPAD")
if scratchpad:
output_dir = Path(scratchpad).resolve().parent / "output"
output_dir.mkdir(parents=True, exist_ok=True)
return output_dir / f"data_factory_{ts}.csv"
downloads = Path.home() / "Downloads"
downloads.mkdir(parents=True, exist_ok=True)
return downloads / f"data_factory_{ts}.csv"
@@ -136,7 +141,11 @@ def build_parser() -> argparse.ArgumentParser:
p.add_argument("--catalog", help="default catalog")
p.add_argument("--schema", help="default schema")
p.add_argument(
"--output", help="output CSV path (default: ~/Downloads/data_factory_<ts>.csv)"
"--output",
help=(
"output CSV path (default: session output when PYTHON_EXEC_SCRATCHPAD "
"is set, otherwise ~/Downloads/data_factory_<ts>.csv)"
),
)
p.add_argument(
"--no-save", action="store_true", help="don't save CSV, only print to stdout"