Rewrite 404main using python-apt. Note that this requires python-apt

0.7.9, not in jaunty.
This commit is contained in:
Colin Watson 2009-06-09 11:00:00 +01:00
parent f01cebdaea
commit 6730937ea3
4 changed files with 67 additions and 29 deletions

88
404main
View File

@ -3,6 +3,7 @@
# #
# Copyright 2006-2007 (C) Pete Savage <petesavage@ubuntu.com> # Copyright 2006-2007 (C) Pete Savage <petesavage@ubuntu.com>
# Copyright 2007 (C) Siegfried-A. Gevatter <rainct@ubuntu.com> # Copyright 2007 (C) Siegfried-A. Gevatter <rainct@ubuntu.com>
# Copyright 2009 (C) Canonical Ltd. (by Colin Watson <cjwatson@ubuntu.com>)
# #
# ################################################################## # ##################################################################
# #
@ -26,49 +27,82 @@
import subprocess import subprocess
import sys import sys
def process_deps(deps): import apt_pkg
import apt
def process_deps(cache, deps):
"""Takes a list of (build) dependencies and processes it.""" """Takes a list of (build) dependencies and processes it."""
for package in [ package.split('|')[0] for package in deps ]: for basedep in [d.or_dependencies[0] for d in deps]:
if not packages.has_key(basedep.name) and basedep.name != '':
# Cut package name (from something like "name ( >= version)")
name = package.split(' ')[0]
if not packages.has_key(name) and name != '':
# Check the (build) dependencies recursively # Check the (build) dependencies recursively
find_main(name) find_main(cache, basedep.name)
def find_main(pack): def get_package_version(cache, distro, pack):
if pack not in cache:
return None
for version in (cache[pack].candidate, cache[pack].installed):
if not version:
continue
for origin in version.origins:
if origin.archive == distro:
return version
return None
# Cache::CompTypeDeb isn't exposed via python-apt
def comp_type_deb(op):
ops = ("", "<=", ">=", "<<", ">>", "=", "!=")
if (op & 15) < 7:
return ops[op & 15]
return ""
def find_main(cache, pack):
"""Searches the dependencies and build dependencies of a package recursively """Searches the dependencies and build dependencies of a package recursively
to determine if they are all in the 'main' component or not.""" to determine if they are all in the 'main' component or not."""
global packages global packages
if pack in packages:
return
# Retrieve information about the package # Retrieve information about the package
out = subprocess.Popen('apt-cache madison ' + pack + ' | grep ' + distro + ' | grep -m 1 Packages', shell=True, stdout=subprocess.PIPE).stdout.read() version = get_package_version(cache, distro, pack)
if out.find("/main") != -1: if not version:
packages[pack] = False
return
elif [origin for origin in version.origins if origin.component == 'main']:
packages[pack] = True packages[pack] = True
return 1 return
else: else:
if not packages.has_key(pack): if not packages.has_key(pack):
packages[pack] = False packages[pack] = False
# Retrive package dependencies # Retrieve package dependencies
deps = subprocess.Popen('apt-cache show ' + pack + ' | grep -m 1 ^Depends', shell=True, stdout=subprocess.PIPE).stdout.read().split('\n')[0].replace('Depends: ', '').split(', ') process_deps(cache, version.dependencies)
process_deps(deps) # Retrieve package build dependencies. There's no handy
# attribute on version for this, so unfortunately we have to
# Retrieve package build dependencies # do a lot of messing about with apt.
deps1 = subprocess.Popen('apt-cache showsrc ' + pack + ' | grep -m 1 ^Build-Depends', shell=True, stdout=subprocess.PIPE).stdout.readlines()
deps = [] deps = []
src_records = apt_pkg.GetPkgSrcRecords()
got_src = False
while src_records.Lookup(version.source_name):
if pack in src_records.Binaries:
got_src = True
break
if got_src:
base_deps = []
for (name, ver, op, deptype) in src_records.BuildDepends:
base_deps.append(apt.package.BaseDependency(name, comp_type_deb(op), ver, False))
if (op & 16) != 16:
deps.append(apt.package.Dependency(base_deps))
base_deps = []
for builddep in deps1: process_deps(cache, deps)
if builddep.startswith('Build-Depends'):
deps += builddep.strip('\n').replace('Build-Depends: ', '').replace('Build-Depends-Indep: ', '').split(', ')
process_deps(deps)
def main(): def main():
@ -80,22 +114,24 @@ def main():
print 'Usage: %s <package name> [<distribution>]' % sys.argv[0] print 'Usage: %s <package name> [<distribution>]' % sys.argv[0]
sys.exit(1) sys.exit(1)
cache = apt.cache.Cache()
if len(sys.argv) == 3 and sys.argv[2]: if len(sys.argv) == 3 and sys.argv[2]:
distro = sys.argv[2] distro = sys.argv[2]
if not subprocess.Popen('apt-cache madison bash | grep ' + distro, shell=True, stdout=subprocess.PIPE).stdout.read(): if not get_package_version(cache, distro, 'bash'):
print '«%s» is not a valid distribution.' % distro print '«%s» is not a valid distribution.' % distro
print 'Remember that for 404main to work with a certain distribution it must be in your /etc/apt/sources.list file.' print 'Remember that for 404main to work with a certain distribution it must be in your /etc/apt/sources.list file.'
sys.exit(1) sys.exit(1)
else: else:
distro = subprocess.Popen('lsb_release -cs', shell=True, stdout=subprocess.PIPE).stdout.read().strip('\n') distro = subprocess.Popen('lsb_release -cs', shell=True, stdout=subprocess.PIPE).stdout.read().strip('\n')
if not subprocess.Popen('apt-cache madison ' + sys.argv[1] + ' | grep ' + distro, shell=True, stdout=subprocess.PIPE).stdout.read(): if not get_package_version(cache, distro, sys.argv[1]):
print 'Can\'t find package «%s» in distribution «%s».' % (sys.argv[1], distro) print 'Can\'t find package «%s» in distribution «%s».' % (sys.argv[1], distro)
sys.exit(1) sys.exit(1)
print 'Checking package «%s» in distribution «%s»...' % (sys.argv[1], distro) print 'Checking package «%s» in distribution «%s»...' % (sys.argv[1], distro)
find_main(sys.argv[1]) find_main(cache, sys.argv[1])
# True if everything checked until the point is in main # True if everything checked until the point is in main
all_in_main = True all_in_main = True

