native.py 2.93 KB
Newer Older
Jonny Lamb's avatar
Jonny Lamb committed
1
2
3
4
# -*- coding: utf-8 -*-
#
#   native.py — native QA plugin
#
Arno Töll's avatar
Arno Töll committed
5
#   This file is part of debexpo - https://alioth.debian.org/projects/debexpo/
Jonny Lamb's avatar
Jonny Lamb committed
6
#
Jonny Lamb's avatar
Jonny Lamb committed
7
#   Copyright © 2008 Jonny Lamb <jonny@debian.org>
8
#   Copyright © 2012 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
9
#   Copyright © 2012 Clément Schreiner <clement@mux.me>
Jonny Lamb's avatar
Jonny Lamb committed
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
#
#   Permission is hereby granted, free of charge, to any person
#   obtaining a copy of this software and associated documentation
#   files (the "Software"), to deal in the Software without
#   restriction, including without limitation the rights to use,
#   copy, modify, merge, publish, distribute, sublicense, and/or sell
#   copies of the Software, and to permit persons to whom the
#   Software is furnished to do so, subject to the following
#   conditions:
#
#   The above copyright notice and this permission notice shall be
#   included in all copies or substantial portions of the Software.
#
#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
#   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
#   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
#   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
#   OTHER DEALINGS IN THE SOFTWARE.

"""
Holds the native plugin.
"""

__author__ = 'Jonny Lamb'
37
38
39
__copyright__ = ", ".join([
        'Copyright © 2008 Jonny Lamb',
        'Copyright © 2012 Nicolas Dandrimont',
40
        'Copyright © 2012 Clément Schreiner',
41
        ])
Jonny Lamb's avatar
Jonny Lamb committed
42
43
44
45
__license__ = 'MIT'

import logging

46
from debexpo.lib import constants, filesystem
47
from debexpo.plugins.api import *
48

Jonny Lamb's avatar
Jonny Lamb committed
49
50
log = logging.getLogger(__name__)

51
52
53

@test_result
class NativeTest(PluginResult):
54
55
56
    """
    Result of the 'native' plugin for a package.
    """
57

58
    is_native = bool_field('native')
59

60
61
62
    def __str__(self):
        return 'Package is %s native' % ('' if self.is_native else 'not')

Jonny Lamb's avatar
Jonny Lamb committed
63

64
class NativePlugin(QAPlugin):
65
66
67
    """
    Plugin checking whether a package is a native package.
    """
68

69
    @importercmd
Jonny Lamb's avatar
Jonny Lamb committed
70
71
72
73
74
    def test_native(self):
        """
        Test to see whether the package is a native package.
        """
        log.debug('Checking whether the package is native or not')
75
        filecheck = filesystem.CheckFiles()
Jonny Lamb's avatar
Jonny Lamb committed
76

77
        is_native = filecheck.is_native_package(self.changes)
Jonny Lamb's avatar
Jonny Lamb committed
78

79
        result = self.new_test_result()
80
        if is_native:
Jonny Lamb's avatar
Jonny Lamb committed
81
82
83
            # Most uploads will not be native, and especially on mentors, a native
            # package is almost probably in error.
            log.warning('Package is native')
84

85
            result['severity'] = constants.PLUGIN_SEVERITY_WARNING
Jonny Lamb's avatar
Jonny Lamb committed
86
87
        else:
            log.debug('Package is not native')
88
            result['severity'] = constants.PLUGIN_SEVERITY_INFO
Jonny Lamb's avatar
Jonny Lamb committed
89

Clément Schreiner's avatar
Clément Schreiner committed
90
        result.is_native = is_native
91

Jonny Lamb's avatar
Jonny Lamb committed
92
plugin = NativePlugin
93
94
95
models = [
    NativeTest,
    ]