Beispiel #1
0
 protected function buildContentFiltering(Command $command, array $contains, $not = false)
 {
     foreach ($contains as $contain) {
         $expr = Expression::create($contain);
         $command->add('| xargs -I{} -r grep -I')->add($expr->isCaseSensitive() ? null : '-i')->add($not ? '-L' : '-l')->add('-Ee')->arg($expr->renderPattern())->add('{}');
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function buildContentFiltering(Command $command, array $contains, $not = false)
 {
     foreach ($contains as $contain) {
         $expr = Expression::create($contain);
         // todo: avoid forking process for each $pattern by using multiple -e options
         $command->add('| grep -v \'^$\'')->add('| xargs -I{} grep -I')->add($expr->isCaseSensitive() ? null : '-i')->add($not ? '-L' : '-l')->add('-Ee')->arg($expr->renderPattern())->add('{}');
     }
 }
Beispiel #3
0
 public function testCastToString()
 {
     $cmd = Command::create();
     $cmd->add('--force');
     $cmd->add('--run');
     $this->assertSame('--force --run', (string) $cmd);
 }
Beispiel #4
0
 private function buildDatesFiltering(Command $command, array $dates)
 {
     foreach ($dates as $i => $date) {
         $command->add($i > 0 ? '-and' : null);
         $mins = (int) round((time() - $date->getTarget()) / 60);
         if (0 > $mins) {
             $command->add(' -mmin -0');
             return;
         }
         switch ($date->getOperator()) {
             case '<=':
                 $command->add('-mmin +' . ($mins - 1));
                 break;
             case '>=':
                 $command->add('-mmin -' . ($mins + 1));
                 break;
             case '>':
                 $command->add('-mmin -' . $mins);
                 break;
             case '!=':
                 $command->add('-mmin +' . $mins . ' -or -mmin -' . $mins);
                 break;
             case '<':
             default:
                 $command->add('-mmin +' . $mins);
         }
     }
 }
 /**
  * @param AdapterInterface $adapter
  * @param Command          $command
  * @param \Exception|null  $previous
  */
 public function __construct(AdapterInterface $adapter, Command $command, \Exception $previous = null)
 {
     $this->command = $command;
     parent::__construct($adapter, 'Shell command failed: "' . $command->join() . '".', $previous);
 }
Beispiel #6
0
 /**
  * {@inheritdoc}
  */
 protected function buildFormatSorting(Command $command, $format)
 {
     $command->get('find')->add('-printf')->arg($format . ' %h/%f\\n')->add('| sort | cut')->arg('-d ')->arg('-f2-');
 }
Beispiel #7
0
    private function buildSorting(Command $command, $sort)
    {
        switch ($sort) {
            case SortableIterator::SORT_BY_NAME:
                $format = null;
                break;
            case SortableIterator::SORT_BY_TYPE:
                $format = '%y';
                break;
            case SortableIterator::SORT_BY_ACCESSED_TIME:
                $format = '%A@';
                break;
            case SortableIterator::SORT_BY_CHANGED_TIME:
                $format = '%C@';
                break;
            case SortableIterator::SORT_BY_MODIFIED_TIME:
                $format = '%T@';
                break;
            default:
                throw new \InvalidArgumentException('Unknown sort options: '.$sort.'.');
        }

        $command->get('find')->add('-printf')->arg($format.' %h/%f\\n');
        $command->ins('sort')->add('| sort');
        $command->ins('awk')->add('| awk')->arg('{ print $'.(null === $format ? '1' : '2').' }');
    }
Beispiel #8
0
 /**
  * @param Command $command
  * @param string  $sort
  *
  * @throws \InvalidArgumentException
  */
 private function buildSorting(Command $command, $sort)
 {
     switch ($sort) {
         case SortableIterator::SORT_BY_NAME:
             $command->ins('sort')->add('| sort');
             return;
         case SortableIterator::SORT_BY_TYPE:
             $format = '%y';
             break;
         case SortableIterator::SORT_BY_ACCESSED_TIME:
             $format = '%A@';
             break;
         case SortableIterator::SORT_BY_CHANGED_TIME:
             $format = '%C@';
             break;
         case SortableIterator::SORT_BY_MODIFIED_TIME:
             $format = '%T@';
             break;
         default:
             throw new \InvalidArgumentException('Unknown sort options: ' . $sort . '.');
     }
     $this->buildFormatSorting($command, $format);
 }