# flake8: noqa
# pylint: skip-file

DOCUMENTATION = '''
---
module: repoquery
short_description: Query package information from Yum repositories
description:
  - Query package information from Yum repositories.
options:
  state:
    description:
    - The expected state. Currently only supports list.
    required: false
    default: list
    choices: ["list"]
    aliases: []
  name:
    description:
    - The name of the package to query
    required: true
    default: None
    aliases: []
  query_type:
    description:
    - Narrows the packages queried based off of this value.
    - If repos, it narrows the query to repositories defined on the machine.
    - If installed, it narrows the query to only packages installed on the machine.
    - If available, it narrows the query to packages that are available to be installed.
    - If recent, it narrows the query to only recently edited packages.
    - If updates, it narrows the query to only packages that are updates to existing installed packages.
    - If extras, it narrows the query to packages that are not present in any of the available repositories.
    - If all, it queries all of the above.
    required: false
    default: repos
    aliases: []
  verbose:
    description:
    - Shows more detail for the requested query.
    required: false
    default: false
    aliases: []
  show_duplicates:
    description:
    - Shows multiple versions of a package.
    required: false
    default: false
    aliases: []
  match_version:
    description:
    - Match the specific version given to the package.
    required: false
    default: None
    aliases: []
author:
- "Matt Woodson <mwoodson@redhat.com>"
extends_documentation_fragment: []
'''

