コード例 #1
0
ファイル: test_paths.py プロジェクト: alertor/python-apt
    def test_policy(self):
        apt_pkg.config["dir"] = "data/test_debs"
        cache = apt_pkg.Cache(None)
        policy = apt_pkg.Policy(cache)
        file_unicode = os.path.join(self.dir_unicode, u"test.prefs")
        file_bytes = os.path.join(self.dir_bytes, b"test.prefs")

        self.assertTrue(policy.read_pinfile(file_unicode))
        self.assertTrue(policy.read_pinfile(file_bytes))
        self.assertTrue(policy.read_pindir(self.dir_unicode))
        self.assertTrue(policy.read_pindir(self.dir_bytes))
コード例 #2
0
ファイル: deb.py プロジェクト: casual-lemon/maas
def get_deb_versions_info(apt_pkg=None) -> Optional[DebVersionsInfo]:
    """Return versions information for Debian-based MAAS."""

    if apt_pkg is None:
        import apt_pkg

        apt_pkg.init()

    try:
        cache = apt_pkg.Cache(None)
    except SystemError:
        maaslog.error(
            "Installed version could not be determined. Ensure "
            "/var/lib/dpkg/status is valid."
        )
        return None

    depcache = apt_pkg.DepCache(cache)
    sources = apt_pkg.SourceList()
    sources.read_main_list()
    policy = apt_pkg.Policy(cache)
    policy.init_defaults()

    current, update, = (
        None,
        None,
    )
    for package in MAAS_PACKAGES:
        current, update = _get_deb_current_and_update(
            cache, depcache, sources, policy, package
        )
        if current:
            break
    else:
        return None
    return DebVersionsInfo(current=current, update=update)