Permalink
Browse files

Don't spam the console with part repair logging, just show a tidy sta…

…tus indicator instead.
  • Loading branch information...
1 parent 05ff6bd commit 5db5d9423c44fc8b68e163c283033f39ee8592f6 Nic Wolfe committed May 23, 2011
Showing with 39 additions and 2 deletions.
  1. +10 −2 www/lib/binaries.php
  2. +29 −0 www/lib/consoletools.php
View
12 www/lib/binaries.php 100644 → 100755
@@ -3,6 +3,7 @@
require_once(WWW_DIR."/lib/nntp.php");
require_once(WWW_DIR."/lib/groups.php");
require_once(WWW_DIR."/lib/backfill.php");
+require_once(WWW_DIR."/lib/consoletools.php");
class Binaries
{
@@ -278,7 +279,8 @@ function scan($nntp, $groupArr, $first, $last, $type='update')
$this->addMissingParts($rangenotreceived, $groupArr['ID']);
break;
}
- echo 'Server did not return article numbers '.implode(',', $rangenotreceived)."$n";
+ if ($type != 'partrepair')
+ echo 'Server did not return article numbers '.implode(',', $rangenotreceived)."$n";
}
if(isset($this->message) && count($this->message))
@@ -374,12 +376,16 @@ private function partRepair($nntp, $groupArr)
$lastnum = $part['numberID'];
}
+ $num_attempted = 0;
+ $consoleTools = new ConsoleTools();
+
//download missing parts in ranges
foreach($ranges as $partfrom=>$partto)
{
$this->startLoop = microtime(true);
- echo '-repairing '.$partfrom.' to '.$partto.$n;
+ $num_attempted += $partto - $partfrom + 1;
+ $consoleTools->overWrite("Attempting repair: ".$consoleTools->percentString($num_attempted,sizeof($missingParts)).": ".$partfrom." to ".$partto);
//get article from newsgroup
$this->scan($nntp, $groupArr, $partfrom, $partto, 'partrepair');
@@ -408,6 +414,8 @@ private function partRepair($nntp, $groupArr)
}
}
+ echo $n;
+
echo $partsRepaired.' parts repaired.'.$n;
}
@@ -0,0 +1,29 @@
+<?
+
+class ConsoleTools
+{
+
+ function ConsoleTools(){
+ $this->lastMessageLength = 0;
+ }
+
+ function overWrite($message, $reset=False)
+ {
+ if ($reset)
+ $this->lastMessageLength = 0;
+
+ echo str_repeat(chr(8), $this->lastMessageLength);
+
+ $this->lastMessageLength = strlen($message);
+ echo $message;
+
+ }
+
+ function percentString($cur, $total)
+ {
+ $percent = 100 * $cur / $total;
+ $formatString = "% ".strlen($total)."d/%d (% 2d%%)";
+ return sprintf($formatString, $cur, $total, $percent);
+ }
+}
+?>

0 comments on commit 5db5d94

Please sign in to comment.