91 lines
2.6 KiB
Plaintext
Raw Normal View History

#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# 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>
2007-11-24 01:04:24 +01:00
# License: GPLv2 or later
#
# This script is used to check if a package and all its build
# dependencies are in main or not.
import subprocess
import sys
2007-11-24 01:04:24 +01:00
def process_deps(deps):
"""Takes a list of (build) dependencies and processes it."""
for package in [ package.split('|')[0] for package in deps ]:
# Cut package name (from something like "name ( >= version)")
name = package.split(' ')[0]
2007-12-01 12:08:06 +01:00
if not packages.has_key(name) and name != '':
2007-11-24 01:04:24 +01:00
# Check the (build) dependencies recursively
find_main(name)
def find_main(pack):
"""Searches the dependencies and build dependencies of a package recursively
to determine if they are all in the 'main' component or not."""
global packages
2007-11-24 01:04:24 +01:00
# Retrieve information about the package
out = subprocess.Popen('apt-cache madison ' + pack, shell=True, stdout=subprocess.PIPE).stdout.read()
2007-12-01 12:08:06 +01:00
if out.find("/main") != -1:
2007-11-24 01:04:24 +01:00
packages[pack] = True
return 1
else:
if not packages.has_key(pack):
2007-11-24 01:04:24 +01:00
packages[pack] = False
# Retrive package dependencies
2007-12-01 12:08:06 +01:00
deps = subprocess.Popen("apt-cache show " + pack + " | grep Depends", shell=True, stdout=subprocess.PIPE).stdout.read().split('\n')[0].replace('Depends: ', '').split(', ')
2007-11-24 01:04:24 +01:00
process_deps(deps)
# Retrieve package build dependencies
2007-12-01 12:08:06 +01:00
deps1 = subprocess.Popen("apt-cache showsrc " + pack + " | grep Build-Depends", shell=True, stdout=subprocess.PIPE).stdout.readlines()
deps = []
2007-11-24 01:04:24 +01:00
for builddep in deps1:
if builddep.startswith('Build-Depends'):
2007-12-01 12:08:06 +01:00
deps += builddep.strip('\n').replace('Build-Depends: ', '').replace('Build-Depends-Indep: ', '').split(', ')
2007-11-24 01:04:24 +01:00
process_deps(deps)
2007-11-24 01:04:24 +01:00
if __name__ == '__main__':
# Check if the amount of arguments is correct
if len(sys.argv) != 2 or sys.argv[1] in ('help', '-h', '--help'):
print "Usage: %s <package name>" % sys.argv[0]
sys.exit(1)
2007-11-24 01:04:24 +01:00
# Global variable to hold the status of all packages
packages = {}
2007-12-01 12:08:06 +01:00
if subprocess.Popen("apt-cache show " + sys.argv[1] + " 2>/dev/null", shell=True, stdout=subprocess.PIPE).stdout.read() == '':
2007-11-24 01:04:24 +01:00
print "Package «%s» doesn't exist." % sys.argv[1]
sys.exit(1)
2007-12-01 12:08:06 +01:00
try:
find_main(sys.argv[1])
except KeyboardInterrupt:
print 'Aborted.'
sys.exit(1)
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:
print "Following packages aren't in main:"
all_in_main = False
print ' ', package
if all_in_main:
print package, "and all its dependencies are in main."