Changeset View
Changeset View
Standalone View
Standalone View
autotests/folding/craftenv.ps1.fold
- This file was added.
1 | <beginfold id='2'><#</beginfold id='2'> | ||||
---|---|---|---|---|---|
2 | Copied from Craft for testing syntax highlighting | ||||
3 | <endfold id='2'>#></endfold id='2'> | ||||
4 | | ||||
5 | <beginfold id='1'>@"</beginfold id='1'> multi | ||||
6 | line | ||||
7 | string | ||||
8 | <endfold id='1'>"@</endfold id='1'> | ||||
9 | | ||||
10 | # this file sets some environment variables that are needed | ||||
11 | # for finding programs and libraries etc. | ||||
12 | # by Hannah von Reth <vonreth@kde.org> | ||||
13 | # you should copy kdesettings.ini to ..\etc\kdesettings.ini | ||||
14 | # and adapt it to your needs (see that file for more info) | ||||
15 | | ||||
16 | # this file should contain all path settings - and provide thus an environment | ||||
17 | # to build and run kde programs | ||||
18 | # based on kdeenv.bat | ||||
19 | | ||||
20 | cls | ||||
21 | | ||||
22 | | ||||
23 | $env:CraftRoot=[System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition) | ||||
24 | | ||||
25 | $CRAFT_ARGUMENTS = $args | ||||
26 | | ||||
27 | &<beginfold id='3'>{</beginfold id='3'> | ||||
28 | [version]$minPythonVersion = 3.6 | ||||
29 | | ||||
30 | function findPython([string] $name) | ||||
31 | <beginfold id='3'>{</beginfold id='3'> | ||||
32 | $py = (Get-Command $name -ErrorAction SilentlyContinue) | ||||
33 | if ($py -and ($py | Get-Member Version) -and $py.Version -ge $minPythonVersion) <beginfold id='3'>{</beginfold id='3'> | ||||
34 | $env:CRAFT_PYTHON=$py.Source | ||||
35 | <endfold id='3'>}</endfold id='3'> | ||||
36 | <endfold id='3'>}</endfold id='3'> | ||||
37 | | ||||
38 | findPython("python3") | ||||
39 | findPython("python") | ||||
40 | | ||||
41 | function readINI([string] $fileName) | ||||
42 | <beginfold id='3'>{</beginfold id='3'> | ||||
43 | $ini = @<beginfold id='3'>{</beginfold id='3'><endfold id='3'>}</endfold id='3'> | ||||
44 | | ||||
45 | switch -regex -file $fileName <beginfold id='3'>{</beginfold id='3'> | ||||
46 | "^\[(.+)\]$" <beginfold id='3'>{</beginfold id='3'> | ||||
47 | $section = $matches[1].Trim() | ||||
48 | $ini[$section] = @<beginfold id='3'>{</beginfold id='3'><endfold id='3'>}</endfold id='3'> | ||||
49 | <endfold id='3'>}</endfold id='3'> | ||||
50 | "^\s*([^#].+?)\s*=\s*(.*)" <beginfold id='3'>{</beginfold id='3'> | ||||
51 | $name,$value = $matches[1..2] | ||||
52 | $ini[$section][$name] = $value.Trim() | ||||
53 | <endfold id='3'>}</endfold id='3'> | ||||
54 | <endfold id='3'>}</endfold id='3'> | ||||
55 | $ini | ||||
56 | <endfold id='3'>}</endfold id='3'> | ||||
57 | | ||||
58 | | ||||
59 | | ||||
60 | if(test-path -path $env:CraftRoot\..\etc\kdesettings.ini) | ||||
61 | <beginfold id='3'>{</beginfold id='3'> | ||||
62 | $settings = readINI $env:CraftRoot\..\etc\kdesettings.ini | ||||
63 | <endfold id='3'>}</endfold id='3'> | ||||
64 | else | ||||
65 | <beginfold id='3'>{</beginfold id='3'> | ||||
66 | Write-Error("$env:CraftRoot\..\etc\kdesettings.ini Does not exist") | ||||
67 | break | ||||
68 | <endfold id='3'>}</endfold id='3'> | ||||
69 | if( $CRAFT_ARGUMENTS[0] -eq "--get") | ||||
70 | <beginfold id='3'>{</beginfold id='3'> | ||||
71 | Write-Host($settings[$CRAFT_ARGUMENTS[1]][$CRAFT_ARGUMENTS[2]]) | ||||
72 | break | ||||
73 | <endfold id='3'>}</endfold id='3'> | ||||
74 | | ||||
75 | | ||||
76 | function prependPATH([string] $path) | ||||
77 | <beginfold id='3'>{</beginfold id='3'> | ||||
78 | $env:PATH="$path{0}$env:PATH" -f [IO.Path]::PathSeparator | ||||
79 | <endfold id='3'>}</endfold id='3'> | ||||
80 | | ||||
81 | | ||||
82 | if( -Not $env:CRAFT_PYTHON) | ||||
83 | <beginfold id='3'>{</beginfold id='3'> | ||||
84 | prependPATH $settings["Paths"]["Python"] | ||||
85 | $env:CRAFT_PYTHON=[IO.PATH]::COMBINE($settings["Paths"]["Python"], "python") | ||||
86 | <endfold id='3'>}</endfold id='3'> | ||||
87 | | ||||
88 | (& $env:CRAFT_PYTHON ([IO.PATH]::COMBINE("$env:CraftRoot", "bin", "CraftSetupHelper.py")) "--setup") | | ||||
89 | foreach <beginfold id='3'>{</beginfold id='3'> | ||||
90 | if ($_ -match "=") <beginfold id='3'>{</beginfold id='3'> | ||||
91 | $v = $_.split("=") | ||||
92 | set-item -force -path "ENV:\$($v[0])" -value "$($v[1])" | ||||
93 | #Write-Host("$v[0]=$v[1]") | ||||
94 | <endfold id='3'>}</endfold id='3'> | ||||
95 | <endfold id='3'>}</endfold id='3'> | ||||
96 | | ||||
97 | cd "$env:KDEROOT" | ||||
98 | <endfold id='3'>}</endfold id='3'> | ||||
99 | | ||||
100 | | ||||
101 | function Global:craft() <beginfold id='3'>{</beginfold id='3'> | ||||
102 | return & $env:CRAFT_PYTHON ([IO.PATH]::COMBINE("$env:CraftRoot", "bin", "craft.py")) $args | ||||
103 | <endfold id='3'>}</endfold id='3'> | ||||
104 | | ||||
105 | | ||||
106 | if($args.Length -ne 0) | ||||
107 | <beginfold id='3'>{</beginfold id='3'> | ||||
108 | invoke-expression -command "$args" | ||||
109 | <endfold id='3'>}</endfold id='3'> |