111 lines
3.5 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
2008-02-24 18:50:01 +01:00
out = subprocess.Popen('apt-cache madison ' + pack + ' | grep ' + distro + ' | grep -m 1 Packages', shell=True, stdout=subprocess.PIPE).stdout.read()
2007-11-24 01:04:24 +01:00
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
2008-02-24 18:50:01 +01:00
deps = subprocess.Popen('apt-cache show ' + pack + ' | grep -m 1 ^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
2008-02-24 18:50:01 +01:00
deps1 = subprocess.Popen('apt-cache showsrc ' + pack + ' | grep -m 1 ^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)
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)
2008-02-24 18:50:01 +01:00
if len(sys.argv) == 3 and sys.argv[2]:
distro = sys.argv[2]
if not subprocess.Popen('apt-cache madison bash | grep ' + distro, shell=True, stdout=subprocess.PIPE).stdout.read():
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:
distro = subprocess.Popen('lsb_release -cs', shell=True, stdout=subprocess.PIPE).stdout.read().strip('\n')
2007-11-24 01:04:24 +01:00
2008-02-24 18:50:01 +01:00
if not subprocess.Popen('apt-cache madison ' + sys.argv[1] + ' | grep ' + distro, shell=True, stdout=subprocess.PIPE).stdout.read():
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)
find_main(sys.argv[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:
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)