mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Fix test_script for Windows
This commit is contained in:
parent
08853b63a3
commit
445749cbda
1 changed files with 29 additions and 19 deletions
|
@ -11,6 +11,7 @@ import functools
|
|||
import glob
|
||||
import logging
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
|
@ -2937,28 +2938,37 @@ def script(
|
|||
os.chmod(path, 320)
|
||||
os.chown(path, __salt__["file.user_to_uid"](runas), -1)
|
||||
|
||||
if salt.utils.platform.is_windows() and shell.lower() != "powershell":
|
||||
cmd_path = _cmd_quote(path, escape=False)
|
||||
if salt.utils.platform.is_windows():
|
||||
if shell.lower() != "powershell":
|
||||
cmd_path = _cmd_quote(path, escape=False)
|
||||
else:
|
||||
cmd_path = path
|
||||
if not env:
|
||||
env = {}
|
||||
mod_paths = [
|
||||
pathlib.Path(
|
||||
rf'{os.getenv("SystemRoot")}\System32\WindowsPowerShell\v1.0\Modules'
|
||||
),
|
||||
pathlib.Path(rf'{os.getenv("ProgramFiles")}\WindowsPowerShell\Modules'),
|
||||
pathlib.Path(
|
||||
rf'{os.getenv("ProgramFiles(x86)", "")}\WindowsPowerShell\Modules'
|
||||
),
|
||||
]
|
||||
ps_module_path = [
|
||||
pathlib.Path(x) for x in os.getenv("PSModulePath", "").split(";")
|
||||
]
|
||||
for mod_path in mod_paths:
|
||||
if mod_path.exists():
|
||||
if mod_path not in ps_module_path:
|
||||
ps_module_path.append(mod_path)
|
||||
mod_paths = ""
|
||||
for mod_path in ps_module_path:
|
||||
if mod_path:
|
||||
mod_paths += f"{str(path)};"
|
||||
env.update({"PSModulePath": mod_paths})
|
||||
else:
|
||||
cmd_path = _cmd_quote(path)
|
||||
|
||||
if not env:
|
||||
env = {}
|
||||
|
||||
paths = [
|
||||
rf'{os.getenv("SystemRoot")}\System32\WindowsPowerShell\v1.0\Modules',
|
||||
rf'{os.getenv("ProgramFiles")}\WindowsPowerShell\Modules',
|
||||
rf'{os.getenv("ProgramFiles(x86)", "")}\WindowsPowerShell\Modules',
|
||||
]
|
||||
|
||||
ps_module_path = os.getenv("PSModulePath", "").split(";")
|
||||
|
||||
for path in paths:
|
||||
if os.path.exists(path):
|
||||
ps_module_path.append(path)
|
||||
|
||||
env.update({"PSModulePath": ";".join(ps_module_path)})
|
||||
|
||||
ret = _run(
|
||||
cmd_path + " " + str(args) if args else cmd_path,
|
||||
cwd=cwd,
|
||||
|
|
Loading…
Add table
Reference in a new issue