From 9ba953ba80460f41fc8db2c2c81d7223d74d35db Mon Sep 17 00:00:00 2001 From: "Siegfried-Angel Gevatter Pujals (RainCT)" Date: Sat, 24 Nov 2007 01:04:24 +0100 Subject: [PATCH] Rewrote 404main --- 404main | 123 +++++++++++++++++++++++++++-------------------- AUTHORS | 2 +- README | 3 +- debian/changelog | 12 +++-- debian/copyright | 10 ++-- dgetlp | 8 ++- 6 files changed, 97 insertions(+), 61 deletions(-) diff --git a/404main b/404main index fb7c01e..0b1dbcd 100755 --- a/404main +++ b/404main @@ -1,66 +1,87 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# The author of this script is unknown -# License: Public Domain # -# This script is used to check in what components ("main", "restricted", -# "universe" or "multiverse") the dependencies of a package are. +# Copyright 2007 (C) Siegfried-A. Gevatter +# Based upon a script by an unknown author +# License: GPLv2 or later +# +# This script is used to check if a certain package in main has all its +# dependencies and build dependencies there too, or not. import subprocess import sys -packages={} -def find_main(pack, version): +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): + # 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 - mad = subprocess.Popen(['apt-cache madison '+pack], shell=True, stdout=subprocess.PIPE) - out = mad.stdout.read() - if out.find("/main")!=-1 or out.find("http")==-1: - packages[(pack)]="In main" - return + + # Retrieve information about the package + out = subprocess.Popen('apt-cache madison ' + pack, shell=True, stdout=subprocess.PIPE).stdout.read() + + if out.find("/main") != -1 or out.find("http") == -1: + packages[pack] = True + return 1 else: if not packages.has_key(pack): - packages[(pack)]="Not in main" - test = subprocess.Popen(['apt-cache show '+pack], shell=True, stdout=subprocess.PIPE) + packages[pack] = False + + # Retrive package dependencies + deps = subprocess.Popen("dpkg-query -W -f='${Depends}' " + pack, shell=True, stdout=subprocess.PIPE).stdout.read().split(', ') + + process_deps(deps) + + # Retrieve package build dependencies + deps1 = subprocess.Popen('apt-cache showsrc ' + pack, shell=True, stdout=subprocess.PIPE).stdout.readlines() deps = [] - for j in test.stdout.readlines(): - if j.startswith("Depend"): - deps = j.strip("\n").strip("Depends: ").split(",") - depse = [] - for p in deps: - a = p.split("|") - for k in a: - depse.append(k) - for i in depse: - info=i.strip(") ").split("(") - if len(info) == 2: - version = info[1].strip(" ") - name = info[0].strip(" ") - if not packages.has_key(name): - find_main(name, version) + + for builddep in deps1: + if builddep.startswith('Build-Depends'): + deps += builddep.strip('\n').strip('Build-Depends: ').strip('Build-Depends-Indep: ').split(', ') + + process_deps(deps) - test = subprocess.Popen(['apt-cache showsrc '+pack], shell=True, stdout=subprocess.PIPE) - deps = [] - for j in test.stdout.readlines(): - if j.startswith("Build-Depend"): - deps = j.strip("\n").strip("Build-Depends: ").split(",") - depse = [] - for p in deps: - a = p.split("|") - for k in a: - depse.append(k) - for i in depse: - info=i.strip(") ").split("(") - if len(info) == 2: - version = info[1].strip(" ") - name = info[0].strip(" ") - if not packages.has_key(name): - find_main(name, version) -pkg = sys.argv[1] +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) -find_main(pkg,0) - -for j in packages: - if packages[(j)] == "Not in main": - print j + ": "+packages[(j)] + # Global variable to hold the status of all packages + packages = {} + + if subprocess.Popen("dpkg-query -W -f='${Package}' " + 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) + + find_main(sys.argv[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." diff --git a/AUTHORS b/AUTHORS index 5d429f9..445a5a0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -3,8 +3,8 @@ Daniel Holbach Jamin W. Collins Jordan Mantha Luke Yelavich -Michael Bienia Martin Pitt +Michael Bienia Kees Cook Siegfried-A. Gevatter Soren Hansen diff --git a/README b/README index 78599bc..ecef42a 100644 --- a/README +++ b/README @@ -3,7 +3,8 @@ ================================ 404main - ... will check in what components the dependencies of are. + ... will check if the dependencies and build dependencies of + are in 'main' or in another component. check-symbols [] ... will compare and give you a diff of the exported symbols of all .so diff --git a/debian/changelog b/debian/changelog index eed7823..7c3e2ff 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,9 +11,15 @@ ubuntu-dev-tools (0.23) UNRELEASED; urgency=low * update-maintainer: Exit after displaying usage for --help. [ Siegfried-Angel Gevatter Pujals (RainCT) ] - * pbuilder-dist: Move warning about changing $COMPONENTS's value to - the right place (it should be displayed if the installed version - of pbuilder is too old, not otherwise). + * pbuilder-dist: + - move warning about changing $COMPONENTS's value to + the right place (it should be displayed if the installed version + of pbuilder is too old, not otherwise). + * dgetlp: + - add "-h", "--help" and "--debug" (-d was already there) + * 404main: + - rewrite most of it; cleanup and improvements + - change license to GPLv2+ -- Siegfried-Angel Gevatter Pujals (RainCT) Fri, 23 Nov 2007 22:07:58 +0100 diff --git a/debian/copyright b/debian/copyright index 61c9033..fc52871 100644 --- a/debian/copyright +++ b/debian/copyright @@ -12,6 +12,7 @@ Upstream Author: Kees Cook Siegfried-A. Gevatter Soren Hansen + Steve Kowalik Terence Simpson @@ -28,8 +29,9 @@ Copyright: Licenses: -check-symbols, dch-repeat, mk-sbuild-lv, pbuilder-dist, pull-debian-debdiff, -submittodebian, update-maintainer, dgetlp and what-patch are licensed under GPLv2: +404main, check-symbols, dch-repeat, dgetlp, mk-sbuild-lv, pbuilder-dist, +pull-debian-debdiff, submittodebian, update-maintainer, and what-patch +are licensed under GPLv2: This package is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -65,5 +67,5 @@ On Debian systems, the complete text of the GNU General Public License v3 can be found in `/usr/share/common-licenses/GPL-3'. The following of the scripts can be used, at your option, regarding any -later version of the previously specified license: pbuilder-dist, dgetlp, -suspicious-source, get-build-deps. +later version of the previously specified license: 404main, pbuilder-dist, +dgetlp, suspicious-source and get-build-deps. diff --git a/dgetlp b/dgetlp index 17231f3..d00eaf0 100755 --- a/dgetlp +++ b/dgetlp @@ -32,7 +32,7 @@ Example: EOF } -if [ "$1" = "-d" ] +if [ $1 ] && [ $1 = "-d" ] || [ $1 = "--debug" ] then # Debug Mode GET="echo "${GET} @@ -40,6 +40,12 @@ then shift fi +if [ $1 ] && [ $1 = "-h" ] || [ $1 = "--help" ] +then + usage + exit 0 +fi + if [ $# -ne 1 ] then usage