protected function execute(InputInterface $input, OutputInterface $output)
 {
     $config = $this->getApplication()->getConfig();
     $client = $this->getApplication()->getClient();
     $torrentList = $client->getTorrentData();
     $obsoleteList = TorrentListUtils::getObsoleteTorrents($torrentList);
     if (empty($obsoleteList)) {
         $output->writeln('There are no obsolete torrents in Transmission.');
         return 0;
     }
     $this->dryRun($input, $output, function () use($client, $obsoleteList, $config, $input, $output) {
         $influxDbClient = $this->getApplication()->getInfluxDbClient($config->get('influxdb-host'), $config->get('influxdb-port'), $config->get('influxdb-user'), $config->get('influxdb-password'), $config->get('influxdb-database'));
         $transmissionHost = $config->get('transmission-host');
         $influxDbClient->sendTorrentPoints($obsoleteList, $transmissionHost);
         $client->removeTorrents($obsoleteList);
         $names = TorrentListUtils::getArrayField($obsoleteList, Torrent\Get::NAME);
         $output->writeln('Removed torrents:' . implode(', ', $names));
     }, 'dry-run, don\'t really remove');
     $output->writeln('Found and deleted ' . count($obsoleteList) . ' obsolete torrents from transmission:');
     TorrentListUtils::printTorrentsTable($obsoleteList, $output);
     return 0;
 }
Пример #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $client = $this->getApplication()->getClient();
     $config = $this->getApplication()->getConfig();
     $torrentIds = $input->getArgument('torrent-ids');
     $torrentList = $client->getTorrentData($torrentIds);
     $notExistsIds = array_diff($torrentIds, TorrentListUtils::getArrayField($torrentList, Torrent\Get::ID));
     if (count($notExistsIds)) {
         foreach ($notExistsIds as $notExistsId) {
             $output->writeln($notExistsId . ' not exists');
         }
         return 1;
     }
     $output->writeln('Torrents for remove:');
     TorrentListUtils::printTorrentsTable($torrentList, $output);
     if (!$input->getOption('yes')) {
         $helper = $this->getHelper('question');
         $question = new ConfirmationQuestion('Continue with this action? ', false);
         if (!$helper->ask($input, $output, $question)) {
             $output->writeln('Aborting.');
             return 1;
         }
     }
     $this->dryRun($input, $output, function () use($config, $torrentList, $client, $input, $output) {
         $influxDbClient = $this->getApplication()->getInfluxDbClient($config->get('influxdb-host'), $config->get('influxdb-port'), $config->get('influxdb-user'), $config->get('influxdb-password'), $config->get('influxdb-database'));
         $transmissionHost = $config->get('transmission-host');
         $influxDbClient->sendTorrentPoints($torrentList, $transmissionHost);
         $deleteLocalData = !$input->getOption('soft');
         $client->removeTorrents($torrentList, $deleteLocalData);
         $output->writeln('Torrents removed.');
         if (!$deleteLocalData) {
             $output->writeln('Data don\'t removed.');
         }
     }, 'dry-run, don\'t really remove torrents');
     return 0;
 }
 public function testPrintTorrentsTable()
 {
     $output = new NullOutput();
     TorrentListUtils::printTorrentsTable($this->expectedTorrentList, $output, 1, 2);
 }
Пример #4
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $client = $this->getApplication()->getClient();
     $torrentList = $client->getTorrentData();
     $torrentList = array_map(function ($torrent) {
         $torrent['age'] = TorrentUtils::getTorrentAgeInDays($torrent);
         return $torrent;
     }, $torrentList);
     $torrentList = TorrentListUtils::filterTorrents($torrentList, ['age' => $input->getOption('age'), 'name' => $input->getOption('name')]);
     TorrentListUtils::printTorrentsTable($torrentList, $output, $input->getOption('sort'), $input->getOption('limit'));
     $freeSpace = $client->getFreeSpace();
     $output->writeln('Free space: ' . TorrentUtils::getSizeInGb($freeSpace) . ' GB');
 }