This commit is contained in:
2018-09-13 01:50:00 -07:00
parent ca7a7a8a58
commit a7716a08cc
11 changed files with 5608 additions and 43 deletions

View File

@@ -5,11 +5,31 @@
class ProgressBar {
protected static $done = 0;
protected static $total = 0;
protected static $time_start;
protected static $time_remain;
protected static $time_update;
protected static $total;
protected static $done;
protected static $message;
public static function display($message = null) {
$string = "PROGRESS:".floor((self::$done/self::$total)*100);
$progress = self::$done/self::$total;
$string = "PROGRESS:".round($progress*100,2);
if ($message === true) {
$message = self::$message;
}
if ($message) {
if (time()-self::$time_update) { // only update the remaining time every 1 seconds
$seconds = time() - self::$time_start;
self::$time_remain = floor($seconds/$progress)-$seconds;
self::$time_update = time();
}
$message = gmdate("H:i:s",self::$time_remain)." | ".$message;
}
if ($message) {
return "\n".$string."\n".$message;
} elseif (!strpos(__FILE__,".app")) {
@@ -17,10 +37,14 @@ class ProgressBar {
} else {
return "\n".$string;
}
}
public static function start($total, $message = null) {
self::$done = 0;
self::$total = $total;
self::$time_start = time();
self::$message = $message;
return $message."\n".self::display();
}
@@ -30,6 +54,8 @@ class ProgressBar {
}
public static function finish() {
global $wopt_currstep;
$wopt_currstep++;
self::$done = 0;
return "\n";
}
@@ -50,11 +76,14 @@ function getParents($zpath, $pathname) {
}
*/
function stringPrint($string) {
echo $string.@str_repeat(" ", (10-strlen($string)));
function stepString() {
global $wopt_steps;
global $wopt_currstep;
return "Step ".$wopt_currstep." of ".$wopt_steps;
}
function shortlabel($pathname, $max = 99, $pad = false) {
function shortlabel($pathname, $max = 99) {
$basename = basename($pathname);
$suffix = "(...).".pathinfo($basename,PATHINFO_EXTENSION);
if (strlen($basename) > $max) {
@@ -62,9 +91,6 @@ function shortlabel($pathname, $max = 99, $pad = false) {
} else {
$return = $basename;
}
if ($pad) {
$return = $return.@str_repeat(" ", ($max-strlen($return)));
}
return $return;
}