<commit_before><?php

/*
 * This file is part of Linfo (c) 2010, 2012 <NAME>.
 * 
 * Linfo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Linfo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Linfo. If not, see <http://www.gnu.org/licenses/>.
 * 
*/

namespace Linfo\OS;

use Exception;
use Linfo\Meta\Timer;
use Linfo\Meta\Errors;
use Linfo\Common;

/*
 * Alpha osx class
 * Differs very slightly from the FreeBSD, especially in the fact that
 * only root can access dmesg
 */

class Darwin extends BSDcommon
{
    // Encapsulate these
    protected $settings,
        $exec,
        $dmesg;

    // Start us off
    public function __construct($settings)
    {

        // Instantiate parent
        parent::__construct($settings);

        // We search these folders for our commands
        $this->exec->setSearchPaths(array('/sbin', '/bin', '/usr/bin', '/usr/sbin'));

        // We need these sysctl values
        $this->GetSysCTL(array(
            'machdep.cpu.vendor',
            'machdep.cpu.brand_string',
            'hw.cpufrequency',
            'hw.ncpu',
            'vm.swapusage',
            'hw.memsize',
            'hw.usermem',
            'kern.boottime',
            'vm.loadavg',
            'hw.model',
        ), false);

        // And get this info for when the above fails 
        try {
            $this->systemProfiler = $this->exec->exec('system_profiler', 'SPHardwareDataType SPSoftwareDataType SPPowerDataType');
        } catch (Exception $e) {
            // Meh
            Errors::add('Linfo Mac OS 10', 'Error using system_profiler');
        }
    }

    // What we should leave out
    public function getContains()
    {
        return array(
                'hw_vendor' => false,
                'drives_rw_stats' => false,
                'drives_vendor' => false,
                'nic_type' => false,
                'nic_port_speed' => false,
            );
    }

    // Operating system
    public function getOS()
    {
        return 'Darwin ('.(preg_match('/^\s+System Version: ([^\(]+)/m', $this->systemProfiler, $m) ? $m[1] : 'Mac OS X').')';
    }

    // Hostname
    public function getHostname()
    {
        return preg_match('/^\s*Computer Name:\s+(.+)\s*$/m', $this->systemProfiler, $m) ? $m[1] : php_uname('n');
    }

    // Get mounted file systems
    public function getMounts()
    {
        // Time?
        if (!empty($this->settings['timer'])) {
            $t = new Timer('Mounted file systems');<commit_msg>Remove extra whitespace from osx version<commit_after><?php

/*
 * This file is part of Linfo (c) 2010, 2012 <NAME>.
 * 
 * Linfo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Linfo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Linfo. If not, see <http://www.gnu.org/licenses/>.
 * 
*/

namespace Linfo\OS;

use Exception;
use Linfo\Meta\Timer;
use Linfo\Meta\Errors;
use Linfo\Common;

/*
 * Alpha osx class
 * Differs very slightly from the FreeBSD, especially in the fact that
 * only root can access dmesg
 */

class Darwin extends BSDcommon
{
    // Encapsulate these
    protected $settings,
        $exec,
        $dmesg;

    // Start us off
    public function __construct($settings)
    {

        // Instantiate parent
        parent::__construct($settings);

        // We search these folders for our commands
        $this->exec->setSearchPaths(array('/sbin', '/bin', '/usr/bin', '/usr/sbin'));

        // We need these sysctl values
        $this->GetSysCTL(array(
            'machdep.cpu.vendor',
            'machdep.cpu.brand_string',
            'hw.cpufrequency',
            'hw.ncpu',
            'vm.swapusage',
            'hw.memsize',
            'hw.usermem',
            'kern.boottime',
            'vm.loadavg',
            'hw.model',
        ), false);

        // And get this info for when the above fails 
        try {
            $this->systemProfiler = $this->exec->exec('system_profiler', 'SPHardwareDataType SPSoftwareDataType SPPowerDataType');
        } catch (Exception $e) {
            // Meh
            Errors::add('Linfo Mac OS 10', 'Error using system_profiler');
        }
    }

    // What we should leave out
    public function getContains()
    {
        return array(
                'hw_vendor' => false,
                'drives_rw_stats' => false,
                'drives_vendor' => false,
                'nic_type' => false,
                'nic_port_speed' => false,
            );
    }

    // Operating system
    public function getOS()
    {
        return 'Darwin ('.(preg_match('/^\s+System Version: ([^\(]+)/m', $this->systemProfiler, $m) ? trim($m[1]) : 'Mac OS X').')';
    }

    // Hostname
    public function getHostname()
    {
        return preg_match('/^\s*Computer Name:\s+(.+)\s*$/m', $this->systemProfiler, $m) ? $m[1] : php_uname('n');
    }

    // Get mounted file systems
    public function getMounts()
    {
        // Time?
        if (!empty($this->settings['timer'])) {
            $t = new Timer('Mounted file systems');
{'fraction_non_alphanumeric': 0.12413560465508518, 'fraction_numerical': 0.004385225164445943, 'mean_word_length': 2.1309398099260823, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7284893', 'n_tokens_mistral': 1775, 'n_tokens_neox': 1694, 'n_words': 546}