<commit_before># This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""The model that represents a boot document in the mongodb collection."""

import models
import models.base as modb


# pylint: disable=too-many-public-methods
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments
# pylint: disable=invalid-name
class BootDocument(modb.BaseDocument):
    """Model for a boot document.

    Each document is a single booted board.
    """

    def __init__(
            self, board, job, kernel, defconfig, lab_name,
            defconfig_full=None, arch=models.ARM_ARCHITECTURE_KEY):
        """A new BootDocument.

        :param board: The name of the board.
        :type board: str
        :param job: The name of the job.
        :type job: str
        :param kernel: The name of the kernel.
        :type kernel: str
        :param defconfig: The name of the defconfig.
        :type defconfig: str
        :param lab_name: The user readable ID of the lab.
        :type lab_name: str
        """
        self._board = board
        self._job = job
        self._kernel = kernel
        self._defconfig = defconfig
        self._lab_name = lab_name
        self._defconfig_full = defconfig_full or defconfig
        self._arch = arch

        self._name = models.BOOT_DOCUMENT_NAME % {
            models.BOARD_KEY: board,
            models.DEFCONFIG_KEY: defconfig_full or defconfig,
            models.JOB_KEY: job,
            models.KERNEL_KEY: kernel,
            models.ARCHITECTURE_KEY: arch
        }
        self._id = None
        self._created_on = None
        self._version = None

        self.boot_log = None
        self.boot_log_html = None
        self.boot_result_description = None
        self.defconfig_id = None
        self.dtb = None
        self.dtb_addr = None
        self.dtb_append = None
        self.endianness = None
        self.fastboot = False
        self.fastboot_cmd = None
        self.git_branch = None
        self.git_commit = None
        self.git_describe = None
        self.git_url = None
        self.initrd_addr = None
        self.job_id = None
        self.kernel_image = None
        self.load_addr = None
        self.metadata = {}
        self.retries = 0
        self.status = None
        self.time = 0
        self.warnings = 0

    @property
    def collection(self):
        return models.BOOT_COLLECTION

    @property
    def name(self):
        """The name of the boot report."""
        return self._name

    @property
    def id(self):
        """The ID of this object as returned by mongodb."""
        return self._id

    @id.setter
    def id(self, value):
        """Set the ID of this object with the ObjectID from mongodb.

        :param value: The ID of this object.
        :type value: str
        """
        self._id = value

    @property
    def arch(self):
        """The architecture of the board."""
        return self._arch

    @property
    def board(self):
        """The board of this document."""
        return self._board

    @property
    def job(self):
        """The job this boot document belongs to."""
        return self._job

    @property
    def kernel(self):
        """The kernel this boot document belongs to."""
        return self._kernel

    @property
    def defconfig(self):
        """The defconfig of this boot document."""
        return self._defconfig

    @property
    def defconfig_full(self):
        """The full value of the defconfig, with fragments."""
        return self._defconfig_full

    @defconfig_full.setter
    def defconfig_full(self, value):
        """Set the defconfig full name."""
        self._defconfig_full = value

    @property
    def lab_name(self):
        """Get the lab ID value of this boot report."""
        return self._lab_name

    @lab_name.setter
    def lab_name(self, value):
        """Set the lab ID value."""
        self._lab_name = value

    @property
    def created_on(self):
        """When this lab object was created."""
        return self._created_on

    @created_on.setter
    def created_on(self, value):
        """Set the creation date of this lab object.

        :param value: The lab creation date, in UTC time zone.
        :type value: datetime
        """
        self._created_on = value

    @property
    def version(self):
        """The version of this document schema."""
        return self._version

    @version.setter
    def version(self, value):
        """The version of this document schema."""
        self._version = value

    def to_dict(self):
        boot_dict = {
            models.ARCHITECTURE_KEY: self.arch,
            models.BOARD_KEY: self.board,
            models.BOOT_LOG_HTML_KEY: self.boot_log_html,
            models.BOOT_LOG_KEY: self.boot_log,
            models.BOOT_RESULT_DESC_KEY: self.boot_result_description,
            models.CREATED_KEY: self.created_on,
            models.DEFCONFIG_FULL_KEY: self.defconfig_full,
            models.DEFCONFIG_ID_KEY: self.defconfig_id,
            models.DEFCONFIG_KEY: self.defconfig,
            models.DTB_ADDR_KEY: self.dtb_addr,
            models.DTB_APPEND_KEY: self.dtb_append,
            models.DTB_KEY: self.dtb,
            models.ENDIANNESS_KEY: self.endianness,
            models.FASTBOOT_CMD_KEY: self.fastboot_cmd,
            models.FASTBOOT_KEY: self.fastboot,
            models.GIT_BRANCH_KEY: self.git_branch,
            models.GIT_COMMIT_KEY: self.git_commit,
            models.GIT_DESCRIBE_KEY: self.git_describe,
            models.GIT_URL_KEY: self.git_url,
            models.INITRD_ADDR_KEY: self.initrd_addr,
            models.JOB_ID_KEY: self.job_id,
            models.JOB_KEY: self.job,
            models.KERNEL_IMAGE_KEY: self.kernel_image,
            models.KERNEL_KEY: self.kernel,
            models.LAB_NAME_KEY: self.lab_name,
            models.LOAD_ADDR_KEY: self.load_addr,
            models.METADATA_KEY: self.metadata,
            models.NAME_KEY: self.name,
            models.RETRIES_KEY: self.retries,
            models.STATUS_KEY: self.status,
            models.TIME_KEY: self.time,
            models.VERSION_KEY: self.version,
            models.WARNINGS_KEY: self.warnings,
        }

        if self.id:
            boot_dict[models.ID_KEY] = self.id

        return boot_dict

    @staticmethod
    def from_json(json_obj):
        return None
