Files
SMANAGE/_tmp_fix_p2.ps1
T

26 lines
1.1 KiB
PowerShell

$path = "d:\SMANAGE\gvsdsdk\models.py"
$utf8NoBom = New-Object System.Text.UTF8Encoding $false
$content = [System.IO.File]::ReadAllText($path, $utf8NoBom)
$CRLF = "`r`n"
$sq = [char]39
$dq = [char]34
$tripleDq = "$dq$dq$dq"
# 构造死函数块(含 MARKER 行和尾部 2 个空行)
$deadFunc = "def _EltEndTimeDefault():$CRLF $tripleDq" + "已废弃:ELT 令牌过期时间默认值,仅为迁移历史兼容保留" + "$tripleDq$CRLF from django.conf import settings$CRLF days = getattr(settings, ${sq}ELT_TOKEN_LIFETIME_DAYS${sq}, 30) # MARKER$CRLF return _UtcNow() + _timedelta(days=days)$CRLF$CRLF$CRLF"
$before = $content.Length
$found1 = $content.Contains($deadFunc)
$content = $content.Replace($deadFunc, "")
# 删除死导入
$deadImport = "from datetime import timedelta as _timedelta$CRLF"
$found2 = $content.Contains($deadImport)
$content = $content.Replace($deadImport, "")
[System.IO.File]::WriteAllText($path, $content, $utf8NoBom)
$removed = $before - $content.Length
Write-Output "deadFunc found: $found1"
Write-Output "deadImport found: $found2"
Write-Output "chars removed: $removed"