1
0

cli_scripts.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 os
  10. import sys
  11. import logging
  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 'COVERAGE_PROCESS_START' in os.environ or 'COVERAGE_FILE' in os.environ:
  26. inject_coverage = inject_sitecustomize = True
  27. else:
  28. inject_coverage = inject_sitecustomize = False
  29. if not os.path.isfile(script_path):
  30. cli_scripts.generate_script(
  31. bin_dir=bin_dir,
  32. script_name=script_name,
  33. executable=sys.executable,
  34. code_dir=RUNTIME_VARS.CODE_DIR,
  35. inject_coverage=inject_coverage,
  36. inject_sitecustomize=inject_sitecustomize
  37. )
  38. log.info('Returning script path %r', script_path)
  39. return script_path
  40. class ScriptPathMixin(object):
  41. def get_script_path(self, script_name):
  42. '''
  43. Return the path to a testing runtime script
  44. '''
  45. # Late import
  46. from tests.support.runtests import RUNTIME_VARS
  47. return get_script_path(RUNTIME_VARS.TMP_SCRIPT_DIR, script_name)