Skip to content
Snippets Groups Projects
Commit 2fbc934c authored by dilawar's avatar dilawar :ant:
Browse files

feat: add uuid1 when command line is used.

parent a6bce64d
No related branches found
No related tags found
1 merge request!2version 0.2.0
Pipeline #3755 failed with stages
in 1 minute and 55 seconds
......@@ -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)
......
......@@ -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__":
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment