~sylvain-pineau/checkbox-core/bug983035

« back to all changes in this revision

Viewing changes to checkbox/journal/score.py

  • Committer: Marc Tardif
  • Date: 2012-04-12 18:58:39 UTC
  • Revision ID: marc.tardif@canonical.com-20120412185839-5lxr7972gntlpl2z
Added journal component.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright (c) 2012 Canonical
 
3
#
 
4
# This file is part of Checkbox.
 
5
#
 
6
# Storm is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU Lesser General Public License as
 
8
# published by the Free Software Foundation; either version 2.1 of
 
9
# the License, or (at your option) any later version.
 
10
#
 
11
# Storm is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU Lesser General Public License for more details.
 
15
#
 
16
# You should have received a copy of the GNU Lesser General Public License
 
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
#
 
19
__metaclass__ = type
 
20
 
 
21
__all__ = [
 
22
    "Score",
 
23
    "ScoreFactor",
 
24
    "ScoreThresh",
 
25
    ]
 
26
 
 
27
from checkbox.lib.enum import Enum
 
28
 
 
29
 
 
30
# Score factor values
 
31
ScoreFactor = Enum(
 
32
    ("UNIQ_MATCH", 100),
 
33
    ("CTIME", 1),
 
34
    ("INODE", 2),
 
35
    ("SAME_SIZE", 2),
 
36
    ("GROWN", 1),
 
37
    ("SHRUNK", -5),
 
38
    )
 
39
 
 
40
# Values for min scores
 
41
ScoreThresh = Enum(
 
42
    ("RESTORE", 10),
 
43
    ("FWSEARCH", 4),
 
44
    ("NONROT", 3),
 
45
    ("MIN_MATCH", 1),
 
46
    )
 
47
 
 
48
 
 
49
class Score:
 
50
 
 
51
    __slots__ = (
 
52
        "value",
 
53
        )
 
54
 
 
55
    def __init__(self, value=None):
 
56
        self.value = value
 
57
 
 
58
    def __cmp__(self, other):
 
59
        if not isinstance(other, Score):
 
60
            other = Score(other)
 
61
 
 
62
        if not self:
 
63
            if not other:
 
64
                return 0
 
65
            else:
 
66
                return -1
 
67
 
 
68
        elif not other:
 
69
            return 1
 
70
 
 
71
        else:
 
72
            return cmp(self.value, other.value)
 
73
 
 
74
    def __lt__(self, other):
 
75
        return self.__cmp__(other) < 0
 
76
 
 
77
    def __le__(self, other):
 
78
        return self.__cmp__(other) <= 0
 
79
 
 
80
    def __gt__(self, other):
 
81
        return self.__cmp__(other) > 0
 
82
 
 
83
    def __ge__(self, other):
 
84
        return self.__cmp__(other) >= 0
 
85
 
 
86
    def __eq__(self, other):
 
87
        return self.__cmp__(other) == 0
 
88
 
 
89
    def __ne__(self, other):
 
90
        return self.__cmp__(other) != 0
 
91
 
 
92
    def __nonzero__(self):
 
93
        return self.value is not None