コード例 #1
0
def uninstall_pkg(pkg_name):
    """
    Uninstall rpm/deb package by name

    :param pkg_name: name of pkg to uninstall
    :type: String

    :return: Flag whether pkg uninstalled
    :rtype: bool
    """

    log = logging.getLogger('package_manager.uninstall_pkg')
    if not is_pkg_installed(pkg_name):
        log.info(f'Package {pkg_name} was removed')
        return True

    cmd = _CMD_PATTERN["UNINSTALL"].get(
        get_os_name()).format(pkg_name=pkg_name)
    err, out = cmd_exec(cmd)

    if err == 0:
        log.info(f'Package {pkg_name} was removed')
        log.debug(out)
        return True

    log.error(out)
    log.error(f'Package "{pkg_name}" was not removed')
    return False
コード例 #2
0
def install_pkg(pkg_path):
    """

    :param pkg_path: path to pkg to install
    :type: pathlib.Path

    :return: Flag whether pkg installed
    :rtype: bool
    """
    configure_logger('package_manager.install_pkg')
    log = logging.getLogger()

    cmd = _CMD_PATTERN["INSTALL"].get(get_os_name()).format(pkg_path=pkg_path)
    err, out = cmd_exec(cmd)

    if err == 0:
        log.debug(out)
        return True

    log.info(out)
    return False
コード例 #3
0
def install_pkg(pkg_path):
    """

    :param pkg_path: path to pkg to install
    :type: pathlib.Path

    :return: Flag whether pkg installed
    :rtype: bool
    """
    log = logging.getLogger('package_manager.install_pkg')

    cmd = _CMD_PATTERN["INSTALL"].get(get_os_name()).format(pkg_path=pkg_path)
    err, out = cmd_exec(f'{cmd} && sudo ldconfig')

    if err == 0:
        log.info(f'Package "{pkg_path}" was installed')
        log.debug(out)
        return True

    log.error(out)
    log.error(f'Package "{pkg_path}" was not installed')
    return False
コード例 #4
0
def is_pkg_installed(pkg_name):
    """
    Check whether pkg is installed

    :param pkg_name: pkg name
    :type: String

    :return: Flag whether pkg is installed
    :rtype: bool

    """

    log = logging.getLogger('package_manager.is_pkg_installed')
    cmd = _CMD_PATTERN["CHECK_INSTALLED"].get(
        get_os_name()).format(pkg_name=pkg_name)
    err, out = cmd_exec(cmd)

    if err == 0:
        log.info(f'Package {pkg_name} was found')
        log.debug(out)
        return True

    log.info(out)
    return False