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 41 42
|
function Add-Watcher {
param(
[String] $Path = ".",
[String] $FileFilter = "*"
)
$AttributeFilter = [IO.NotifyFilters]::FileName,
[IO.NotifyFilters]::LastWrite
$ChangeTypes = [System.IO.WatcherChangeTypes]::All
$Timeout = 1000
try {
$watcher = New-Object `
-TypeName IO.FileSystemWatcher `
-ArgumentList $Path, $FileFilter `
-Property @{
IncludeSubdirectories = $true
NotifyFilter = $AttributeFilter
}
do {
$result = $watcher.WaitForChanged($ChangeTypes, $Timeout)
if ($result.TimedOut) { continue }
Invoke-Action -Change $result
} while ($true)
} finally {
$watcher.Dispose()
}
}
function Invoke-Action {
param (
[Parameter(Mandatory)]
[System.IO.WaitForChangedResult] $ChangeInformation
)
tox -e linting,py -p auto -o
}
Add-Watcher -FileFilter *.py
|