mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-13 18:01:28 +00:00
introduce ability to find reverse dependencies recursively
The change is introducing two options: --recursive and --recursive-depth. So user will be able to print the full chain of reverse-deps. Signed-off-by: Sahid Orentino Ferdjaoui <sahid.ferdjaoui@canonical.com>
This commit is contained in:
parent
ae9c80de37
commit
5cf0f000db
110
reverse-depends
110
reverse-depends
@ -24,6 +24,7 @@ from ubuntutools.misc import (system_distribution, vendor_to_distroinfo,
|
|||||||
codename_to_distribution)
|
codename_to_distribution)
|
||||||
from ubuntutools.rdepends import query_rdepends, RDependsException
|
from ubuntutools.rdepends import query_rdepends, RDependsException
|
||||||
|
|
||||||
|
DEFAULT_MAX_DEPTH = 10 # We want avoid any infinite loop...
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
system_distro_info = vendor_to_distroinfo(system_distribution())()
|
system_distro_info = vendor_to_distroinfo(system_distribution())()
|
||||||
@ -67,6 +68,12 @@ def main():
|
|||||||
dest='server', default=None,
|
dest='server', default=None,
|
||||||
help='Reverse Dependencies webservice URL. '
|
help='Reverse Dependencies webservice URL. '
|
||||||
'Default: UbuntuWire')
|
'Default: UbuntuWire')
|
||||||
|
parser.add_option('-x', '--recursive',
|
||||||
|
action='store_true', dest='recursive', default=False,
|
||||||
|
help='Consider to find reverse dependencies recursively.')
|
||||||
|
parser.add_option('-d', '--recursive-deph', type="int",
|
||||||
|
metavar='RECURSIVE_DEPTH', dest='recursive_depth', default=DEFAULT_MAX_DEPTH,
|
||||||
|
help='If recusive, you can specify the depth.')
|
||||||
|
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
|
|
||||||
@ -90,12 +97,27 @@ def main():
|
|||||||
# We already printed a warning
|
# We already printed a warning
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def query(package):
|
||||||
try:
|
try:
|
||||||
data = query_rdepends(package, options.release, options.arch, **opts)
|
return query_rdepends(package, options.release, options.arch, **opts)
|
||||||
except RDependsException, e:
|
except RDependsException, e:
|
||||||
Logger.error(str(e))
|
Logger.error(str(e))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def filter_out_fiels(data, fields):
|
||||||
|
for field in data.keys():
|
||||||
|
if field not in fields:
|
||||||
|
del data[field]
|
||||||
|
|
||||||
|
def filter_out_component(data, component):
|
||||||
|
for field, rdeps in data.items():
|
||||||
|
filtered = [rdep for rdep in rdeps
|
||||||
|
if rdep['Component'] in component]
|
||||||
|
if not filtered:
|
||||||
|
del data[field]
|
||||||
|
else:
|
||||||
|
data[field] = filtered
|
||||||
|
|
||||||
if options.arch == 'source':
|
if options.arch == 'source':
|
||||||
fields = ['Reverse-Build-Depends', 'Reverse-Build-Depends-Indep']
|
fields = ['Reverse-Build-Depends', 'Reverse-Build-Depends-Indep']
|
||||||
else:
|
else:
|
||||||
@ -105,50 +127,81 @@ def main():
|
|||||||
if options.suggests:
|
if options.suggests:
|
||||||
fields.append('Reverse-Suggests')
|
fields.append('Reverse-Suggests')
|
||||||
|
|
||||||
for field in data.keys():
|
def build_results(package, result, fields, component, recursive):
|
||||||
if field not in fields:
|
data = query(package)
|
||||||
del data[field]
|
if not data:
|
||||||
|
return
|
||||||
|
|
||||||
if options.component:
|
result[package] = data
|
||||||
for field, rdeps in data.items():
|
|
||||||
filtered = [rdep for rdep in rdeps
|
if fields:
|
||||||
if rdep['Component'] in options.component]
|
filter_out_fiels(result[package], fields)
|
||||||
if not filtered:
|
if component:
|
||||||
del data[field]
|
filter_out_component(result[package], component)
|
||||||
else:
|
|
||||||
data[field] = filtered
|
if recursive > 0:
|
||||||
|
for rdeps in result[package].itervalues():
|
||||||
|
for rdep in rdeps:
|
||||||
|
build_results(
|
||||||
|
rdep['Package'], result, fields, component, recursive - 1)
|
||||||
|
|
||||||
|
result = {}
|
||||||
|
build_results(
|
||||||
|
package, result, fields, options.component,
|
||||||
|
options.recursive and options.recursive_depth or 0)
|
||||||
|
|
||||||
if options.list:
|
if options.list:
|
||||||
display_consise(data)
|
display_consise(result)
|
||||||
else:
|
else:
|
||||||
display_verbose(data)
|
display_verbose(package, result)
|
||||||
|
|
||||||
|
|
||||||
def display_verbose(data):
|
|
||||||
if not data:
|
def display_verbose(package, values):
|
||||||
|
if not values:
|
||||||
print "No reverse dependencies found"
|
print "No reverse dependencies found"
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def print_field(field):
|
||||||
|
print field
|
||||||
|
print '=' * len(field)
|
||||||
|
|
||||||
|
def print_package(values, package, arch, dependency, offset=0):
|
||||||
|
line = ' ' * offset + '* %s' % package
|
||||||
|
if all_archs and set(arch) != all_archs:
|
||||||
|
line += ' [%s]' % ' '.join(sorted(arch))
|
||||||
|
if dependency:
|
||||||
|
if len(line) < 30:
|
||||||
|
line += ' ' * (30 - len(line))
|
||||||
|
line += ' (for %s)' % dependency
|
||||||
|
print line
|
||||||
|
data = values.get(package)
|
||||||
|
if data:
|
||||||
|
offset = offset + 1
|
||||||
|
for rdeps in data.itervalues():
|
||||||
|
for rdep in rdeps:
|
||||||
|
print_package(values,
|
||||||
|
rdep['Package'],
|
||||||
|
rdep['Architectures'],
|
||||||
|
rdep.get('Dependency'),
|
||||||
|
offset)
|
||||||
|
|
||||||
all_archs = set()
|
all_archs = set()
|
||||||
# This isn't accurate, but we make up for it by displaying what we found
|
# This isn't accurate, but we make up for it by displaying what we found
|
||||||
|
for data in values.itervalues():
|
||||||
for rdeps in data.itervalues():
|
for rdeps in data.itervalues():
|
||||||
for rdep in rdeps:
|
for rdep in rdeps:
|
||||||
if 'Architectures' in rdep:
|
if 'Architectures' in rdep:
|
||||||
all_archs.update(rdep['Architectures'])
|
all_archs.update(rdep['Architectures'])
|
||||||
|
|
||||||
for field, rdeps in data.iteritems():
|
for field, rdeps in values[package].iteritems():
|
||||||
print field
|
print_field(field)
|
||||||
print '=' * len(field)
|
|
||||||
rdeps.sort(key=lambda x: x['Package'])
|
rdeps.sort(key=lambda x: x['Package'])
|
||||||
for rdep in rdeps:
|
for rdep in rdeps:
|
||||||
line = '* %s' % rdep['Package']
|
print_package(values,
|
||||||
if all_archs and set(rdep['Architectures']) != all_archs:
|
rdep['Package'],
|
||||||
line += ' [%s]' % ' '.join(sorted(rdep['Architectures']))
|
rdep['Architectures'],
|
||||||
if 'Dependency' in rdep:
|
rdep.get('Dependency'))
|
||||||
if len(line) < 30:
|
|
||||||
line += ' ' * (30 - len(line))
|
|
||||||
line += ' (for %s)' % rdep['Dependency']
|
|
||||||
print line
|
|
||||||
print
|
print
|
||||||
|
|
||||||
if all_archs:
|
if all_archs:
|
||||||
@ -157,8 +210,9 @@ def display_verbose(data):
|
|||||||
% ', '.join(sorted(list(all_archs))))
|
% ', '.join(sorted(list(all_archs))))
|
||||||
|
|
||||||
|
|
||||||
def display_consise(data):
|
def display_consise(values):
|
||||||
result = set()
|
result = set()
|
||||||
|
for data in values.itervalues():
|
||||||
for rdeps in data.itervalues():
|
for rdeps in data.itervalues():
|
||||||
for rdep in rdeps:
|
for rdep in rdeps:
|
||||||
result.add(rdep['Package'])
|
result.add(rdep['Package'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user