Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Modules/Controller.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ function Invoke-MainLoop {
& $CompleteLogRunHandler
} else {
$elapsedString = Format-ElapsedTime -Elapsed $runStopwatch.Elapsed
$summaryLines = Get-SummaryLines -Stats $stats -ElapsedString $elapsedString -ModeFlags $resolved
$summaryLines = Get-SummaryLines -Stats $stats -ElapsedString $elapsedString -ModeFlags $resolved -FullLogging $script:FullLogging
Write-SummaryReport -Lines $summaryLines -FullLogging $script:FullLogging
& $CompleteLogRunHandler
}
Expand Down
141 changes: 109 additions & 32 deletions Modules/Summary.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,132 @@ function Format-ElapsedTime {
return ("{0:D2}h {1:D2}m {2:D2}s" -f [int][Math]::Floor($Elapsed.TotalHours), $Elapsed.Minutes, $Elapsed.Seconds)
}

function Format-SummaryCount {
param(
[int]$Count,
[Parameter(Mandatory)]
[string]$Singular
)

$noun = $Singular
if ($Count -ne 1) { $noun += "s" }
return ($Count.ToString() + " " + $noun)
}

function Format-SummaryRow {
param(
[Parameter(Mandatory)]
[string]$Label,
[Parameter(Mandatory)]
[string[]]$Parts
)

return ($Label.PadRight(10) + ": " + ($Parts -join ", "))
}

