-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrun.ps1
More file actions
40 lines (37 loc) · 1.18 KB
/
Copy pathrun.ps1
File metadata and controls
40 lines (37 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env pwsh
param(
[string]$Python = "python",
[string]$Image,
[string[]]$Expect
)
$ErrorActionPreference = "Stop"
$expectWasExplicit = $PSBoundParameters.ContainsKey("Expect")
if (-not (Test-Path -LiteralPath (Join-Path $PSScriptRoot "generated\__init__.py"))) {
throw "Generated bindings were not found. Run generate.ps1 first."
}
if (-not $Image) {
$Image = Join-Path $PSScriptRoot "sample.png"
& (Join-Path $PSScriptRoot "make-test-image.ps1") -Output $Image
if (-not $expectWasExplicit) {
$Expect = @("DYNWINRT", "OCR", "42")
}
}
$Image = [System.IO.Path]::GetFullPath($Image)
if (-not (Test-Path -LiteralPath $Image -PathType Leaf)) {
throw "Image was not found: $Image"
}
if (-not [System.IO.Path]::IsPathRooted($Python)) {
$callerPython = Join-Path (Get-Location).Path $Python
if (Test-Path -LiteralPath $callerPython -PathType Leaf) {
$Python = [System.IO.Path]::GetFullPath($callerPython)
}
}
$arguments = @((Join-Path $PSScriptRoot "app.py"), "--image", $Image)
if ($Expect.Count -gt 0) {
$arguments += "--expect"
$arguments += $Expect
}
& $Python @arguments
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}