1
0

cli_scripts.py 1.4 KB

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