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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
= ILaunchpadContainer =
Some of our content classes may be used as the context of an OAuth
token so that any application using that token will have access only to
things in the scope of that context. The classes that can be used as
the context of an OAuth token must have ILaunchpadContainer adapters, so
that we have an easy way of finding whether or not any given object is
within the scope of a token's context and grant or deny access to it.
>>> from lp.services.webapp.interfaces import ILaunchpadContainer
>>> from lp.services.webapp.testing import verifyObject
>>> from lp.registry.interfaces.product import IProductSet
>>> from lp.registry.interfaces.distribution import (
... IDistributionSet)
>>> firefox = getUtility(IProductSet)['firefox']
>>> mozilla = firefox.project
>>> ubuntu = getUtility(IDistributionSet)['ubuntu']
>>> evolution = ubuntu.getSourcePackage('evolution')
The ILaunchpadContainer defines only the isWithin(context) method, which
returns True if this context is the given one or is within it.
A product is within itself or its project.
>>> ILaunchpadContainer(firefox).isWithin(firefox)
True
>>> ILaunchpadContainer(firefox).isWithin(mozilla)
True
>>> ILaunchpadContainer(firefox).isWithin(ubuntu)
False
>>> verifyObject(ILaunchpadContainer, ILaunchpadContainer(firefox))
True
A project is only within itself.
>>> ILaunchpadContainer(mozilla).isWithin(mozilla)
True
>>> ILaunchpadContainer(mozilla).isWithin(firefox)
False
>>> ILaunchpadContainer(mozilla).isWithin(ubuntu)
False
>>> verifyObject(ILaunchpadContainer, ILaunchpadContainer(mozilla))
True
A distribution is only within itself.
>>> ILaunchpadContainer(ubuntu).isWithin(ubuntu)
True
>>> ILaunchpadContainer(ubuntu).isWithin(mozilla)
False
>>> ILaunchpadContainer(ubuntu).isWithin(firefox)
False
>>> verifyObject(ILaunchpadContainer, ILaunchpadContainer(ubuntu))
True
A distribution source package is within itself or its distribution.
>>> ILaunchpadContainer(evolution).isWithin(evolution)
True
>>> ILaunchpadContainer(evolution).isWithin(ubuntu)
True
>>> ILaunchpadContainer(evolution).isWithin(firefox)
False
>>> ILaunchpadContainer(evolution).isWithin(mozilla)
False
>>> verifyObject(ILaunchpadContainer, ILaunchpadContainer(evolution))
True
An ILaunchpadContainer will never be within something which doesn't
provide ILaunchpadContainer as well.
>>> from lp.registry.interfaces.person import IPersonSet
>>> salgado = getUtility(IPersonSet).getByName('salgado')
>>> ILaunchpadContainer(firefox).isWithin(salgado)
False
== Bugs ==
Bugs are associated to our pillars through their bug tasks, so a bug is
said to be within any of its bugtasks' targets.
>>> from lp.bugs.interfaces.bug import IBugSet
>>> from operator import attrgetter
>>> bug_1 = getUtility(IBugSet).get(1)
>>> bugtasks = bug_1.bugtasks
>>> targets = [task.target for task in bug_1.bugtasks]
>>> [(target.title, ILaunchpadContainer(bug_1).isWithin(target))
... for target in sorted(targets, key=attrgetter('title'))]
[(u'Mozilla Firefox', True),
(...mozilla-firefox... package in Debian', True),
(...mozilla-firefox... package in Ubuntu', True)]
But it's not within anything other than its tasks' targets.
>>> evolution in targets
False
>>> ILaunchpadContainer(bug_1).isWithin(evolution)
False
== Branches ==
A branch is within its product, in case it is associated with one.
>>> sample_person = getUtility(IPersonSet).getByName('name12')
>>> from lp.code.interfaces.branchnamespace import (
... get_branch_namespace)
>>> firefox_main = get_branch_namespace(
... sample_person, product=firefox).getByName('main')
>>> ILaunchpadContainer(firefox_main).isWithin(firefox)
True
>>> ILaunchpadContainer(firefox_main).isWithin(mozilla)
True
If the branch is not associated with a product, then it's not within
anything.
>>> junk= get_branch_namespace(sample_person).getByName('junk.dev')
>>> print junk.product
None
>>> ILaunchpadContainer(junk).isWithin(firefox)
False
|