#!/usr/bin/python
#
# lp-binary-url -- finds the binary package URL from Launchpad
#
# Copyright (C) 2010 Philippe Gauthier <philippe.gauthier@deuxpi.ca>
#
# Based un pull-lp-source
# Copyright (C) 2008 Iain Lane <iain@orangesquash.org.uk>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# See file /usr/share/common-licenses/GPL for more details.
import commands
import os
import sys
try:
from ubuntutools.lp.lpapicache import Distribution, Launchpad
from ubuntutools.lp.udtexceptions import (SeriesNotFoundException,
PackageNotFoundException, PocketDoesNotExistError)
from ubuntutools.misc import split_release_pocket, host_architecture
except ImportError:
print "E: Please install the 'ubuntu-dev-tools' package and rerun this" \
" script again."
sys.exit(1)
if len(sys.argv) < 2:
print "Usage: %s package [release] [arch]" % sys.argv[0]
sys.exit(1)
Launchpad.login_anonymously()
package = sys.argv[1].lower()
source = commands.getoutput("apt-cache show %s | grep Source:" % package)
if source.startswith("Source:"):
source = source.split()[1]
print "W: Source package for '%s' is '%s'." % (package, source)
package = source
if len(sys.argv) >= 3: # Custom distribution specified.
release = sys.argv[2].lower()
else:
release = os.getenv('DIST') or Distribution('ubuntu').getDevelopmentSeries().name
if len(sys.argv) >= 4:
arch = sys.argv[3]
else:
arch = host_architecture()
try:
(release, pocket) = split_release_pocket(release)
except PocketDoesNotExistError, e:
print 'E: %s' % e
sys.exit(1)
try:
spph = Distribution('ubuntu').getArchive().getSourcePackage(package, release, pocket)
except (SeriesNotFoundException, PackageNotFoundException), e:
print 'E: %s' % e
sys.exit(1)
for url in spph.binaryFileUrls():
if url.endswith("_%s.deb" % arch):
print url