<commit_before><?php

namespace Drucker;

use Illuminate\Support\Str;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;
use Symfony\Component\Process\Exception\ProcessFailedException;

class Drucker
{
    private $filesystem;
    private $mailPath;
    private $command;

    public function __construct($mailPath = 'mails', $command = 'lp', $filesystem = null)
    {
        $this->command = $command;
        $this->filesystem = $filesystem ?: new Filesystem();

        $this->prepareDirectory($mailPath);
        $this->mailPath = $mailPath;
    }

    private function prepareDirectory($directory)
    {
        if (!$this->filesystem->isDirectory($directory)) {
            $this->filesystem->makeDirectory($directory, 0755, true);
        }
    }

    private function cleanupDirectory($directory)
    {
        $this->filesystem->delete($directory);
    }

    public function queue($contents)
    {
        $filePath = $this->mailPath . '/' . Str::random(32);

        $this->filesystem->put($filePath, $contents);

        $builder = $this->createProcessBuilder();
        $process = $builder->setInput($filePath)->getProcess();

        $output = $this->getOutput($process);

        // This is pretty much a fire-and-forget approach.
        if (preg_match("/request\s+id\s+is\s+(.*)\s+\(\d+ file\(s\)\)/", $output, $match)) {
            $this->filesystem->delete($filePath);
        }
    }

    protected function createProcessBuilder()
    {
        return ProcessBuilder::create()->setPrefix($this->command);
    }

    protected function getOutput(Process $process)
    {
        $process->run();
        if (!$process->isSuccessful()) {
            throw new ProcessFailedException($process->getErrorOutput());
        }
        return $process->getOutput();
    }
}<commit_msg>Set mail path as argument<commit_after><?php

namespace Drucker;

use Illuminate\Support\Str;
use Illuminate\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;
use Symfony\Component\Process\Exception\ProcessFailedException;

class Drucker
{
    private $filesystem;
    private $mailPath;
    private $command;

    public function __construct($mailPath = 'mails', $command = 'lp', $filesystem = null)
    {
        $this->command = $command;
        $this->filesystem = $filesystem ?: new Filesystem();

        $this->prepareDirectory($mailPath);
        $this->mailPath = $mailPath;
    }

    private function prepareDirectory($directory)
    {
        if (!$this->filesystem->isDirectory($directory)) {
            $this->filesystem->makeDirectory($directory, 0755, true);
        }
    }

    private function cleanupDirectory($directory)
    {
        $this->filesystem->delete($directory);
    }

    public function queue($contents)
    {
        $filePath = $this->mailPath . '/' . Str::random(32);

        $this->filesystem->put($filePath, $contents);

        $builder = $this->createProcessBuilder();
        $process = $builder->add($filePath)->getProcess();

        $output = $this->getOutput($process);

        // This is pretty much a fire-and-forget approach.
        if (preg_match("/request\s+id\s+is\s+(.*)\s+\(\d+ file\(s\)\)/", $output, $match)) {
            $this->filesystem->delete($filePath);
        }
    }

    protected function createProcessBuilder()
    {
        return ProcessBuilder::create()->setPrefix($this->command);
    }

    protected function getOutput(Process $process)
    {
        $process->run();
        if (!$process->isSuccessful()) {
            throw new ProcessFailedException($process->getErrorOutput());
        }
        return $process->getOutput();
    }
}
{'fraction_non_alphanumeric': 0.15105417667467308, 'fraction_numerical': 0.0032025620496397116, 'mean_word_length': 2.8759048603929678, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2433712', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1050, 'n_words': 192}