2011-11-09 23:44:22 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
#
|
|
|
|
# Copyright (C) 2011, Stefano Rivera <stefanor@debian.org>
|
|
|
|
#
|
|
|
|
# Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
# purpose with or without fee is hereby granted, provided that the above
|
|
|
|
# copyright notice and this permission notice appear in all copies.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
|
|
|
import optparse
|
2011-11-11 23:13:01 +02:00
|
|
|
import sys
|
2011-11-09 23:44:22 +02:00
|
|
|
|
2011-11-11 23:13:01 +02:00
|
|
|
from devscripts.logger import Logger
|
2011-11-09 23:44:22 +02:00
|
|
|
from distro_info import UbuntuDistroInfo
|
|
|
|
|
2011-11-11 23:38:01 +02:00
|
|
|
from ubuntutools.rdepends import query_rdepends, RDependsException
|
2011-11-09 23:44:22 +02:00
|
|
|
|
2011-11-10 02:05:43 +02:00
|
|
|
|
2011-11-09 23:44:22 +02:00
|
|
|
def main():
|
2011-11-11 23:47:14 +02:00
|
|
|
parser = optparse.OptionParser('%progname [options] package',
|
|
|
|
description="List reverse-dependancies of package. "
|
|
|
|
"If the package name is prefixed with src: then the "
|
|
|
|
"reverse-depndencies of all the binary packages that "
|
|
|
|
"the specified source package builds will be listed.")
|
2011-11-09 23:44:22 +02:00
|
|
|
parser.add_option('-r', '--release', metavar='RELEASE',
|
|
|
|
default=UbuntuDistroInfo().devel(),
|
|
|
|
help='Query dependencies in RELEASE. Default: devel')
|
|
|
|
parser.add_option('-R', '--without-recommends',
|
|
|
|
action='store_false', dest='recommends', default=True,
|
2011-11-11 16:31:10 +02:00
|
|
|
help='Only consider Depends relationships, '
|
2011-11-09 23:44:22 +02:00
|
|
|
'not Recommends.')
|
|
|
|
parser.add_option('-s', '--with-suggests',
|
|
|
|
action='store_true', dest='suggests', default=False,
|
|
|
|
help='Also consider Suggests relationships.')
|
|
|
|
parser.add_option('-b', '--build-depends',
|
|
|
|
action='store_const', dest='arch', const='source',
|
|
|
|
help='Query build dependencies (synonym for '
|
|
|
|
'--arch=source')
|
2011-11-11 16:31:10 +02:00
|
|
|
parser.add_option('-a', '--arch', metavar='ARCH', default='any',
|
|
|
|
help='Query dependencies in ARCH '
|
|
|
|
'(default: any)')
|
|
|
|
parser.add_option('-c', '--component', metavar='COMPONENT',
|
|
|
|
action='append',
|
|
|
|
help='Only consider reverse-dependencies in COMPONENT. '
|
|
|
|
'Can be specified multiple times. (default: all)')
|
|
|
|
parser.add_option('-l', '--list',
|
|
|
|
action='store_true', default=False,
|
|
|
|
help='Display a simple, machine-readable list')
|
2011-11-09 23:44:22 +02:00
|
|
|
parser.add_option('-u', '--service-url', metavar='URL',
|
|
|
|
dest='server', default=None,
|
|
|
|
help='Reverse Depedencies webservice URL'
|
|
|
|
'(default: UbuntuWire)')
|
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
|
|
|
if len(args) != 1:
|
|
|
|
parser.error("One (and only one) package must be specified")
|
|
|
|
package = args[0]
|
|
|
|
|
2011-11-10 02:05:43 +02:00
|
|
|
opts = {}
|
2011-11-09 23:44:22 +02:00
|
|
|
if options.server is not None:
|
|
|
|
opts['server'] = options.server
|
|
|
|
|
2011-11-11 23:13:01 +02:00
|
|
|
try:
|
|
|
|
data = query_rdepends(package, options.release, options.arch, **opts)
|
2011-11-11 23:38:01 +02:00
|
|
|
except RDependsException, e:
|
|
|
|
Logger.error(str(e))
|
|
|
|
sys.exit(1)
|
2011-11-10 02:05:43 +02:00
|
|
|
|
|
|
|
if options.arch == 'source':
|
2011-11-11 16:42:10 +02:00
|
|
|
fields = ['Reverse-Build-Depends', 'Reverse-Build-Depends-Indep']
|
2011-11-10 02:05:43 +02:00
|
|
|
else:
|
2011-11-11 16:31:10 +02:00
|
|
|
fields = ['Reverse-Depends']
|
2011-11-11 16:42:10 +02:00
|
|
|
if options.recommends:
|
|
|
|
fields.append('Reverse-Recommends')
|
|
|
|
if options.suggests:
|
|
|
|
fields.append('Reverse-Suggests')
|
2011-11-10 02:05:43 +02:00
|
|
|
|
2011-11-11 16:31:10 +02:00
|
|
|
for field in data.keys():
|
|
|
|
if field not in fields:
|
|
|
|
del data[field]
|
|
|
|
|
|
|
|
if options.component:
|
|
|
|
for field, rdeps in data.items():
|
|
|
|
filtered = [rdep for rdep in rdeps
|
|
|
|
if rdep['Component'] in options.component]
|
|
|
|
if not filtered:
|
|
|
|
del data[field]
|
|
|
|
else:
|
|
|
|
data[field] = filtered
|
|
|
|
|
|
|
|
if options.list:
|
|
|
|
display_consise(data)
|
|
|
|
else:
|
|
|
|
display_verbose(data)
|
|
|
|
|
|
|
|
|
|
|
|
def display_verbose(data):
|
|
|
|
if not data:
|
|
|
|
print "No reverse dependencies found"
|
|
|
|
return
|
|
|
|
|
|
|
|
all_archs = set()
|
|
|
|
# This isn't accurate, but we make up for it by displaying what we found
|
|
|
|
for rdeps in data.itervalues():
|
|
|
|
for rdep in rdeps:
|
|
|
|
if 'Architectures' in rdep:
|
|
|
|
all_archs.update(rdep['Architectures'])
|
|
|
|
|
|
|
|
for field, rdeps in data.iteritems():
|
|
|
|
print field
|
|
|
|
print '=' * len(field)
|
2011-11-11 23:32:20 +02:00
|
|
|
rdeps.sort(key=lambda x: x['Package'])
|
2011-11-11 16:31:10 +02:00
|
|
|
for rdep in rdeps:
|
|
|
|
if all_archs and set(rdep['Architectures']) != all_archs:
|
|
|
|
print '* %s [%s]' % (rdep['Package'],
|
|
|
|
', '.join(sorted(rdep['Architectures'])))
|
|
|
|
else:
|
|
|
|
print '* %s' % rdep['Package']
|
|
|
|
print
|
|
|
|
|
|
|
|
if all_archs:
|
|
|
|
print ("Packages without architectures listed are "
|
|
|
|
"reverse-dependencies in: %s"
|
|
|
|
% ', '.join(sorted(list(all_archs))))
|
|
|
|
|
|
|
|
|
|
|
|
def display_consise(data):
|
2011-11-10 02:05:43 +02:00
|
|
|
result = set()
|
2011-11-11 16:31:10 +02:00
|
|
|
for rdeps in data.itervalues():
|
|
|
|
for rdep in rdeps:
|
|
|
|
result.add(rdep['Package'])
|
2011-11-10 02:05:43 +02:00
|
|
|
|
|
|
|
print u'\n'.join(sorted(list(result)))
|
2011-11-09 23:44:22 +02:00
|
|
|
|
2011-11-11 16:31:10 +02:00
|
|
|
|
2011-11-09 23:44:22 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|