diff --git a/bitia/helper.py b/bitia/helper.py index bf2acfe19177ff4c9997bc0ed97e5ed9a7d404c2..7785111b8a843b4561f3924203247c4af58dad0e 100644 --- a/bitia/helper.py +++ b/bitia/helper.py @@ -5,9 +5,11 @@ __email__ = "dilawar@subcom.tech" import hashlib import sys +import uuid import zipfile import shutil from pathlib import Path +from datetime import datetime import tempfile import typing as T @@ -84,7 +86,9 @@ def create_pipeline_from_single_script(script: Path) -> Path: return prepare_archive(pipeline_dir) -def create_pipeline_from_command(cmd: str) -> Path: +def create_pipeline_from_command( + cmd: str, add_timestamp: bool = True, add_uuid1: bool = True +) -> Path: """Create a pipeline from user input. Returns @@ -94,7 +98,12 @@ def create_pipeline_from_command(cmd: str) -> Path: pipeline_dir = Path(tempfile.mkdtemp(prefix="bitia_")) pipeline_file = pipeline_dir / bconfig.BITIA_MAIN_SCRIPT_NAME with pipeline_file.open("w", newline="\n") as outf: - outf.write(f"#!/bin/sh\n\n{cmd}") + outf.writeline("#!/bin/sh") + if add_timestamp: + outf.writeline(f"# timestamp={datetime.now().isoformat()}") + if add_uuid1: + outf.writeline(f"# uuid={uuid.uuid1()}") + outf.writeline(f"{cmd}") logger.info("Wrote pipeline %s", pipeline_file.read_text()) return prepare_archive(pipeline_dir) diff --git a/tests/test_cli.py b/tests/test_cli.py index fe4885eaf3cb8bdb2565ff273f43c89281d156cd..30b3a9ac48a26b4f4cba2002dbe5d3efa42bc407 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2,8 +2,11 @@ from bitia.__main__ import run_pipeline def test_cli_sanity(): + nlines = 0 for line in run_pipeline("ls -ltr /"): - print(line) + nlines += 1 + print(11, line) + assert nlines > 10, "Too few lines" if __name__ == "__main__":