from ceph_deploy.lib.remoto import process


def apt(conn, packages, *a, **kw):
    if isinstance(packages, str):
        packages = [packages]
    cmd = [
        'env',
        'DEBIAN_FRONTEND=noninteractive',
        'apt-get',
        '-q',
        'install',
        '--assume-yes',
    ]
    cmd.extend(packages)
    return process.run(
        conn,
        cmd,
        *a,
        **kw
    )


def apt_remove(conn, packages, *a, **kw):
    if isinstance(packages, str):
        packages = [packages]

    purge = kw.pop('purge', False)
    cmd = [
        'apt-get',
        '-q',
        'remove',
        '-f',
        '-y',
        '--force-yes',
    ]
    if purge:
        cmd.append('--purge')
    cmd.append('--')
    cmd.extend(packages)

    return process.run(
        conn,
        cmd,
        *a,
        **kw
    )


def apt_update(conn):
    cmd = [
        'apt-get',
        '-q',
        'update',
    ]
    return process.run(
        conn,
        cmd,
    )


def yum(conn, packages, *a, **kw):
    if isinstance(packages, str):
        packages = [packages]

    cmd = [
        'yum',
        '-y',
        '-q',
        'install',
    ]
    cmd.extend(packages)
    return process.run(
        conn,
        cmd,
        *a,
        **kw
    )


def yum_remove(conn, packages, *a, **kw):
    cmd = [
        'yum',
        '-y',
        '-q',
        'remove',
    ]
    if isinstance(packages, str):
        cmd.append(packages)
    else:
        cmd.extend(packages)
    return process.run(
        conn,
        cmd,
        *a,
        **kw
    )


def rpm(conn, rpm_args=None, *a, **kw):
    """
    A minimal front end for ``rpm`. Extra flags can be passed in via
    ``rpm_args`` as an iterable.
    """
    rpm_args = rpm_args or []
    cmd = [
        'rpm',
        '-Uvh',
    ]
    cmd.extend(rpm_args)
    return process.run(
        conn,
        cmd,
        *a,
        **kw
    )

@@ -1904,28 +1904,682 @@
      *a,%0A        **kw%0A    )%0A
+%0A%0Adef zypper(conn, packages, *a, **kw):%0A    if isinstance(packages, str):%0A        packages = %5Bpackages%5D%0A%0A    cmd = %5B%0A        'zypper',%0A        '--non-interactive',%0A        '--quiet',%0A        'install',%0A    %5D%0A%0A    cmd.extend(packages)%0A    return process.run(%0A        conn,%0A        cmd,%0A        *a,%0A        **kw%0A    )%0A%0A%0Adef zypper_remove(conn, packages, *a, **kw):%0A    cmd = %5B%0A        'zypper',%0A        '--non-interactive',%0A        '--quiet',%0A        'remove',%0A        %5D%0A%0A    if isinstance(packages, str):%0A        cmd.append(packages)%0A    else:%0A        cmd.extend(packages)%0A    return process.run(%0A        conn,%0A        cmd,%0A        *a,%0A        **kw%0A    )%0A

add zypper support to pkg_managers