~launchpad-pqm/launchpad/devel

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
# Copyright 2009 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Implementation of `ISuiteSourcePackage`."""

__metaclass__ = type
__all__ = [
    'SuiteSourcePackage',
    ]

from zope.interface import implements

from lp.registry.interfaces.suitesourcepackage import ISuiteSourcePackage


class SuiteSourcePackage:
    """Implementation of `ISuiteSourcePackage`."""

    implements(ISuiteSourcePackage)

    def __init__(self, distroseries, pocket, sourcepackagename):
        self.distroseries = distroseries
        self.pocket = pocket
        self.sourcepackagename = sourcepackagename

    def __eq__(self, other):
        try:
            other = ISuiteSourcePackage(other)
        except TypeError:
            return NotImplemented
        return (
            self.sourcepackage == other.sourcepackage
            and self.pocket == other.pocket)

    def __ne__(self, other):
        return not (self == other)

    def __repr__(self):
        return '<%s %s>' % (self.__class__.__name__, self.path)

    @property
    def displayname(self):
        """See `ISuiteSourcePackage`."""
        return "%s in %s" % (self.sourcepackagename.name, self.suite)

    @property
    def distribution(self):
        """See `ISuiteSourcePackage`."""
        return self.distroseries.distribution

    @property
    def path(self):
        """See `ISuiteSourcePackage`."""
        return '/'.join([
            self.distribution.name,
            self.suite,
            self.sourcepackagename.name])

    @property
    def sourcepackage(self):
        """See `ISuiteSourcePackage`."""
        return self.distroseries.getSourcePackage(self.sourcepackagename)

    @property
    def suite(self):
        """See `ISuiteSourcePackage`."""
        return self.distroseries.getSuite(self.pocket)