Bug#523998: python-apt: Package class should have a get_version method
On Tue, Apr 14, 2009 at 09:22:26AM +0200, Sebastian Heinlein wrote:
> Package: python-apt
> Version: 0.7.7.1+nmu1
> Severity: wishlist
> Tags: patch
>
> The Package class should provide a nice way to get a corresponding Version
> instance by specifing the version string.
>
> E.g.: Package.get_version("242-1")
We could also support Package.versions["242-1"], by providing a class VersionList
with a special __getitem__()
The code listed below would allow us to do things like::
'242-1' in Package.versions
Package.versions['242-1']
While still allowing stuff like::
Package.versions[0]
This gives us a bit more options, and seems a bit more natural; although we would
have a class which represents a sequence and parts of a mapping.
Else we may get a request: please add has_version() to Package or similar.
What do you think?
-- (Pseudo?) Code:
class VersionList(list):
def __getitem__(self, item):
if not isinstance(item, basestr):
return list.__getitem__(self, item)
for ver in self:
if ver.version == item:
return ver
def __contains__(self, item):
for ver in self:
if ver.version == item or ver == item:
return True
--
Julian Andres Klode - Free Software Developer
Debian Developer - Contributing Member of SPI
Ubuntu Member - Fellow of FSFE
Website: http://jak-linux.org/ XMPP: juliank@jabber.org
Debian: http://www.debian.org/ SPI: http://www.spi-inc.org/
Ubuntu: http://www.ubuntu.com/ FSFE: http://www.fsfe.org/
Reply to: