Revision 31c4557a
Added by David Sorber over 11 years ago
| software/apt-tools/get_deps.py | ||
|---|---|---|
|
import apt
|
||
|
|
||
|
# Virtual package mapping
|
||
|
virtual_mapping = {'awk': 'gawk'}
|
||
|
virtual_mapping = {'awk': 'gawk',
|
||
|
'perlapi-5.18.1': 'perl-base',
|
||
|
'perlapi-5.18.2': 'perl-base',
|
||
|
'upstart-job': 'upstart',
|
||
|
'python:any': 'python2.7',
|
||
|
'python3:any': 'python3.4',
|
||
|
'whiptail-provider': 'whiptail'}
|
||
|
|
||
|
def main():
|
||
|
|
||
|
parser = argparse.ArgumentParser(description='Process some integers.')
|
||
|
parser.add_argument('-v', '--verbose', action='store_true')
|
||
|
parser.add_argument('input_package_files', action='store')
|
||
|
parser.add_argument('-v', '--verbose', action='store_true',
|
||
|
help='write additional information to stderr')
|
||
|
parser.add_argument('input_package_files', action='store',
|
||
|
help='a comma separated list of files containing '
|
||
|
'package names, one per line')
|
||
|
args = parser.parse_args()
|
||
|
|
||
|
# Input packages
|
||
| ... | ... | |
|
cache = apt.Cache(memonly=True)
|
||
|
cache.open()
|
||
|
|
||
|
# Create a set to hold the names of all packages and their dependencies
|
||
|
packages = set()
|
||
|
|
||
|
while True:
|
||
|
try:
|
||
|
# Grab next package
|
||
|
pkg_name = in_packages.pop()
|
||
|
#~ print('Package: {:s}'.format(pkg_name))
|
||
|
pkg_name = in_packages.pop()
|
||
|
if args.verbose:
|
||
|
sys.stderr.write('Package: {:s}\n'.format(pkg_name))
|
||
|
sys.stderr.flush()
|
||
|
|
||
|
# Check if the package is in the cache, if not check if it is in
|
||
|
# our list of known virtual packages
|
||
|
if pkg_name not in cache:
|
||
|
if pkg_name in virtual_mapping:
|
||
|
pkg_name = virtual_mapping[pkg_name]
|
||
|
else:
|
||
|
sys.stderr.write('ERROR: unkown package "{:s}"; if this is '
|
||
|
'a virtual package please add it to the '
|
||
|
'virtual package mapping\n'.format(pkg_name))
|
||
|
continue
|
||
|
|
||
|
# Add this package (with version) to the list of packages
|
||
|
if pkg_name not in packages:
|
||
|
packages.add(pkg_name)
|
||
|
packages.add(pkg_name)
|
||
|
|
||
|
# Get package dependencies
|
||
|
for pdep in cache[pkg_name].versions[0].dependencies:
|
||
|
dep_name = pdep[0].name
|
||
|
#~ print('\tDependency: {:s}'.format(dep_name))
|
||
|
if args.verbose:
|
||
|
sys.stderr.write('\tDependency: {:s}\n'.format(dep_name))
|
||
|
sys.stderr.flush()
|
||
|
if dep_name not in packages:
|
||
|
if dep_name in virtual_mapping:
|
||
|
dep_name = virtual_mapping[dep_name]
|
||
Made a few more udates to the script and added additional virtual package mappings.