1
0

cli_scripts.py 1.5 KB

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