mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-03 05:59:10 +00:00
uninstalled: Add support PowerShell on Windows
... depending on detected shell program. For instance, if the nearest ancestor process is PowerShell, run uninstalled environment via PowerShell. Otherwise, $COMSPEC (most likely cmd.exe) will be used.
This commit is contained in:
parent
b0eea913a4
commit
f42544cb6b
2 changed files with 33 additions and 2 deletions
19
cmd_or_ps.ps1
Normal file
19
cmd_or_ps.ps1
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
$i=1
|
||||||
|
$ppid=(gwmi win32_process -Filter "processid='$pid'").parentprocessid
|
||||||
|
$pname=(Get-Process -id $ppid).Name
|
||||||
|
While($true) {
|
||||||
|
if($pname -eq "cmd" -Or $pname -eq "powershell") {
|
||||||
|
Write-Host ("{0}.exe" -f $pname)
|
||||||
|
Break
|
||||||
|
}
|
||||||
|
|
||||||
|
# 10 times iteration seems to be sufficient
|
||||||
|
if($i -gt 10) {
|
||||||
|
Break
|
||||||
|
}
|
||||||
|
|
||||||
|
# not found yet, find grand parant
|
||||||
|
$ppid=(gwmi win32_process -Filter "processid='$ppid'").parentprocessid
|
||||||
|
$pname=(Get-Process -id $ppid).Name
|
||||||
|
$i++
|
||||||
|
}
|
|
@ -193,6 +193,11 @@ def get_subprocess_env(options, gst_version):
|
||||||
|
|
||||||
return env
|
return env
|
||||||
|
|
||||||
|
def get_windows_shell():
|
||||||
|
command = ['powershell.exe' ,'-noprofile', '-executionpolicy', 'bypass', '-file', 'cmd_or_ps.ps1']
|
||||||
|
result = subprocess.check_output(command)
|
||||||
|
return result.decode().strip()
|
||||||
|
|
||||||
# https://stackoverflow.com/questions/1871549/determine-if-python-is-running-inside-virtualenv
|
# https://stackoverflow.com/questions/1871549/determine-if-python-is-running-inside-virtualenv
|
||||||
def in_venv():
|
def in_venv():
|
||||||
return (hasattr(sys, 'real_prefix') or
|
return (hasattr(sys, 'real_prefix') or
|
||||||
|
@ -226,8 +231,15 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
if not args:
|
if not args:
|
||||||
if os.name is 'nt':
|
if os.name is 'nt':
|
||||||
args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
|
shell = get_windows_shell()
|
||||||
args += ['/k', 'prompt [gst-{}] $P$G'.format(gst_version)]
|
if shell == 'powershell.exe':
|
||||||
|
args = ['powershell.exe']
|
||||||
|
args += ['-NoLogo', '-NoExit']
|
||||||
|
prompt = 'function global:prompt { "[gst-' + gst_version + '"+"] PS " + $PWD + "> "}'
|
||||||
|
args += ['-Command', prompt]
|
||||||
|
else:
|
||||||
|
args = [os.environ.get("COMSPEC", r"C:\WINDOWS\system32\cmd.exe")]
|
||||||
|
args += ['/k', 'prompt [gst-{}] $P$G'.format(gst_version)]
|
||||||
else:
|
else:
|
||||||
args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
|
args = [os.environ.get("SHELL", os.path.realpath("/bin/sh"))]
|
||||||
if "bash" in args[0] and not strtobool(os.environ.get("GST_BUILD_DISABLE_PS1_OVERRIDE", r"FALSE")):
|
if "bash" in args[0] and not strtobool(os.environ.get("GST_BUILD_DISABLE_PS1_OVERRIDE", r"FALSE")):
|
||||||
|
|
Loading…
Reference in a new issue