<commit_before>#!/usr/bin/env python

import os
import json
import subprocess

from moulinette.utils.process import check_output
from moulinette.utils.filesystem import read_file, read_json, write_to_json
from yunohost.diagnosis import Diagnoser
from yunohost.utils.packages import ynh_packages_version


class BaseSystemDiagnoser(Diagnoser):

    id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
    cache_duration = 600
    dependencies = []

    def run(self):

        # Detect virt technology (if not bare metal) and arch
        # Gotta have this "|| true" because it systemd-detect-virt return 'none'
        # with an error code on bare metal ~.~
        virt = check_output("systemd-detect-virt || true", shell=True).strip()
        if virt.lower() == "none":
            virt = "bare-metal"

        # Detect arch
        arch = check_output("dpkg --print-architecture").strip()
        hardware = dict(meta={"test": "hardware"},
                        status="INFO",
                        data={"virt": virt, "arch": arch},
                        summary="diagnosis_basesystem_hardware")

        # Also possibly the board name
        if os.path.exists("/proc/device-tree/model"):
            model = read_file('/proc/device-tree/model').strip()
            hardware["data"]["model"] = model
            hardware["details"] = ["diagnosis_basesystem_hardware_board"]

        yield hardware

        # Kernel version
        kernel_version = read_file('/proc/sys/kernel/osrelease').strip()
        yield dict(meta={"test": "kernel"},
                   data={"kernel_version": kernel_version},
                   status="INFO",
                   summary="diagnosis_basesystem_kernel")

        # Debian release
        debian_version = read_file("/etc/debian_version").strip()<commit_msg>This file sometimes has stupid \x00 inside ~.~<commit_after>#!/usr/bin/env python

import os
import json
import subprocess

from moulinette.utils.process import check_output
from moulinette.utils.filesystem import read_file, read_json, write_to_json
from yunohost.diagnosis import Diagnoser
from yunohost.utils.packages import ynh_packages_version


class BaseSystemDiagnoser(Diagnoser):

    id_ = os.path.splitext(os.path.basename(__file__))[0].split("-")[1]
    cache_duration = 600
    dependencies = []

    def run(self):

        # Detect virt technology (if not bare metal) and arch
        # Gotta have this "|| true" because it systemd-detect-virt return 'none'
        # with an error code on bare metal ~.~
        virt = check_output("systemd-detect-virt || true", shell=True).strip()
        if virt.lower() == "none":
            virt = "bare-metal"

        # Detect arch
        arch = check_output("dpkg --print-architecture").strip()
        hardware = dict(meta={"test": "hardware"},
                        status="INFO",
                        data={"virt": virt, "arch": arch},
                        summary="diagnosis_basesystem_hardware")

        # Also possibly the board name
        if os.path.exists("/proc/device-tree/model"):
            model = read_file('/proc/device-tree/model').strip().replace('\x00', '')
            hardware["data"]["model"] = model
            hardware["details"] = ["diagnosis_basesystem_hardware_board"]

        yield hardware

        # Kernel version
        kernel_version = read_file('/proc/sys/kernel/osrelease').strip()
        yield dict(meta={"test": "kernel"},
                   data={"kernel_version": kernel_version},
                   status="INFO",
                   summary="diagnosis_basesystem_kernel")

        # Debian release
        debian_version = read_file("/etc/debian_version").strip()
{'fraction_non_alphanumeric': 0.12300621789672884, 'fraction_numerical': 0.003784806704514734, 'mean_word_length': 2.54066985645933, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, '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': '6328626', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1022, 'n_words': 234}