2
TODO
View File

@ -6,7 +6,5 @@ TODO for the ubuntu-dev-tools package
- Create missing and improve existing manpages (for all commands). - Create missing and improve existing manpages (for all commands).
- Modify 404main to use the more robust python-apt module.
- Ask all authors who have used GPL if they are happy with using "or any later" - Ask all authors who have used GPL if they are happy with using "or any later"
versions of the license. versions of the license.

4
debian/changelog vendored
View File

@ -35,6 +35,10 @@ ubuntu-dev-tools (0.75) UNRELEASED; urgency=low
- Fix permissions warning message and do not mention teams as we check on - Fix permissions warning message and do not mention teams as we check on
a per package basis. a per package basis.
[ Colin Watson ]
* Rewrite 404main using python-apt. Note that this requires python-apt
0.7.9, not in jaunty.
-- Michael Bienia <geser@ubuntu.com> Tue, 09 Jun 2009 10:31:03 +0200 -- Michael Bienia <geser@ubuntu.com> Tue, 09 Jun 2009 10:31:03 +0200
ubuntu-dev-tools (0.74) karmic; urgency=low ubuntu-dev-tools (0.74) karmic; urgency=low

2
debian/control vendored
View File

@ -14,7 +14,7 @@ Package: ubuntu-dev-tools
Architecture: all Architecture: all
Depends: ${python:Depends}, ${misc:Depends}, binutils, devscripts, sudo, Depends: ${python:Depends}, ${misc:Depends}, binutils, devscripts, sudo,
python-debian, python-launchpad-bugs (>= 0.2.25), python-launchpadlib, python-debian, python-launchpad-bugs (>= 0.2.25), python-launchpadlib,
dctrl-tools, lsb-release, diffstat, dpkg-dev dctrl-tools, lsb-release, diffstat, dpkg-dev, python-apt (>= 0.7.9)
Recommends: bzr, pbuilder | cowdancer | sbuild, reportbug (>= 3.39ubuntu1), Recommends: bzr, pbuilder | cowdancer | sbuild, reportbug (>= 3.39ubuntu1),
ca-certificates, debootstrap, genisoimage, perl-modules, libwww-perl ca-certificates, debootstrap, genisoimage, perl-modules, libwww-perl
Conflicts: devscripts (<< 2.10.7ubuntu5) Conflicts: devscripts (<< 2.10.7ubuntu5)