Remove data regarding unreferenced packages and delete files in the package pool that
        are no longer being used by packages.

    :param bool dry_run: Report potential changes without making any changes.

    :return: A dictionary of the package keys and files that were removed.
    :rtype: dict

    CLI Example:

    .. code-block:: bash

        salt '*' aptly.cleanup_db

def cleanup_db(config_path=_DEFAULT_CONFIG_PATH, dry_run=False):
    '''
    Remove data regarding unreferenced packages and delete files in the package pool that
        are no longer being used by packages.

    :param bool dry_run: Report potential changes without making any changes.

    :return: A dictionary of the package keys and files that were removed.
    :rtype: dict

    CLI Example:

    .. code-block:: bash

        salt '*' aptly.cleanup_db
    '''
    _validate_config(config_path)
    dry_run = six.text_type(bool(dry_run)).lower()

    ret = {'deleted_keys': list(),
           'deleted_files': list()}

    cmd = ['db', 'cleanup', '-config={}'.format(config_path),
           '-dry-run={}'.format(dry_run), '-verbose=true']

    cmd_ret = _cmd_run(cmd)

    type_pattern = r'^List\s+[\w\s]+(?P<package_type>(file|key)s)[\w\s]+:$'
    list_pattern = r'^\s+-\s+(?P<package>.*)$'
    current_block = None

    for line in cmd_ret.splitlines():
        if current_block:
            match = re.search(list_pattern, line)
            if match:
                package_type = 'deleted_{}'.format(current_block)
                ret[package_type].append(match.group('package'))
            else:
                current_block = None
        # Intentionally not using an else here, in case of a situation where
        # the next list header might be bordered by the previous list.
        if not current_block:
            match = re.search(type_pattern, line)
            if match:
                current_block = match.group('package_type')

    log.debug('Package keys identified for deletion: %s', len(ret['deleted_keys']))
    log.debug('Package files identified for deletion: %s', len(ret['deleted_files']))
    return ret