~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/doc/distribution.txt

  • Committer: William Grant
  • Date: 2011-06-07 05:02:53 UTC
  • mfrom: (7675.1045.468 db-devel)
  • mto: This revision was merged to the branch mainline in revision 13167.
  • Revision ID: william.grant@canonical.com-20110607050253-dg51108zbt44ecoc
Re-merge db-stable at r10651 (no DB changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
objects for the distribution.
6
6
 
7
7
 
 
8
Guessing package names
 
9
----------------------
 
10
 
 
11
IDistribution allows us to retrieve packages by name, returning a tuple
 
12
of Source/BinaryPackageName instances published within this
 
13
distribution:
 
14
 
8
15
    >>> from lp.registry.interfaces.distribution import IDistributionSet
9
16
    >>> from lp.registry.interfaces.pocket import PackagePublishingPocket
 
17
    >>> from lp.registry.interfaces.sourcepackagename import ISourcePackageName
10
18
    >>> from lp.soyuz.enums import PackagePublishingStatus
11
 
 
12
 
    >>> ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
13
 
    >>> debian = getUtility(IDistributionSet).getByName('debian')
14
 
 
15
 
(Create some data that is depended upon by later tests. It was part of a
16
 
test "narrative" that was converted to unit tests.... for obvious reasons.)
 
19
    >>> from lp.soyuz.interfaces.binarypackagename import IBinaryPackageName
 
20
 
 
21
    >>> distroset = getUtility(IDistributionSet)
 
22
    >>> gentoo = distroset.getByName("gentoo")
 
23
    >>> ubuntu = distroset.get(1)
 
24
 
 
25
    >>> source_name, bin_name = ubuntu.guessPackageNames('pmount')
 
26
    >>> ISourcePackageName.providedBy(source_name)
 
27
    True
 
28
 
 
29
    >>> IBinaryPackageName.providedBy(bin_name)
 
30
    True
 
31
 
 
32
    >>> source_name.name, bin_name.name
 
33
    (u'pmount', u'pmount')
 
34
 
 
35
Prevents wrong usage by and assertion error:
 
36
 
 
37
    >>> name_tuple = ubuntu.guessPackageNames(ubuntu)
 
38
    Traceback (most recent call last):
 
39
    ...
 
40
    AssertionError: Expected string. Got: <Distribution ...>
 
41
 
 
42
Raises NotFoundError for following conditions:
 
43
 
 
44
    >>> name_tuple = ubuntu.guessPackageNames('@#$')
 
45
    Traceback (most recent call last):
 
46
    ...
 
47
    NotFoundError: 'Invalid package name: @#$'
 
48
 
 
49
    >>> name_tuple = ubuntu.guessPackageNames('zeca')
 
50
    Traceback (most recent call last):
 
51
    ...
 
52
    NotFoundError: 'Unknown package: zeca'
 
53
 
 
54
    >>> name_tuple = ubuntu.guessPackageNames('1234')
 
55
    Traceback (most recent call last):
 
56
    ...
 
57
    NotFoundError: 'Unknown package: 1234'
 
58
 
 
59
Packages only published in PPAs will not be found in the Ubuntu archive.
 
60
Here, 'at' is published in mark's PPA only:
17
61
 
18
62
    >>> from lp.soyuz.tests.ppa import publishToPPA
 
63
    >>> ubuntutest = distroset.getByName("ubuntutest")
19
64
    >>> publishToPPA(
20
65
    ...     person_name='cprov',
21
66
    ...     sourcepackage_name='at', sourcepackage_version='0.00',
23
68
    ...     distribution_name='ubuntutest',
24
69
    ...     distroseries_name='hoary-test',
25
70
    ...     publishing_status=PackagePublishingStatus.PUBLISHED)
 
71
    >>> name_tuple = ubuntutest.guessPackageNames('at')
 
72
    Traceback (most recent call last):
 
73
    ...
 
74
    NotFoundError: u'Package at not published in ubuntutest'
 
75
 
 
76
It also raises NotFoundError on distributions with no series:
 
77
 
 
78
    >>> source_name, bin_name = gentoo.guessPackageNames('pmount')
 
79
    Traceback (most recent call last):
 
80
    ...
 
81
    NotFoundError: u"Gentoo has no series; 'pmount' was never published in it"
 
82
 
 
83
A distroseries can only be created by the distro owner or the admin
 
84
team.
 
85
 
 
86
    >>> gentoo.newSeries('gentoo-two', 'Gentoo Two',
 
87
    ...                  'Gentoo Two Dot Oh', 'Gentoo 2', 'G2',
 
88
    ...                  '2.0', None, gentoo.owner)
 
89
    Traceback (most recent call last):
 
90
    ...
 
91
    Unauthorized: (<Distribution...>, 'newSeries', 'launchpad.Moderate')
 
92
 
 
93
    >>> login('mark@example.com')
 
94
    >>> from lp.registry.interfaces.distroseries import IDistroSeriesSet
 
95
    >>> distroseriesset = getUtility(IDistroSeriesSet)
 
96
    >>> gentoo_two = gentoo.newSeries('gentoo-two', 'Gentoo Two',
 
97
    ...                               'Gentoo Two Dot Oh', 'Gentoo 2', 'G2',
 
98
    ...                               '2.0', None, gentoo.owner)
 
99
 
 
100
    # Reverting the logged in user.
 
101
 
 
102
    >>> login(ANONYMOUS)
 
103
 
 
104
Even if we add a series to Gentoo, no packages have ever been published
 
105
in it, and therefore guessPackageNames will still fail:
 
106
 
 
107
    >>> source_name, bin_name = gentoo.guessPackageNames('pmount')
 
108
    Traceback (most recent call last):
 
109
    ...
 
110
    NotFoundError: u'Package pmount not published in Gentoo'
 
111
 
 
112
It will find packages that are at the PENDING publishing state in
 
113
addition to PUBLISHED ones:
 
114
 
 
115
    >>> login("admin@canonical.com")
 
116
    >>> from lp.soyuz.tests.test_publishing import (
 
117
    ...     SoyuzTestPublisher)
 
118
    >>> test_publisher = SoyuzTestPublisher()
 
119
    >>> ignore = test_publisher.setUpDefaultDistroSeries(
 
120
    ...     ubuntu['breezy-autotest'])
 
121
    >>> ignore = test_publisher.getPubSource(
 
122
    ...     sourcename="pendingpackage",
 
123
    ...     status=PackagePublishingStatus.PENDING)
 
124
    >>> login(ANONYMOUS)
 
125
    >>> (source, binary) = ubuntu.guessPackageNames("pendingpackage")
 
126
    >>> print source.name
 
127
    pendingpackage
 
128
 
 
129
It also works if we look for a package name which is the name of both
 
130
binary and source packages but for which only the source is published:
 
131
 
 
132
    >>> from lp.app.interfaces.launchpad import ILaunchpadCelebrities
 
133
    >>> debian = getUtility(ILaunchpadCelebrities).debian
 
134
    >>> source_name, bin_name = debian.guessPackageNames('alsa-utils')
 
135
    >>> print bin_name
 
136
    None
 
137
 
 
138
    >>> source_name.name
 
139
    u'alsa-utils'
 
140
 
 
141
It's possible for a binary package to have the same name as a source
 
142
package, yet not be derived from that source package. In this case, we
 
143
want to prefer the source package with that name.
 
144
 
 
145
First, we need a function to help testing:
 
146
 
 
147
    >>> def print_guessed_names(package_name):
 
148
    ...     source, binary = ubuntu.guessPackageNames(package_name)
 
149
    ...     print "source: %r" % source.name
 
150
    ...     print "binary: %r" % getattr(binary, 'name', None)
 
151
 
 
152
Note that source packages can produces lots of differently named binary
 
153
packages so only return a match if it's got the same name as the source
 
154
package rather than returning an arbitrary binary package:
 
155
 
 
156
Both iceweasel and mozilla-firefox source packages produce mozilla-
 
157
firefox binary packages.
 
158
 
 
159
    >>> print_guessed_names('mozilla-firefox')
 
160
    source: u'mozilla-firefox'
 
161
    binary: u'mozilla-firefox'
 
162
 
 
163
    >>> print_guessed_names('iceweasel')
 
164
    source: u'iceweasel'
 
165
    binary: None
 
166
 
 
167
If we don't get a hit on the source package we search binary packages.
 
168
Because there is a many to one relationship from binary packages to
 
169
source packages we can always return a source package name even if it
 
170
differs:
 
171
 
 
172
    >>> print_guessed_names('linux-2.6.12')
 
173
    source: u'linux-source-2.6.15'
 
174
    binary: u'linux-2.6.12'
 
175
 
 
176
If there are multiple matching binary packages, the source of the latest
 
177
publication is used. If we create a new 'linux' source with a 'linux-2.6.12'
 
178
binary, 'linux' will be returned instead of 'linux-source-2.6.15'.
 
179
 
 
180
    >>> from lp.soyuz.tests.test_publishing import (
 
181
    ...     SoyuzTestPublisher)
 
182
    >>> test_publisher = SoyuzTestPublisher()
 
183
    >>> hoary = test_publisher.setUpDefaultDistroSeries(
 
184
    ...     ubuntu.getSeries('hoary'))
 
185
    >>> fake_chroot = test_publisher.addMockFile('fake_chroot.tar.gz')
 
186
    >>> unused = hoary['i386'].addOrUpdateChroot(fake_chroot)
 
187
    >>> login('admin@canonical.com')
 
188
    >>> test_publisher.getPubBinaries(
 
189
    ...     'linux-2.6.12', architecturespecific=True)
 
190
    [<BinaryPackagePublishingHistory ...>]
 
191
    >>> login(ANONYMOUS)
 
192
 
 
193
    >>> print_guessed_names('linux-2.6.12')
 
194
    source: u'linux'
 
195
    binary: u'linux-2.6.12'
26
196
 
27
197
 
28
198
Handling Personal Package Archives