This file is indexed.

/usr/lib/python3/dist-packages/plainbox/impl/unit/file.py is in python3-plainbox 0.25-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# This file is part of Checkbox.
#
# Copyright 2014 Canonical Ltd.
# Written by:
#   Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
#
# Checkbox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3,
# as published by the Free Software Foundation.
#
# Checkbox 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 Checkbox.  If not, see <http://www.gnu.org/licenses/>.

"""
:mod:`plainbox.impl.unit.file` -- file unit
===========================================
"""

import logging
import os

from plainbox.i18n import gettext as _
from plainbox.i18n import gettext_noop as N_
from plainbox.impl.symbol import SymbolDef
from plainbox.impl.unit.job import propertywithsymbols
from plainbox.impl.unit.unit import Unit, UnitValidator
from plainbox.impl.unit.validators import CorrectFieldValueValidator
from plainbox.impl.validation import Problem
from plainbox.impl.validation import Severity

__all__ = ['FileRole', 'FileUnit']


logger = logging.getLogger("plainbox.unit.file")


class FileRole(SymbolDef):
    """
    Symbols that correspond to the role that a particular file plays.

    Each file in a particular provider can be classified to belong to one
    of the following roles. It is possible that the set of roles is not
    exhaustive and new roles will be added in the futurte.
    """
    unit_source = 'unit-source'
    legacy_whitelist = 'legacy-whitelist'
    script = 'script'  # architecture independent executable
    binary = 'binary'  # architecture dependent executable
    data = 'data'  # data file
    i18n = 'i18n'  # translation catalog
    manage_py = 'manage.py'  # management script
    legal = 'legal'  # license & copyright
    docs = 'docs'  # documentation
    unknown = 'unknown'  # unknown / unclassified
    build = 'build'  # build artefact
    invalid = 'invalid'  # invalid file that will never be used
    vcs = 'vcs'  # version control system data
    src = 'src'  # source


class FileUnitValidator(UnitValidator):
    """
    Validator for the FileUnit class.

    The sole purpose of this class is to have a custom :meth:`explain()`
    so that we can skip the 'field' part as nobody is really writing file
    units and the notion of a field may be confusing.
    """

    def explain(self, unit, field, kind, message):
        stock_msg = self._explain_map.get(kind)
        if message or stock_msg:
            return message or stock_msg


class FileUnit(Unit):
    """
    Unit that describes a single file.

    Every file that is a part of a provider has a corresponding file unit.
    Units like this are automatically generated by the provider itself.

    The file unit can be still defined to provide any additional meta-data.
    The file unit is used for contextual validation of job definitions and
    other unit types. The sole purpose, for now, is to advise against using
    the ``.txt`` or the ``.txt.in`` extensions in favour of the new one
    ``.pxu``
    """

    def __str__(self):
        """
        Same as .path
        """
        return self.path

    def __repr__(self):
        return "<FileUnit path:{!r}, role:{!r}>".format(self.path, self.role)

    @property
    def path(self):
        """
        Absolute path of the file this unit describes

        Typically you may wish to construct a relative path, using some other
        directory as the base directory, depending on context.
        """
        return self.get_record_value('path')

    @propertywithsymbols(symbols=FileRole)
    def role(self):
        """
        Role of the file within the provider
        """
        return self.get_record_value('role')

    class Meta:

        name = N_('file')

        validator_cls = FileUnitValidator

        class fields(SymbolDef):
            """
            Symbols for each field that a FileUnit can have
            """
            path = 'path'
            role = 'role'
            base = 'base'

        field_validators = {
            fields.path: [
                CorrectFieldValueValidator(
                    lambda value: os.path.splitext(value)[1] == '.pxu',
                    Problem.deprecated, Severity.advice,
                    onlyif=lambda unit: unit.role == FileRole.unit_source,
                    message=_(
                        "please use .pxu as an extension for all"
                        " files with plainbox units, see: {}"
                    ).format(
                        'http://plainbox.readthedocs.org/en/latest/author/'
                        'faq.html#faq-1'
                    )),
            ],
            fields.role: [
                CorrectFieldValueValidator(
                    lambda value: value in FileRole.get_all_symbols(),
                    message=_('valid values are: {}').format(
                        ', '.join(str(sym) for sym in sorted(
                            FileRole.get_all_symbols())))),
            ]
        }