cli_scripts.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """
  2. tests.support.cli_scripts
  3. ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. Code to generate Salt CLI scripts for test runs
  5. """
  6. import logging
  7. import os
  8. from saltfactories.utils import cli_scripts
  9. log = logging.getLogger(__name__)
  10. def get_script_path(bin_dir, script_name):
  11. """
  12. Return the path to a testing runtime script, generating one if it does not yet exist
  13. """
  14. # Late import
  15. from tests.support.runtests import RUNTIME_VARS
  16. if not os.path.isdir(bin_dir):
  17. os.makedirs(bin_dir)
  18. cli_script_name = "cli_{}.py".format(script_name.replace("-", "_"))
  19. script_path = os.path.join(bin_dir, cli_script_name)
  20. if not os.path.isfile(script_path):
  21. cli_scripts.generate_script(
  22. bin_dir=bin_dir,
  23. script_name=script_name,
  24. code_dir=RUNTIME_VARS.CODE_DIR,
  25. inject_coverage="COVERAGE_PROCESS_START" in os.environ,
  26. inject_sitecustomize="COVERAGE_PROCESS_START" in os.environ,
  27. )
  28. log.info("Returning script path %r", script_path)
  29. return script_path
  30. class ScriptPathMixin:
  31. def get_script_path(self, script_name):
  32. """
  33. Return the path to a testing runtime script
  34. """
  35. # Late import
  36. from tests.support.runtests import RUNTIME_VARS
  37. return get_script_path(RUNTIME_VARS.TMP_SCRIPT_DIR, script_name)