ubuntu-dev-tools/reverse-depends

77 lines
2.9 KiB
Plaintext
Raw Normal View History

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
from distro_info import UbuntuDistroInfo
from ubuntutools.rdepends import rdepends
2011-11-09 23:44:22 +02:00
def main():
parser = optparse.OptionParser('%progname [options] package')
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,
help='Only examine Depends relationships, '
'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')
parser.add_option('-a', '--arch', metavar='ARCH', default='i386',
help='Query dependencies in ARCH'
'(default: i386)')
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]
opts = {}
2011-11-09 23:44:22 +02:00
if options.server is not None:
opts['server'] = options.server
data = rdepends(package, options.release, options.arch, **opts)
if options.arch == 'source':
fields = ('Build-Depends', 'Build-Depends-Indep')
else:
fields = ['Depends']
if options.recommends:
fields.append('Recommends')
if options.suggests:
fields.append('Suggests')
result = set()
for field in fields:
result.update(data.get(field, []))
print u'\n'.join(sorted(list(result)))
2011-11-09 23:44:22 +02:00
if __name__ == '__main__':
main()