activate.ps1 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # This Source Code Form is subject to the terms of the Mozilla Public
  2. # License, v. 2.0. If a copy of the MPL was not distributed with this
  3. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. $Env:VIRTUAL_ENV = (gl);
  5. $Env:CUDDLEFISH_ROOT = $Env:VIRTUAL_ENV;
  6. # http://stackoverflow.com/questions/5648931/powershell-test-if-registry-value-exists/5652674#5652674
  7. Function Test-RegistryValue {
  8. param(
  9. [Alias("PSPath")]
  10. [Parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
  11. [String]$Path
  12. ,
  13. [Parameter(Position = 1, Mandatory = $true)]
  14. [String]$Name
  15. ,
  16. [Switch]$PassThru
  17. )
  18. process {
  19. if (Test-Path $Path) {
  20. $Key = Get-Item -LiteralPath $Path
  21. if ($Key.GetValue($Name, $null) -ne $null) {
  22. if ($PassThru) {
  23. Get-ItemProperty $Path $Name
  24. } else {
  25. $true
  26. }
  27. } else {
  28. $false
  29. }
  30. } else {
  31. $false
  32. }
  33. }
  34. }
  35. $WINCURVERKEY = 'HKLM:SOFTWARE\Microsoft\Windows\CurrentVersion';
  36. $WIN64 = (Test-RegistryValue $WINCURVERKEY 'ProgramFilesDir (x86)');
  37. if($WIN64) {
  38. $PYTHONKEY='HKLM:SOFTWARE\Wow6432Node\Python\PythonCore';
  39. }
  40. else {
  41. $PYTHONKEY='HKLM:SOFTWARE\Python\PythonCore';
  42. }
  43. $Env:PYTHONVERSION = '';
  44. $Env:PYTHONINSTALL = '';
  45. foreach ($version in @('2.6', '2.5', '2.4')) {
  46. if (Test-RegistryValue "$PYTHONKEY\$version\InstallPath" '(default)') {
  47. $Env:PYTHONVERSION = $version;
  48. }
  49. }
  50. if ($Env:PYTHONVERSION) {
  51. $Env:PYTHONINSTALL = (Get-Item "$PYTHONKEY\$version\InstallPath)").'(default)';
  52. }
  53. if ($Env:PYTHONINSTALL) {
  54. $Env:Path += ";$Env:PYTHONINSTALL";
  55. }
  56. if (Test-Path Env:_OLD_PYTHONPATH) {
  57. $Env:PYTHONPATH = $Env:_OLD_PYTHONPATH;
  58. }
  59. else {
  60. $Env:PYTHONPATH = '';
  61. }
  62. $Env:_OLD_PYTHONPATH=$Env:PYTHONPATH;
  63. $Env:PYTHONPATH= "$Env:VIRTUAL_ENV\python-lib;$Env:PYTHONPATH";
  64. if (Test-Path Function:_OLD_VIRTUAL_PROMPT) {
  65. Set-Content Function:Prompt (Get-Content Function:_OLD_VIRTUAL_PROMPT);
  66. }
  67. else {
  68. function global:_OLD_VIRTUAL_PROMPT {}
  69. }
  70. Set-Content Function:_OLD_VIRTUAL_PROMPT (Get-Content Function:Prompt);
  71. function global:prompt { "($Env:VIRTUAL_ENV) $(_OLD_VIRTUAL_PROMPT)"; };
  72. if (Test-Path Env:_OLD_VIRTUAL_PATH) {
  73. $Env:PATH = $Env:_OLD_VIRTUAL_PATH;
  74. }
  75. else {
  76. $Env:_OLD_VIRTUAL_PATH = $Env:PATH;
  77. }
  78. $Env:Path="$Env:VIRTUAL_ENV\bin;$Env:Path"
  79. [System.Console]::WriteLine("Note: this PowerShell SDK activation script is experimental.")
  80. python -c "from jetpack_sdk_env import welcome; welcome()"