container.py 850 B

1234567891011121314151617181920212223
  1. from pathlib import Path
  2. from typing import Union
  3. class SimgCmd:
  4. def __init__(self, config: dict, simg: Union[str, None]) -> None:
  5. if simg is None:
  6. self.command = None
  7. else:
  8. self.command = (f"singularity run -B {config['work_dir']}:{config['work_dir']},"
  9. f"{config['output_dir']}:{config['output_dir']},"
  10. f"{config['subject_dir']}:{config['subject_dir']}")
  11. self._simg = simg
  12. def cmd(self, command: str, options: Union[str, None] = None) -> str:
  13. if self.command is None:
  14. run_cmd = command
  15. else:
  16. if options is None:
  17. run_cmd = f"{self.command} {self._simg} {command}"
  18. else:
  19. run_cmd = f"{self.command} {options} {self._simg} {command}"
  20. return run_cmd