#!/usr/bin/python # -*- coding: utf-8 -*- # # Copyright 2006-2007 (C) Pete Savage # Copyright 2007 (C) Siegfried-A. Gevatter # 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 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] if not packages.has_key(name) and name != '': # 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 # Retrieve information about the package out = subprocess.Popen('apt-cache madison ' + pack, shell=True, stdout=subprocess.PIPE).stdout.read() if out.find("/main") != -1: packages[pack] = True return 1 else: if not packages.has_key(pack): packages[pack] = False # Retrive package dependencies deps = subprocess.Popen("apt-cache show " + pack + " | grep Depends", shell=True, stdout=subprocess.PIPE).stdout.read().split('\n')[0].replace('Depends: ', '').split(', ') process_deps(deps) # Retrieve package build dependencies deps1 = subprocess.Popen("apt-cache showsrc " + pack + " | grep Build-Depends", shell=True, stdout=subprocess.PIPE).stdout.readlines() deps = [] for builddep in deps1: if builddep.startswith('Build-Depends'): deps += builddep.strip('\n').replace('Build-Depends: ', '').replace('Build-Depends-Indep: ', '').split(', ') process_deps(deps) 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 " % sys.argv[0] sys.exit(1) # Global variable to hold the status of all packages packages = {} if subprocess.Popen("apt-cache show " + sys.argv[1] + " 2>/dev/null", shell=True, stdout=subprocess.PIPE).stdout.read() == '': print "Package «%s» doesn't exist." % sys.argv[1] sys.exit(1) try: find_main(sys.argv[1]) except KeyboardInterrupt: print 'Aborted.' sys.exit(1) # 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."