5
5
objects for the distribution.
11
IDistribution allows us to retrieve packages by name, returning a tuple
12
of Source/BinaryPackageName instances published within this
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
12
>>> ubuntu = getUtility(IDistributionSet).getByName('ubuntu')
13
>>> debian = getUtility(IDistributionSet).getByName('debian')
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
21
>>> distroset = getUtility(IDistributionSet)
22
>>> gentoo = distroset.getByName("gentoo")
23
>>> ubuntu = distroset.get(1)
25
>>> source_name, bin_name = ubuntu.guessPackageNames('pmount')
26
>>> ISourcePackageName.providedBy(source_name)
29
>>> IBinaryPackageName.providedBy(bin_name)
32
>>> source_name.name, bin_name.name
33
(u'pmount', u'pmount')
35
Prevents wrong usage by and assertion error:
37
>>> name_tuple = ubuntu.guessPackageNames(ubuntu)
38
Traceback (most recent call last):
40
AssertionError: Expected string. Got: <Distribution ...>
42
Raises NotFoundError for following conditions:
44
>>> name_tuple = ubuntu.guessPackageNames('@#$')
45
Traceback (most recent call last):
47
NotFoundError: 'Invalid package name: @#$'
49
>>> name_tuple = ubuntu.guessPackageNames('zeca')
50
Traceback (most recent call last):
52
NotFoundError: 'Unknown package: zeca'
54
>>> name_tuple = ubuntu.guessPackageNames('1234')
55
Traceback (most recent call last):
57
NotFoundError: 'Unknown package: 1234'
59
Packages only published in PPAs will not be found in the Ubuntu archive.
60
Here, 'at' is published in mark's PPA only:
18
62
>>> from lp.soyuz.tests.ppa import publishToPPA
63
>>> ubuntutest = distroset.getByName("ubuntutest")
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):
74
NotFoundError: u'Package at not published in ubuntutest'
76
It also raises NotFoundError on distributions with no series:
78
>>> source_name, bin_name = gentoo.guessPackageNames('pmount')
79
Traceback (most recent call last):
81
NotFoundError: u"Gentoo has no series; 'pmount' was never published in it"
83
A distroseries can only be created by the distro owner or the admin
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):
91
Unauthorized: (<Distribution...>, 'newSeries', 'launchpad.Moderate')
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)
100
# Reverting the logged in user.
104
Even if we add a series to Gentoo, no packages have ever been published
105
in it, and therefore guessPackageNames will still fail:
107
>>> source_name, bin_name = gentoo.guessPackageNames('pmount')
108
Traceback (most recent call last):
110
NotFoundError: u'Package pmount not published in Gentoo'
112
It will find packages that are at the PENDING publishing state in
113
addition to PUBLISHED ones:
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)
125
>>> (source, binary) = ubuntu.guessPackageNames("pendingpackage")
126
>>> print source.name
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:
132
>>> from lp.app.interfaces.launchpad import ILaunchpadCelebrities
133
>>> debian = getUtility(ILaunchpadCelebrities).debian
134
>>> source_name, bin_name = debian.guessPackageNames('alsa-utils')
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.
145
First, we need a function to help testing:
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)
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:
156
Both iceweasel and mozilla-firefox source packages produce mozilla-
157
firefox binary packages.
159
>>> print_guessed_names('mozilla-firefox')
160
source: u'mozilla-firefox'
161
binary: u'mozilla-firefox'
163
>>> print_guessed_names('iceweasel')
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
172
>>> print_guessed_names('linux-2.6.12')
173
source: u'linux-source-2.6.15'
174
binary: u'linux-2.6.12'
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'.
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 ...>]
193
>>> print_guessed_names('linux-2.6.12')
195
binary: u'linux-2.6.12'
28
198
Handling Personal Package Archives