~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/adapters/copypolicy.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright 2011 Canonical Ltd.  This software is licensed under the
 
2
# GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
"""Copy Policy Classes.
 
5
 
 
6
The classes contain various policies about copying packages that can be
 
7
decided at runtime, such as whether to auto-accept a package or not.
 
8
"""
 
9
 
 
10
__metaclass__ = type
 
11
 
 
12
__all__ = [
 
13
    "InsecureCopyPolicy",
 
14
    ]
 
15
 
 
16
 
 
17
from lp.registry.interfaces.pocket import PackagePublishingPocket
 
18
from lp.registry.interfaces.series import SeriesStatus
 
19
 
 
20
 
 
21
class BaseCopyPolicy:
 
22
    """Encapsulation of the policies for copying a package in Launchpad."""
 
23
 
 
24
    def autoApprove(self, packageupload):
 
25
        """Decide if the packageupload can be approved automatically or
 
26
        should be held in the queue.
 
27
        """
 
28
        raise AssertionError("Subclass must provide autoApprove")
 
29
 
 
30
    def autoApproveNew(self, packageupload):
 
31
        """Decide if a previously unknown package is approved automatically
 
32
        or should be held in the queue.
 
33
        """
 
34
        raise AssertionError("Subclass must provide autoApproveNew")
 
35
 
 
36
 
 
37
class InsecureCopyPolicy(BaseCopyPolicy):
 
38
    """A policy for copying from insecure sources."""
 
39
 
 
40
    def autoApproveNew(self, packageupload):
 
41
        if packageupload.isPPA():
 
42
            return True
 
43
        return False
 
44
 
 
45
    def autoApprove(self, packageupload):
 
46
        if packageupload.isPPA():
 
47
            return True
 
48
 
 
49
        # This check is orthogonal to the
 
50
        # IDistroSeries.canUploadToPocket check.
 
51
        if (packageupload.pocket == PackagePublishingPocket.RELEASE and
 
52
            packageupload.distroseries.status != SeriesStatus.FROZEN):
 
53
            return True
 
54
 
 
55
        return False