Source code for COT.helpers.apt_get

#!/usr/bin/env python
# - Wrapper for the 'apt-get' package manager.
# October 2016, Glenn F. Matthews
# Copyright (c) 2015-2016 the COT project developers.
# See the COPYRIGHT.txt file at the top-level directory of this distribution
# and at
# This file is part of the Common OVF Tool (COT) project.
# It is subject to the license terms in the LICENSE.txt file found in the
# top-level directory of this distribution and at
# No part
# of COT, including this file, may be copied, modified, propagated, or
# distributed except according to the terms contained in the LICENSE.txt file.

"""Wrapper for the 'apt-get' package manager."""

import logging
import re

from COT.helpers.helper import PackageManager, helpers

logger = logging.getLogger(__name__)

[docs]class AptGet(PackageManager): """The 'apt-get' package manager utility.""" _updated = False
[docs] def __init__(self): """Initializer.""" super(AptGet, self).__init__("apt-get", version_regexp="apt ([0-9.]+)")
[docs] def install_package(self, package): """Install the requested package if needed. Args: package (str): Name of the package to install. """ # Check whether it's already installed if"install ok installed", helpers['dpkg'].call(['-s', package], require_success=False)): return # Update the repository if needed if not AptGet._updated:['-q', 'update'], capture_output=False, retry_with_sudo=True) AptGet._updated = True['-q', 'install', package], capture_output=False, retry_with_sudo=True)