function Get-SummaryLines {
param(
[Parameter(Mandatory)]
[hashtable]$Stats,
[Parameter(Mandatory)]
[string]$ElapsedString,
[Parameter(Mandatory)]
[hashtable]$ModeFlags
[hashtable]$ModeFlags,
[bool]$FullLogging = $false
)

$lines = New-Object System.Collections.Generic.List[string]
$lines.Add("=== SUMMARY ===")
$modeNames = @{
FullPipeline = "Full Pipeline"
ImageConversion = "Image Conversion"
AnimatedConversion = "Animated Conversion"
ZipFolders = "Zip Folders"
}

$rows = New-Object System.Collections.Generic.List[string]
$attention = New-Object System.Collections.Generic.List[string]

if ($ModeFlags.RunImageConversion) {
$lines.Add("Loose Img Conv. : Success = " + $Stats.LooseImgConverted.Success + " | Failed = " + $Stats.LooseImgConverted.Fail + " | Skipped (animated) = " + $Stats.LooseImgConverted.Skipped)
$lines.Add("Loose Img Deleted : Success = " + $Stats.LooseImgDeleted.Success + " | Failed = " + $Stats.LooseImgDeleted.Fail)
$lines.Add("Loose Stale Cleaned : Success = " + $Stats.LooseStaleCleaned.Success + " | Failed = " + $Stats.LooseStaleCleaned.Fail)
$lines.Add("Covers Normalised : Success = " + $Stats.CoversNormalized.Success + " | Failed = " + $Stats.CoversNormalized.Fail)
$conv = $Stats.LooseImgConverted; $del = $Stats.LooseImgDeleted; $stale = $Stats.LooseStaleCleaned
$parts = New-Object System.Collections.Generic.List[string]
if ($conv.Success -gt 0) { $parts.Add([string]$conv.Success + " converted") }
if ($conv.Fail -gt 0) { $parts.Add([string]$conv.Fail + " FAILED") }
if ($conv.Skipped -gt 0) { $parts.Add([string]$conv.Skipped + " skipped") }
if ($del.Success -gt 0) { $parts.Add((Format-SummaryCount -Count $del.Success -Singular "original") + " deleted") }
if ($del.Fail -gt 0) { $parts.Add((Format-SummaryCount -Count $del.Fail -Singular "original") + " NOT deleted") }
if ($stale.Success -gt 0) { $parts.Add((Format-SummaryCount -Count $stale.Success -Singular "already-converted original") + " cleaned up") }
if ($stale.Fail -gt 0) { $parts.Add((Format-SummaryCount -Count $stale.Fail -Singular "already-converted original") + " NOT cleaned up") }
if ($parts.Count -gt 0) { $rows.Add((Format-SummaryRow -Label "Images" -Parts $parts.ToArray())) }
if ($conv.Fail -gt 0) { $attention.Add((Format-SummaryCount -Count $conv.Fail -Singular "image") + " failed") }
$notDeleted = [int]$del.Fail + [int]$stale.Fail
if ($notDeleted -gt 0) { $attention.Add((Format-SummaryCount -Count $notDeleted -Singular "original image") + " not deleted") }
}

if ($ModeFlags.RunAnimatedConversion) {
$lines.Add("Loose Anim. Conv. : Success = " + $Stats.LooseAnimatedConverted.Success + " | Failed = " + $Stats.LooseAnimatedConverted.Fail + " | Skipped (already converted) = " + $Stats.LooseAnimatedConverted.Skipped)
$lines.Add("Loose Anim. Deleted : Success = " + $Stats.LooseAnimatedDeleted.Success + " | Failed = " + $Stats.LooseAnimatedDeleted.Fail)
$conv = $Stats.LooseAnimatedConverted; $del = $Stats.LooseAnimatedDeleted
$parts = New-Object System.Collections.Generic.List[string]
if ($conv.Success -gt 0) { $parts.Add([string]$conv.Success + " converted") }
if ($conv.Fail -gt 0) { $parts.Add([string]$conv.Fail + " FAILED") }
if ($conv.Skipped -gt 0) { $parts.Add([string]$conv.Skipped + " skipped (already converted)") }
if ($del.Success -gt 0) { $parts.Add((Format-SummaryCount -Count $del.Success -Singular "original") + " deleted") }
if ($del.Fail -gt 0) { $parts.Add((Format-SummaryCount -Count $del.Fail -Singular "original") + " NOT deleted") }
if ($parts.Count -gt 0) { $rows.Add((Format-SummaryRow -Label "Animated" -Parts $parts.ToArray())) }
if ($conv.Fail -gt 0) { $attention.Add((Format-SummaryCount -Count $conv.Fail -Singular "animated file") + " failed") }
if ($del.Fail -gt 0) { $attention.Add((Format-SummaryCount -Count $del.Fail -Singular "animated original") + " not deleted") }
}

if ($ModeFlags.RunImageConversion -or $ModeFlags.RunAnimatedConversion) {
$lines.Add("Inspect Failed : " + $Stats.InspectFailed.Count + " file(s) - could not determine if animated")
$zip = $null; $folders = $null; $skipLabel = "skipped"
if ($ModeFlags.RunZip) { $zip = $Stats.LooseFolderZipped; $folders = $Stats.LooseFolderDeleted }
elseif ($ModeFlags.RunZipOnly) { $zip = $Stats.ZipOnlyZipped; $folders = $Stats.ZipOnlyFolderDeleted; $skipLabel = "skipped (animated originals kept)" }
if ($null -ne $zip) {
$parts = New-Object System.Collections.Generic.List[string]
if ($zip.Success -gt 0) { $parts.Add([string]$zip.Success + " zipped") }
if ($zip.Fail -gt 0) { $parts.Add([string]$zip.Fail + " FAILED") }
if ($zip.Skipped -gt 0) { $parts.Add([string]$zip.Skipped + " " + $skipLabel) }
if ($folders.Success -gt 0) { $parts.Add((Format-SummaryCount -Count $folders.Success -Singular "folder") + " deleted") }
if ($folders.Fail -gt 0) { $parts.Add((Format-SummaryCount -Count $folders.Fail -Singular "folder") + " NOT deleted") }
if ($parts.Count -gt 0) { $rows.Add((Format-SummaryRow -Label "Chapters" -Parts $parts.ToArray())) }
$notZipped = [int]$zip.Fail + [int]$zip.Skipped
if ($notZipped -gt 0) { $attention.Add((Format-SummaryCount -Count $notZipped -Singular "chapter") + " not zipped") }
if ($folders.Fail -gt 0) { $attention.Add((Format-SummaryCount -Count $folders.Fail -Singular "chapter folder") + " not deleted") }
}

if ($ModeFlags.RunZip) {
$lines.Add("Loose Folders Zipped: Success = " + $Stats.LooseFolderZipped.Success + " | Failed = " + $Stats.LooseFolderZipped.Fail + " | Skipped (unconverted images) = " + $Stats.LooseFolderZipped.Skipped)
$lines.Add("Loose Fldr Deleted : Success = " + $Stats.LooseFolderDeleted.Success + " | Failed = " + $Stats.LooseFolderDeleted.Fail)
if ($ModeFlags.RunImageConversion) {
$covers = $Stats.CoversNormalized
$parts = New-Object System.Collections.Generic.List[string]
if ($covers.Success -gt 0) { $parts.Add([string]$covers.Success + " normalized") }
if ($covers.Fail -gt 0) { $parts.Add([string]$covers.Fail + " FAILED") }
if ($parts.Count -gt 0) { $rows.Add((Format-SummaryRow -Label "Covers" -Parts $parts.ToArray())) }
if ($covers.Fail -gt 0) { $attention.Add((Format-SummaryCount -Count $covers.Fail -Singular "cover") + " failed") }
}

if ($ModeFlags.RunZipOnly) {
$lines.Add("Zip-only Zipped : Success = " + $Stats.ZipOnlyZipped.Success + " | Failed = " + $Stats.ZipOnlyZipped.Fail + " | Skipped (animated originals kept) = " + $Stats.ZipOnlyZipped.Skipped)
$lines.Add("Zip-only Fldr Del. : Success = " + $Stats.ZipOnlyFolderDeleted.Success + " | Failed = " + $Stats.ZipOnlyFolderDeleted.Fail)
# Kept apart from the Fail counts: these files were never tried.
if (($ModeFlags.RunImageConversion -or $ModeFlags.RunAnimatedConversion) -and $Stats.InspectFailed.Count -gt 0) {
$left = (Format-SummaryCount -Count $Stats.InspectFailed.Count -Singular "file")
$rows.Add((Format-SummaryRow -Label "Left alone" -Parts @($left + " (name clash, or couldn't tell if animated)")))
$attention.Add($left + " left alone")
}

$lines.Add("Time taken : " + $ElapsedString)
$modeName = [string]$modeNames[[string]$ModeFlags['Mode']]
$title = "SUMMARY"
if ($modeName) { $title += ": " + $modeName }
if ($Stats.Aborted) { $title += " - ABORTED" }

$lines = New-Object System.Collections.Generic.List[string]
$lines.Add("=== " + $title + " (" + $ElapsedString + ") ===")
foreach ($row in $rows) { $lines.Add($row) }
if ($Stats.Aborted) {
$lines.Add("Run was ABORTED : " + $Stats.ForceKilledCount + " job(s) force-stopped after the drain timeout")
$lines.Add("=== Processing ABORTED ===")
} else {
$lines.Add("=== Processing complete ===")
$abortText = "stopped before finishing"
if ($Stats.ForceKilledCount -gt 0) { $abortText += ", " + (Format-SummaryCount -Count $Stats.ForceKilledCount -Singular "job") + " force-stopped after the drain timeout" }
$lines.Add((Format-SummaryRow -Label "Aborted" -Parts @($abortText)))
} elseif ($rows.Count -eq 0) {
$lines.Add("Nothing was converted or zipped.")
}
if ($attention.Count -gt 0) {
$logText = " - see the Errors/Warnings logs"
if ($FullLogging) { $logText = " - see the log" }
# A chapter skipped only because the run was aborted isn't in the logs.
if ($Stats.Aborted -and $attention.Count -eq 1 -and $null -ne $zip -and $zip.Skipped -gt 0 -and [int]$zip.Fail -eq 0) { $logText = "" }
$lines.Add((Format-SummaryRow -Label "Attention" -Parts $attention.ToArray()) + $logText)
}

return ,$lines.ToArray()
Expand All @@ -84,16 +165,12 @@ function Write-SummaryReport {
)

Write-Host ""
# -ForceConsole: without it, Write-Log
# (Logging.ps1) suppresses console output whenever Clean Console
# Output is enabled, and nothing turns CCR off before this runs
# (Controller.ps1 sets it once per loop iteration, the summary is
# written inside that same iteration) - so with CCO on, the user would see
# a single blank line and no summary at all: no counts, no elapsed
# time, no "=== Processing ABORTED ===" footer. Every other
# end-of-operation Summary-level Write-Log call in this codebase
# (UnwantedImage.ps1's four) passes -ForceConsole too.
foreach ($line in $Lines) { Write-Log $line -Level Summary -ForceConsole }
# Not Write-Log: the console gets the lines without a timestamp and level,
# even with Clean Console Output on. The full log still gets both.
foreach ($line in $Lines) {
Write-LogLineToRunFiles -Line (Format-LogLine -Message $line -Level "Summary") -Level "Summary"
Write-LogLineToHost -Line $line -Level "Summary"
}

if (-not $FullLogging) {
Write-SummaryLog -Lines $Lines
Expand Down
Loading
Loading