File: watcher.ps1

package info (click to toggle)
python-isoduration 20.11.0%2Bgit20211126.ae0bd61-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 252 kB
  • sloc: python: 1,748; makefile: 3
file content (42 lines) | stat: -rw-r--r-- 1,006 bytes parent folder | download
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