EXAMPLES = '''
# Example 1: Get bash versions
  - name: Get bash version
    repoquery:
      name: bash
      show_duplicates: True
    register: bash_out

# Results:
#    ok: [localhost] => {
#        "bash_out": {
#            "changed": false,
#            "results": {
#                "cmd": "/usr/bin/repoquery --quiet --pkgnarrow=repos --queryformat=%{version}|%{release}|%{arch}|%{repo}|%{version}-%{release} --show-duplicates bash",
#                "package_found": true,
#                "package_name": "bash",
#                "returncode": 0,
#                "versions": {
#                    "available_versions": [
#                        "4.2.45",
#                        "4.2.45",
#                        "4.2.45",
#                        "4.2.46",
#                        "4.2.46",
#                        "4.2.46",
#                        "4.2.46"
#                    ],
#                    "available_versions_full": [
#                        "4.2.45-5.el7",
#                        "4.2.45-5.el7_0.2",
#                        "4.2.45-5.el7_0.4",
#                        "4.2.46-12.el7",
#                        "4.2.46-19.el7",
#                        "4.2.46-20.el7_2",
#                        "4.2.46-21.el7_3"
#                    ],
#                    "latest": "4.2.46",
#                    "latest_full": "4.2.46-21.el7_3"
#                }
#            },
#            "state": "present"
#        }
#    }



# Example 2: Get bash versions verbosely
  - name: Get bash versions verbosely
    repoquery:
      name: bash
      show_duplicates: True
      verbose: True
    register: bash_out

# Results:
#    ok: [localhost] => {
#        "bash_out": {
#            "changed": false,
#            "results": {
#                "cmd": "/usr/bin/repoquery --quiet --pkgnarrow=repos --queryformat=%{version}|%{release}|%{arch}|%{repo}|%{version}-%{release} --show-duplicates bash",
#                "package_found": true,
#                "package_name": "bash",
#                "raw_versions": {
#                    "4.2.45-5.el7": {
#                        "arch": "x86_64",
#                        "release": "5.el7",
#                        "repo": "rhel-7-server-rpms",
#                        "version": "4.2.45",
#                        "version_release": "4.2.45-5.el7"
#                    },
#                    "4.2.45-5.el7_0.2": {
#                        "arch": "x86_64",
#                        "release": "5.el7_0.2",
#                        "repo": "rhel-7-server-rpms",
#                        "version": "4.2.45",
#                        "version_release": "4.2.45-5.el7_0.2"
#                    },
#                    "4.2.45-5.el7_0.4": {
#                        "arch": "x86_64",
#                        "release": "5.el7_0.4",
#                        "repo": "rhel-7-server-rpms",
#                        "version": "4.2.45",
#                        "version_release": "4.2.45-5.el7_0.4"
#                    },
#                    "4.2.46-12.el7": {
#                        "arch": "x86_64",
#                        "release": "12.el7",
#                        "repo": "rhel-7-server-rpms",
#                        "version": "4.2.46",
#                        "version_release": "4.2.46-12.el7"
#                    },
#                    "4.2.46-19.el7": {
#                        "arch": "x86_64",
#                        "release": "19.el7",
#                        "repo": "rhel-7-server-rpms",
#                        "version": "4.2.46",
#                        "version_release": "4.2.46-19.el7"
#                    },
#                    "4.2.46-20.el7_2": {
#                        "arch": "x86_64",
#                        "release": "20.el7_2",
#                        "repo": "rhel-7-server-rpms",
#                        "version": "4.2.46",
#                        "version_release": "4.2.46-20.el7_2"
#                    },
#                    "4.2.46-21.el7_3": {
#                        "arch": "x86_64",
#                        "release": "21.el7_3",
#                        "repo": "rhel-7-server-rpms",
#                        "version": "4.2.46",
#                        "version_release": "4.2.46-21.el7_3"
#                    }
#                },
#                "results": "4.2.45|5.el7|x86_64|rhel-7-server-rpms|4.2.45-5.el7\n4.2.45|5.el7_0.2|x86_64|rhel-7-server-rpms|4.2.45-5.el7_0.2\n4.2.45|5.el7_0.4|x86_64|rhel-7-server-rpms|4.2.45-5.el7_0.4\n4.2.46|12.el7|x86_64|rhel-7-server-rpms|4.2.46-12.el7\n4.2.46|19.el7|x86_64|rhel-7-server-rpms|4.2.46-19.el7\n4.2.46|20.el7_2|x86_64|rhel-7-server-rpms|4.2.46-20.el7_2\n4.2.46|21.el7_3|x86_64|rhel-7-server-rpms|4.2.46-21.el7_3\n",
#                "returncode": 0,
#                "versions": {
#                    "available_versions": [
#                        "4.2.45",
#                        "4.2.45",
#                        "4.2.45",
#                        "4.2.46",
#                        "4.2.46",
#                        "4.2.46",
#                        "4.2.46"
#                    ],
#                    "available_versions_full": [
#                        "4.2.45-5.el7",
#                        "4.2.45-5.el7_0.2",
#                        "4.2.45-5.el7_0.4",
#                        "4.2.46-12.el7",
#                        "4.2.46-19.el7",
#                        "4.2.46-20.el7_2",
#                        "4.2.46-21.el7_3"
#                    ],
#                    "latest": "4.2.46",
#                    "latest_full": "4.2.46-21.el7_3"
#                }
#            },
#            "state": "present"
#        }
#    }

# Example 3: Match a specific version
  - name: matched versions repoquery test
    repoquery:
      name: atomic-openshift
      show_duplicates: True
      match_version: 3.3
    register: openshift_out

# Result:

#    ok: [localhost] => {
#        "openshift_out": {
#            "changed": false,
#            "results": {
#                "cmd": "/usr/bin/repoquery --quiet --pkgnarrow=repos --queryformat=%{version}|%{release}|%{arch}|%{repo}|%{version}-%{release} --show-duplicates atomic-openshift",
#                "package_found": true,
#                "package_name": "atomic-openshift",
#                "returncode": 0,
#                "versions": {
#                    "available_versions": [
#                        "3.2.0.43",
#                        "3.2.1.23",
#                        "3.3.0.32",
#                        "3.3.0.34",
#                        "3.3.0.35",
#                        "3.3.1.3",
#                        "3.3.1.4",
#                        "3.3.1.5",
#                        "3.3.1.7",
#                        "3.4.0.39"
#                    ],
#                    "available_versions_full": [
#                        "3.2.0.43-1.git.0.672599f.el7",
#                        "3.2.1.23-1.git.0.88a7a1d.el7",
#                        "3.3.0.32-1.git.0.37bd7ea.el7",
#                        "3.3.0.34-1.git.0.83f306f.el7",
#                        "3.3.0.35-1.git.0.d7bd9b6.el7",
#                        "3.3.1.3-1.git.0.86dc49a.el7",
#                        "3.3.1.4-1.git.0.7c8657c.el7",
#                        "3.3.1.5-1.git.0.62700af.el7",
#                        "3.3.1.7-1.git.0.0988966.el7",
#                        "3.4.0.39-1.git.0.5f32f06.el7"
#                    ],
#                    "latest": "3.4.0.39",
#                    "latest_full": "3.4.0.39-1.git.0.5f32f06.el7",
#                    "matched_version_found": true,
#                    "matched_version_full_latest": "3.3.1.7-1.git.0.0988966.el7",
#                    "matched_version_latest": "3.3.1.7",
#                    "matched_versions": [
#                        "3.3.0.32",
#                        "3.3.0.34",
#                        "3.3.0.35",
#                        "3.3.1.3",
#                        "3.3.1.4",
#                        "3.3.1.5",
#                        "3.3.1.7"
#                    ],
#                    "matched_versions_full": [
#                        "3.3.0.32-1.git.0.37bd7ea.el7",
#                        "3.3.0.34-1.git.0.83f306f.el7",
#                        "3.3.0.35-1.git.0.d7bd9b6.el7",
#                        "3.3.1.3-1.git.0.86dc49a.el7",
#                        "3.3.1.4-1.git.0.7c8657c.el7",
#                        "3.3.1.5-1.git.0.62700af.el7",
#                        "3.3.1.7-1.git.0.0988966.el7"
#                    ],
#                    "requested_match_version": "3.3"
#                }
#            },
#            "state": "present"
#        }
#    }

'''
