Update ConsoleTools class and related scripts

This commit is contained in:
DariusIII
2018-01-05 12:57:07 +01:00
parent 2047e1ec62
commit 5173bc501e
14 changed files with 28 additions and 80 deletions
+1
View File
@@ -1,4 +1,5 @@
2018-01-05 DariusIII
* Chg: Update ConsoleTools class and related scripts
* Chg: Update Forking and postprocess.php
* Chg: Update Movie class and add missing rtrating column to movieinfo table in mysql-ddl.sql
* Chg: Update nntmux/AniDB class
+1 -1
View File
@@ -26,7 +26,7 @@ if (isset($argv[1])) {
function create_guids($live, $delete = false)
{
$pdo = new DB();
$consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$consoletools = new ConsoleTools();
$timestart = time();
$relcount = $deleted = $total = 0;
+1 -1
View File
@@ -9,7 +9,7 @@ use nntmux\ConsoleTools;
$category = new Category();
$pdo = new DB();
$consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$consoletools = new ConsoleTools();
$ran = false;
if (isset($argv[1], $argv[2]) && $argv[1] === 'all' && $argv[2] === 'true') {
+1 -1
View File
@@ -33,7 +33,7 @@ $timestart = time();
$relcount = 0;
$ri = new ReleaseImage();
$nzb = new NZB($pdo);
$consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$consoletools = new ConsoleTools();
$pdo->queryExec('UPDATE groups SET first_record = 0, first_record_postdate = NULL, last_record = 0, last_record_postdate = NULL, last_updated = NULL');
echo ColorCLI::primary('Reseting all groups completed.');
+1 -1
View File
@@ -27,7 +27,7 @@ if (isset($argv[1]) && ($argv[1] === 'true' || $argv[1] === 'check')) {
$releases = new Releases(['Settings' => $pdo]);
$nzb = new NZB($pdo);
$releaseImage = new ReleaseImage();
$consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$consoletools = new ConsoleTools();
$couldbe = $argv[1] === 'true' ? $couldbe = 'were ' : 'could be ';
$limit = $counterfixed = 0;
if (isset($argv[2]) && is_numeric($argv[2])) {
+2 -2
View File
@@ -55,7 +55,7 @@ function reCategorize($argv)
} else {
$chgcount = categorizeRelease('', $update, true);
}
$consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$consoletools = new ConsoleTools();
$time = $consoletools->convertTime(time() - $timestart);
if ($update === true) {
echo ColorCLI::header('Finished re-categorizing '.number_format($chgcount).' releases in '.$time.' , using the searchname.'.PHP_EOL);
@@ -72,7 +72,7 @@ function categorizeRelease($where, $update = true, $echooutput = false)
global $pdo;
$cat = new Categorize(['Settings' => $pdo]);
$pdo->log = new ColorCLI();
$consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$consoletools = new ConsoleTools();
$relcount = $chgcount = 0;
echo ColorCLI::primary('SELECT id, searchname, fromname, groups_id, categories_id FROM releases '.$where);
$resrel = $pdo->queryDirect('SELECT id, searchname, fromname, groups_id, categories_id FROM releases '.$where);
+1 -1
View File
@@ -27,7 +27,7 @@ function getPreName($argv)
{
global $pdo;
$timestart = time();
$consoletools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$consoletools = new ConsoleTools();
$namefixer = new NameFixer(['Settings' => $pdo, 'ConsoleTools' => $consoletools]);
$res = false;
@@ -1,44 +0,0 @@
<?php
require_once dirname(__DIR__, 4).DIRECTORY_SEPARATOR.'bootstrap/autoload.php';
use nntmux\NNTP;
use nntmux\Tmux;
use nntmux\ColorCLI;
use nntmux\processing\PostProcess;
$c = new ColorCLI();
if (! isset($argv[1])) {
exit($c->error('This script is not intended to be run manually, it is called from postprocess.php.'));
}
$tmux = new Tmux;
$torun = $tmux->get()->post;
$pieces = explode(' =+= ', $argv[1]);
$postprocess = new PostProcess(['Echo' => true]);
if (isset($pieces[6])) {
// Create the connection here and pass
$nntp = new NNTP();
if ($nntp->doConnect() === false) {
exit($c->error('Unable to connect to usenet.'));
}
$postprocess->processAdditional($nntp, $argv[1]);
$nntp->doQuit();
} elseif (isset($pieces[3])) {
// Create the connection here and pass
$nntp = new NNTP();
if ($nntp->doConnect() === false) {
exit($c->error('Unable to connect to usenet.'));
}
$postprocess->processNfos($argv[1], $nntp);
$nntp->doQuit();
} elseif (isset($pieces[2])) {
$postprocess->processMovies($argv[1]);
echo '.';
} elseif (isset($pieces[1])) {
$postprocess->processTv($argv[1]);
}
+1 -1
View File
@@ -9,7 +9,7 @@ use nntmux\ConsoleTools;
$start = time();
$pdo = new DB();
$consoleTools = new ConsoleTools(['ColorCLI' => $pdo->log]);
$consoleTools = new ConsoleTools();
// Create the connection here and pass
$nntp = new NNTP(['Settings' => $pdo]);
+15 -24
View File
@@ -8,7 +8,7 @@ namespace nntmux;
class ConsoleTools
{
/**
* @var ColorCLI
* @var \nntmux\ColorCLI
*/
public $cli;
@@ -18,19 +18,10 @@ class ConsoleTools
public $lastMessageLength;
/**
* Construct.
*
* @param array $options
* ConsoleTools constructor.
*/
public function __construct(array $options = [])
public function __construct()
{
$defaults = [
'ColorCLI' => null,
];
$options += $defaults;
$this->cli = ($options['ColorCLI'] instanceof ColorCLI ? $options['ColorCLI'] : new ColorCLI());
$this->lastMessageLength = 0;
}
@@ -44,11 +35,11 @@ class ConsoleTools
$this->lastMessageLength = 0;
}
echo str_repeat(chr(8), $this->lastMessageLength);
echo str_repeat(\chr(8), $this->lastMessageLength);
echo str_repeat(' ', $this->lastMessageLength);
echo str_repeat(chr(8), $this->lastMessageLength);
echo str_repeat(\chr(8), $this->lastMessageLength);
$this->lastMessageLength = strlen($message);
$this->lastMessageLength = \strlen($message);
echo ColorCLI::headerOver($message);
}
@@ -62,11 +53,11 @@ class ConsoleTools
$this->lastMessageLength = 0;
}
echo str_repeat(chr(8), $this->lastMessageLength);
echo str_repeat(\chr(8), $this->lastMessageLength);
echo str_repeat(' ', $this->lastMessageLength);
echo str_repeat(chr(8), $this->lastMessageLength);
echo str_repeat(\chr(8), $this->lastMessageLength);
$this->lastMessageLength = strlen($message);
$this->lastMessageLength = \strlen($message);
echo ColorCLI::primaryOver($message);
}
@@ -80,11 +71,11 @@ class ConsoleTools
$this->lastMessageLength = 0;
}
echo str_repeat(chr(8), $this->lastMessageLength);
echo str_repeat(\chr(8), $this->lastMessageLength);
echo str_repeat(' ', $this->lastMessageLength);
echo str_repeat(chr(8), $this->lastMessageLength);
echo str_repeat(\chr(8), $this->lastMessageLength);
$this->lastMessageLength = strlen($message);
$this->lastMessageLength = \strlen($message);
echo $message;
}
@@ -94,7 +85,7 @@ class ConsoleTools
public function appendWrite($message): void
{
echo $message;
$this->lastMessageLength += strlen($message);
$this->lastMessageLength += \strlen($message);
}
/**
@@ -106,7 +97,7 @@ class ConsoleTools
public function percentString($cur, $total): string
{
$percent = 100 * $cur / $total;
$formatString = '% '.strlen($total).'d/%d (% 2d%%)';
$formatString = '% '.\strlen($total).'d/%d (% 2d%%)';
return sprintf($formatString, $cur, $total, $percent);
}
@@ -122,7 +113,7 @@ class ConsoleTools
{
$percent1 = 100 * ($first - 1) / $total;
$percent2 = 100 * $last / $total;
$formatString = '% '.strlen($total).'d-% '.strlen($total).'d/%d (% 2d%%-% 3d%%)';
$formatString = '% '.\strlen($total).'d-% '.\strlen($total).'d/%d (% 2d%%-% 3d%%)';
return sprintf($formatString, $first, $last, $total, $percent1, $percent2);
}
+1 -1
View File
@@ -172,7 +172,7 @@ class NameFixer
$this->fullall = '';
$this->_fileName = '';
$this->done = $this->matched = false;
$this->consoletools = ($options['ConsoleTools'] instanceof ConsoleTools ? $options['ConsoleTools'] : new ConsoleTools(['ColorCLI' => $this->pdo->log]));
$this->consoletools = ($options['ConsoleTools'] instanceof ConsoleTools ? $options['ConsoleTools'] : new ConsoleTools());
$this->category = ($options['Categorize'] instanceof Categorize ? $options['Categorize'] : new Categorize(['Settings' => $this->pdo]));
$this->text = ($options['Misc'] instanceof Utility ? $options['Misc'] : new Utility());
$this->_groups = ($options['Groups'] instanceof Groups ? $options['Groups'] : new Groups(['Settings' => $this->pdo]));
+1 -1
View File
@@ -67,7 +67,7 @@ class PreDb
{
$this->dateLimit = $dateLimit;
$consoleTools = new ConsoleTools(['ColorCLI' => $this->pdo->log]);
$consoleTools = new ConsoleTools();
$updated = 0;
if ($this->echooutput) {
+1 -1
View File
@@ -133,7 +133,7 @@ class ReleaseRemover
$options += $defaults;
$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());
$this->consoleTools = ($options['ConsoleTools'] instanceof ConsoleTools ? $options['ConsoleTools'] : new ConsoleTools(['ColorCLI' => $this->pdo->log]));
$this->consoleTools = ($options['ConsoleTools'] instanceof ConsoleTools ? $options['ConsoleTools'] : new ConsoleTools());
$this->releases = ($options['Releases'] instanceof Releases ? $options['Releases'] : new Releases(['Settings' => $this->pdo]));
$this->nzb = ($options['NZB'] instanceof NZB ? $options['NZB'] : new NZB($this->pdo));
$this->releaseImage = ($options['ReleaseImage'] instanceof ReleaseImage ? $options['ReleaseImage'] : new ReleaseImage());
+1 -1
View File
@@ -138,7 +138,7 @@ class ProcessReleases
$this->echoCLI = ($options['Echo'] && NN_ECHOCLI);
$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());
$this->consoleTools = ($options['ConsoleTools'] instanceof ConsoleTools ? $options['ConsoleTools'] : new ConsoleTools(['ColorCLI' => $this->pdo->log]));
$this->consoleTools = ($options['ConsoleTools'] instanceof ConsoleTools ? $options['ConsoleTools'] : new ConsoleTools());
$this->groups = ($options['Groups'] instanceof Groups ? $options['Groups'] : new Groups(['Settings' => $this->pdo]));
$this->nzb = ($options['NZB'] instanceof NZB ? $options['NZB'] : new NZB($this->pdo));
$this->releaseCleaning = ($options['ReleaseCleaning'] instanceof ReleaseCleaning ? $options['ReleaseCleaning'] : new ReleaseCleaning($this->pdo));