+++ /dev/null
-#!/usr/bin/env python
-# -*- coding: utf-8 -*-
-
-import apt
-import difflib
-
-def get_apt_cache():
- cache = apt.cache.Cache()
- cache.update()
- return cache
-
-def guess_packages_by_name(name, cache=None, cache_update=False,
- count=5, cutoff=0.6):
- cache = cache or apt.cache.Cache()
- if cache_update:
- cache.update()
- result = difflib.get_close_matches(
- name,
- cache.keys(),
- count,
- cutoff
- )
- return map(lambda x: get_package_by_name(x, cache=cache), result)
-
-def get_package_by_name(name, cache=None, cache_update=False):
- cache = cache or apt.cache.Cache()
- if cache_update:
- cache.update()
- try:
- return cache[name]
- except KeyError:
- return None
-
-def get_providing_packages_by_name(name, cache=None, cache_update=False):
- cache = cache or apt.cache.Cache()
- if cache_update:
- cache.update()
- return cache.get_providing_packages(name)
-
-def find_linux_headers_packages(cache=None, cache_update=False):
- return filter(lambda x: x.name.startswith('linux-headers-2.6.') and
- 'vserver' not in x.name and
- 'xen' not in x.name and
- 'openvz' not in x.name,
- get_providing_packages_by_name(
- 'linux-headers',
- cache=cache,
- cache_update=cache_update
- )
- )
-
-def find_linux_image_packages(cache=None, cache_update=False):
- return filter(lambda x: x.name.startswith('linux-image-2.6.') and
- 'vserver' not in x.name and
- 'xen' not in x.name and
- 'openvz' not in x.name,
- get_providing_packages_by_name(
- 'linux-image',
- cache=cache,
- cache_update=cache_update
-
- )
- )
-
-def find_linux_source_packages(cache=None, cache_update=False):
- return filter(lambda x: x.name.startswith('linux-source-2.6.') and
- 'vserver' not in x.name and
- 'xen' not in x.name and
- 'openvz' not in x.name,
- get_providing_packages_by_name(
- 'linux-source',
- cache=cache,
- cache_update=cache_update
- )
- )
-
-def find_gcc_compiler_packages(cache=None, cache_update=False):
- return filter(lambda x: x.name.startswith('gcc-') and
- 'vserver' not in x.name and
- 'xen' not in x.name and
- 'openvz' not in x.name,
- get_providing_packages_by_name(
- 'c-compiler',
- cache=cache,
- cache_update=cache_update
- )
- )
-
-def find_iptables_packages(cache=None, cache_update=False):
- return [get_package_by_name('iptables', cache=cache,
- cache_update=cache_update)]
-
-def find_ebtables_packages(cache=None, cache_update=False):
- return [get_package_by_name('ebtables', cache=cache,
- cache_update=cache_update)]
-
-