2007-03-27 21:59:13 +10:00
|
|
|
#!/usr/bin/python
|
2007-11-07 20:05:37 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-08-04 13:52:30 +02:00
|
|
|
#
|
2007-11-30 17:55:33 +01:00
|
|
|
# Copyright 2006-2007 (C) Pete Savage <petesavage@ubuntu.com>
|
2008-01-17 19:43:26 +01:00
|
|
|
# Copyright 2007 (C) Siegfried-A. Gevatter <rainct@ubuntu.com>
|
2009-06-09 11:00:00 +01:00
|
|
|
# Copyright 2009 (C) Canonical Ltd. (by Colin Watson <cjwatson@ubuntu.com>)
|
2008-08-11 20:06:35 +02:00
|
|
|
#
|
|
|
|
# ##################################################################
|
|
|
|
#
|
|
|
|
# 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 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2010-12-03 00:06:43 +01:00
|
|
|
#
|
2008-08-11 20:06:35 +02:00
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# ##################################################################
|
2007-11-24 01:04:24 +01:00
|
|
|
#
|
2007-11-30 17:55:33 +01:00
|
|
|
# This script is used to check if a package and all its build
|
|
|
|
# dependencies are in main or not.
|
2007-03-27 21:59:13 +10:00
|
|
|
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
2009-06-09 11:00:00 +01:00
|
|
|
import apt_pkg
|
|
|
|
import apt
|
|
|
|
|
|
|
|
def process_deps(cache, deps):
|
2007-11-24 01:04:24 +01:00
|
|
|
"""Takes a list of (build) dependencies and processes it."""
|
|
|
|
|
2009-06-09 11:00:00 +01:00
|
|
|
for basedep in [d.or_dependencies[0] for d in deps]:
|
|
|
|
if not packages.has_key(basedep.name) and basedep.name != '':
|
2007-11-24 01:04:24 +01:00
|
|
|
# Check the (build) dependencies recursively
|
2009-06-09 11:00:00 +01:00
|
|
|
find_main(cache, basedep.name)
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2007-11-24 01:04:24 +01:00
|
|
|
|
2009-06-09 11:00:00 +01:00
|
|
|
# Cache::CompTypeDeb isn't exposed via python-apt
|
|
|
|
def comp_type_deb(op):
|
|
|
|
ops = ("", "<=", ">=", "<<", ">>", "=", "!=")
|
|
|
|
if (op & 15) < 7:
|
|
|
|
return ops[op & 15]
|
|
|
|
return ""
|
2007-11-24 01:04:24 +01:00
|
|
|
|
2009-06-09 11:00:00 +01:00
|
|
|
|
|
|
|
def find_main(cache, pack):
|
2007-11-24 01:04:24 +01:00
|
|
|
"""Searches the dependencies and build dependencies of a package recursively
|
|
|
|
to determine if they are all in the 'main' component or not."""
|
|
|
|
|
2007-03-27 21:59:13 +10:00
|
|
|
global packages
|
2007-11-24 01:04:24 +01:00
|
|
|
|
2009-06-09 11:00:00 +01:00
|
|
|
if pack in packages:
|
|
|
|
return
|
|
|
|
|
2007-11-24 01:04:24 +01:00
|
|
|
# Retrieve information about the package
|
2009-06-09 11:00:00 +01:00
|
|
|
version = get_package_version(cache, distro, pack)
|
2007-11-24 01:04:24 +01:00
|
|
|
|
2009-06-09 11:00:00 +01:00
|
|
|
if not version:
|
|
|
|
packages[pack] = False
|
|
|
|
return
|
|
|
|
elif [origin for origin in version.origins if origin.component == 'main']:
|
2007-11-24 01:04:24 +01:00
|
|
|
packages[pack] = True
|
2009-06-09 11:00:00 +01:00
|
|
|
return
|
2007-03-27 21:59:13 +10:00
|
|
|
else:
|
|
|
|
if not packages.has_key(pack):
|
2007-11-24 01:04:24 +01:00
|
|
|
packages[pack] = False
|
|
|
|
|
2009-06-09 11:00:00 +01:00
|
|
|
# Retrieve package dependencies
|
|
|
|
process_deps(cache, version.dependencies)
|
2007-11-24 01:04:24 +01:00
|
|
|
|
2009-06-09 11:00:00 +01:00
|
|
|
# Retrieve package build dependencies. There's no handy
|
|
|
|
# attribute on version for this, so unfortunately we have to
|
|
|
|
# do a lot of messing about with apt.
|
2007-03-27 21:59:13 +10:00
|
|
|
deps = []
|
2010-03-25 22:15:56 +01:00
|
|
|
src_records = apt_pkg.SourceRecords()
|
2009-06-09 11:00:00 +01:00
|
|
|
got_src = False
|
2010-03-25 22:15:56 +01:00
|
|
|
while src_records.lookup(version.source_name):
|
|
|
|
if pack in src_records.binaries:
|
2009-06-09 11:00:00 +01:00
|
|
|
got_src = True
|
|
|
|
break
|
|
|
|
if got_src:
|
2010-03-25 22:15:56 +01:00
|
|
|
for deptype, all_deps in src_records.build_depends.iteritems():
|
|
|
|
for or_deps in all_deps:
|
2009-06-09 11:00:00 +01:00
|
|
|
base_deps = []
|
2010-03-25 22:15:56 +01:00
|
|
|
for (name, ver, op) in or_deps:
|
|
|
|
base_deps.append(apt.package.BaseDependency(name, op, ver, False))
|
|
|
|
deps.append(apt.package.Dependency(base_deps))
|
2007-11-24 01:04:24 +01:00
|
|
|
|
2009-06-09 11:00:00 +01:00
|
|
|
process_deps(cache, deps)
|
2007-03-27 21:59:13 +10:00
|
|
|
|
|
|
|
|
2008-02-24 18:50:01 +01:00
|
|
|
def main():
|
|
|
|
|
|
|
|
global packages, distro
|
2007-11-24 01:04:24 +01:00
|
|
|
|
|
|
|
# Check if the amount of arguments is correct
|
2008-02-24 18:50:01 +01:00
|
|
|
if len(sys.argv) < 2 or len(sys.argv) > 3 or sys.argv[1] in ('help', '-h', '--help'):
|
|
|
|
print 'Usage: %s <package name> [<distribution>]' % sys.argv[0]
|
2007-11-24 01:04:24 +01:00
|
|
|
sys.exit(1)
|
|
|
|
|
2009-06-09 11:00:00 +01:00
|
|
|
cache = apt.cache.Cache()
|
|
|
|
|
2008-02-24 18:50:01 +01:00
|
|
|
if len(sys.argv) == 3 and sys.argv[2]:
|
|
|
|
distro = sys.argv[2]
|
2009-06-09 11:00:00 +01:00
|
|
|
if not get_package_version(cache, distro, 'bash'):
|
2008-02-24 18:50:01 +01:00
|
|
|
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.'
|
|
|
|
sys.exit(1)
|
|
|
|
else:
|
2009-06-09 11:00:55 +01:00
|
|
|
distro = subprocess.Popen(['lsb_release', '-cs'], stdout=subprocess.PIPE).stdout.read().strip('\n')
|
2007-11-24 01:04:24 +01:00
|
|
|
|
2009-06-09 11:00:00 +01:00
|
|
|
if not get_package_version(cache, distro, sys.argv[1]):
|
2008-02-24 18:50:01 +01:00
|
|
|
print 'Can\'t find package «%s» in distribution «%s».' % (sys.argv[1], distro)
|
2007-12-01 12:08:06 +01:00
|
|
|
sys.exit(1)
|
2007-11-24 01:04:24 +01:00
|
|
|
|
2008-02-24 18:50:01 +01:00
|
|
|
print 'Checking package «%s» in distribution «%s»...' % (sys.argv[1], distro)
|
|
|
|
|
2009-06-09 11:00:00 +01:00
|
|
|
find_main(cache, sys.argv[1])
|
2008-02-24 18:50:01 +01:00
|
|
|
|
2007-11-24 01:04:24 +01:00
|
|
|
# True if everything checked until the point is in main
|
|
|
|
all_in_main = True
|
|
|
|
|
|
|
|
for package in packages:
|
|
|
|
if not packages[package]:
|
|
|
|
if all_in_main:
|
2008-02-24 18:50:01 +01:00
|
|
|
print 'The following packages aren\'t in main:'
|
2007-11-24 01:04:24 +01:00
|
|
|
all_in_main = False
|
|
|
|
print ' ', package
|
|
|
|
|
|
|
|
if all_in_main:
|
2008-02-24 18:50:01 +01:00
|
|
|
print 'Package «%s» and all its dependencies and build dependencies are in main.' % sys.argv[1]
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
# Global variable to hold the status of all packages
|
|
|
|
packages = {}
|
|
|
|
|
|
|
|
# Global variable to hold the target distribution
|
|
|
|
distro = ''
|
|
|
|
|
|
|
|
try:
|
|
|
|
main()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
print 'Aborted.'
|
|
|
|
sys.exit(1)
|