<commit_msg>boot: Clean up model code.<commit_after># This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""The model that represents a boot document in the mongodb collection."""

import models
import models.base as modb


# pylint: disable=too-many-public-methods
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments
# pylint: disable=invalid-name
class BootDocument(modb.BaseDocument):
    """Model for a boot document.

    Each document is a single booted board.
    """

    def __init__(
            self, board, job, kernel, defconfig, lab_name,
            defconfig_full=None, arch=models.ARM_ARCHITECTURE_KEY):
        """A new BootDocument.

        :param board: The name of the board.
        :type board: str
        :param job: The name of the job.
        :type job: str
        :param kernel: The name of the kernel.
        :type kernel: str
        :param defconfig: The name of the defconfig.
        :type defconfig: str
        :param lab_name: The user readable ID of the lab.
        :type lab_name: str
        """

        doc_name = models.BOOT_DOCUMENT_NAME % {
            models.BOARD_KEY: board,
            models.DEFCONFIG_KEY: defconfig_full or defconfig,
            models.JOB_KEY: job,
            models.KERNEL_KEY: kernel,
            models.ARCHITECTURE_KEY: arch
        }

        self._created_on = None
        self._id = None
        self._name = doc_name
        self._version = None

        self._arch = arch
        self._board = board
        self._defconfig = defconfig
        self._defconfig_full = defconfig_full or defconfig
        self._job = job
        self._kernel = kernel
        self._lab_name = lab_name
        self.boot_log = None
        self.boot_log_html = None
        self.boot_result_description = None
        self.defconfig_id = None
        self.dtb = None
        self.dtb_addr = None
        self.dtb_append = None
        self.endianness = None
        self.fastboot = False
        self.fastboot_cmd = None
        self.git_branch = None
        self.git_commit = None
        self.git_describe = None
        self.git_url = None
        self.initrd_addr = None
        self.job_id = None
        self.kernel_image = None
        self.load_addr = None
        self.metadata = {}
        self.retries = 0
        self.status = None
        self.time = 0
        self.warnings = 0

    @property
    def collection(self):
        return models.BOOT_COLLECTION

    @property
    def name(self):
        """The name of the boot report."""
        return self._name

    @property
    def id(self):
        """The ID of this object as returned by mongodb."""
        return self._id

    @id.setter
    def id(self, value):
        """Set the ID of this object with the ObjectID from mongodb.

        :param value: The ID of this object.
        :type value: str
        """
        self._id = value

    @property
    def arch(self):
        """The architecture of the board."""
        return self._arch

    @property
    def board(self):
        """The board of this document."""
        return self._board

    @property
    def job(self):
        """The job this boot document belongs to."""
        return self._job

    @property
    def kernel(self):
        """The kernel this boot document belongs to."""
        return self._kernel

    @property
    def defconfig(self):
        """The defconfig of this boot document."""
        return self._defconfig

    @property
    def defconfig_full(self):
        """The full value of the defconfig, with fragments."""
        return self._defconfig_full

    @defconfig_full.setter
    def defconfig_full(self, value):
        """Set the defconfig full name."""
        self._defconfig_full = value

    @property
    def lab_name(self):
        """Get the lab ID value of this boot report."""
        return self._lab_name

    @lab_name.setter
    def lab_name(self, value):
        """Set the lab ID value."""
        self._lab_name = value

    @property
    def created_on(self):
        """When this lab object was created."""
        return self._created_on

    @created_on.setter
    def created_on(self, value):
        """Set the creation date of this lab object.

        :param value: The lab creation date, in UTC time zone.
        :type value: datetime
        """
        self._created_on = value

    @property
    def version(self):
        """The version of this document schema."""
        return self._version

    @version.setter
    def version(self, value):
        """The version of this document schema."""
        self._version = value

    def to_dict(self):
        boot_dict = {
            models.ARCHITECTURE_KEY: self.arch,
            models.BOARD_KEY: self.board,
            models.BOOT_LOG_HTML_KEY: self.boot_log_html,
            models.BOOT_LOG_KEY: self.boot_log,
            models.BOOT_RESULT_DESC_KEY: self.boot_result_description,
            models.CREATED_KEY: self.created_on,
            models.DEFCONFIG_FULL_KEY: self.defconfig_full,
            models.DEFCONFIG_ID_KEY: self.defconfig_id,
            models.DEFCONFIG_KEY: self.defconfig,
            models.DTB_ADDR_KEY: self.dtb_addr,
            models.DTB_APPEND_KEY: self.dtb_append,
            models.DTB_KEY: self.dtb,
            models.ENDIANNESS_KEY: self.endianness,
            models.FASTBOOT_CMD_KEY: self.fastboot_cmd,
            models.FASTBOOT_KEY: self.fastboot,
            models.GIT_BRANCH_KEY: self.git_branch,
            models.GIT_COMMIT_KEY: self.git_commit,
            models.GIT_DESCRIBE_KEY: self.git_describe,
            models.GIT_URL_KEY: self.git_url,
            models.INITRD_ADDR_KEY: self.initrd_addr,
            models.JOB_ID_KEY: self.job_id,
            models.JOB_KEY: self.job,
            models.KERNEL_IMAGE_KEY: self.kernel_image,
            models.KERNEL_KEY: self.kernel,
            models.LAB_NAME_KEY: self.lab_name,
            models.LOAD_ADDR_KEY: self.load_addr,
            models.METADATA_KEY: self.metadata,
            models.NAME_KEY: self.name,
            models.RETRIES_KEY: self.retries,
            models.STATUS_KEY: self.status,
            models.TIME_KEY: self.time,
            models.VERSION_KEY: self.version,
            models.WARNINGS_KEY: self.warnings,
        }

        if self.id:
            boot_dict[models.ID_KEY] = self.id

        return boot_dict

    @staticmethod
    def from_json(json_obj):
        return None

{'fraction_non_alphanumeric': 0.08326235093696763, 'fraction_numerical': 0.0005678591709256105, 'mean_word_length': 2.1101545253863137, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6466363', 'n_tokens_mistral': 4100, 'n_tokens_neox': 4004, 'n_words': 1186}