controlfields.py 3.71 KB
Newer Older
Jonny Lamb's avatar
Jonny Lamb committed
1
2
3
4
# -*- coding: utf-8 -*-
#
#   controlfields.py — controlfields 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 © 2010 Jan Dittberner <jandd@debian.org>
9
#   Copyright © 2012 Nicolas Dandrimont <Nicolas.Dandrimont@crans.org>
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 controlfields plugin.
"""

__author__ = 'Jonny Lamb'
37
38
39
40
41
__copyright__ = ', '.join([
        'Copyright © 2008 Jonny Lamb',
        'Copyright © 2010 Jan Dittberner',
        'Copyright © 2012 Nicolas Dandrimont',
        ])
Jonny Lamb's avatar
Jonny Lamb committed
42
43
__license__ = 'MIT'

44
from debian import deb822
Jonny Lamb's avatar
Jonny Lamb committed
45
46
import logging

47
from debexpo.lib import constants
48
49
from debexpo.plugins.api import *
from debexpo.model import meta
Jonny Lamb's avatar
Jonny Lamb committed
50
51
52

log = logging.getLogger(__name__)

53
54
fields = ['Homepage', 'Vcs-Browser', 'Vcs-Git', 'Vcs-Svn', 'Vcs-Bzr', 'Vcs-Hg']

Jonny Lamb's avatar
Jonny Lamb committed
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
@test_result
class ControlfieldTest(PluginResult):
    """ Result of the control fields plugin """

    homepage = bool_field('homepage')
    vcs = bool_field('vcs')

    def get_fields(self):

        q = meta.session.query(ControlField)
        q = q.filter_by(package_version=self.package_version)
        return dict((f.field, f.value) for f in q.all())

    def __str__(self):
        if self.homepage:
            return 'Homepage {vcs} control field{s} present'.format(
                vcs='and VCS' if self.vcs else '',
                s='s' if self.vcs else '')


class ControlField(PluginResult):
    """ Additional debian/control field """
    field = string_field('field')
    value = string_field('data')


class ControlFieldsPlugin(QAPlugin):

    @importercmd
85
    def test_control_fields(self):
Jonny Lamb's avatar
Jonny Lamb committed
86
87
88
        """
        Checks whether additional debian/control fields are present.
        """
89
90
        log.debug('Checking whether additional debian/control'
                  'fields are present')
Jonny Lamb's avatar
Jonny Lamb committed
91
92

        try:
93
            dsc = deb822.Dsc(file(self.changes.get_dsc()))
Jonny Lamb's avatar
Jonny Lamb committed
94
95
96
97
        except:
            log.critical('Could not open dsc file; skipping plugin')
            return

98
99
        severity = constants.PLUGIN_SEVERITY_WARNING

100
        found_homepage = False
101
102
        for item in fields:
            if item in dsc:
103
104
105
106
                if item == 'Homepage':
                    found_homepage = True
                self.new_result(ControlField, field=item,
                                value=dsc[item])
107

108
109
110
111
        if found_homepage:
            test_result = self.new_test_result(
                severity=constants.PLUGIN_SEVERITY_INFO)
            test_result.homepage = True
Jonny Lamb's avatar
Jonny Lamb committed
112

113
114
            if len(self.results) > 1:
                test_result.vcs = True
115

116
plugin = ControlFieldsPlugin
117
118
119
120
models = [
    ControlfieldTest,
    ControlField,
    ]