# Path: canaryd/subprocess.py
# def get_command_output(command, *args, **kwargs):
#     logger.debug('Executing command: {0}'.format(command))
# 
#     if not kwargs.get('shell', False):
#         command = ensure_command_tuple(command)
# 
#     try:
#         output = check_output(  # noqa: F405
#             command,
#             close_fds=True,
#             stderr=STDOUT,  # noqa: F405
#             *args, **kwargs
#         )
#     except CalledProcessError as e:  # noqa: F405
#         e.output = decode_output(e.output)
#         raise e
# 
#     output = decode_output(output)
#     return output


import re
from canaryd_packages import six
from canaryd.subprocess import get_command_output



DEB_REGEX = r'^[a-z]+\s+([a-zA-Z0-9\+\-\.]+):?[a-zA-Z0-9]*\s+([a-zA-Z0-9:~\.\-\+]+).+$'
RPM_REGEX = r'^([a-zA-Z0-9_\-\+]+)\-([0-9a-z\.\-]+)\.[a-z0-9_\.]+$'
PKG_REGEX = r'^([a-zA-Z0-9_\-\+]+)\-([0-9a-z\.]+)'


def get_parse_packages(timeout, package_type, command, regex, lower=True):
    output = get_command_output(
        command,
        timeout=timeout,
    )

    packages = {}

    for line in output.splitlines():
        matches = re.match(regex, line)

        if matches:
            # Sort out name

# Path: canaryd/subprocess.py
# def get_command_output(command, *args, **kwargs):
#     logger.debug('Executing command: {0}'.format(command))
# 
#     if not kwargs.get('shell', False):
#         command = ensure_command_tuple(command)
# 
#     try:
#         output = check_output(  # noqa: F405
#             command,
#             close_fds=True,
#             stderr=STDOUT,  # noqa: F405
#             *args, **kwargs
#         )
#     except CalledProcessError as e:  # noqa: F405
#         e.output = decode_output(e.output)
#         raise e
# 
#     output = decode_output(output)
#     return output


# Path: canaryd/plugins/packages_util.py
import re
from canaryd_packages import six
from canaryd.subprocess import get_command_output




DEB_REGEX = r'^[a-z]+\s+([a-zA-Z0-9\+\-\.]+):?[a-zA-Z0-9]*\s+([a-zA-Z0-9:~\.\-\+]+).+$'
RPM_REGEX = r'^([a-zA-Z0-9_\-\+]+)\-([0-9a-z\.\-]+)\.[a-z0-9_\.]+$'
PKG_REGEX = r'^([a-zA-Z0-9_\-\+]+)\-([0-9a-z\.]+)'


def get_parse_packages(timeout, package_type, command, regex, lower=True):
    output = get_command_output(
        command,
        timeout=timeout,
    )

    packages = {}

    for line in output.splitlines():
        matches = re.match(regex, line)

        if matches:
            # Sort out name

            name = matches.group(1)