
    Vhl$                         d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZmZ d Zd Zd	 Zd
 Zd Zd Zd Zd Zedk(  r e        yy)    )absolute_importdivisionprint_functionay  
module: flatpak_remote
short_description: Manage flatpak repository remotes
description:
  - Allows users to add or remove flatpak remotes.
  - The flatpak remotes concept is comparable to what is called repositories in other packaging formats.
  - Currently, remote addition is only supported using C(flatpakrepo) file URLs.
  - Existing remotes will not be updated.
  - See the M(community.general.flatpak) module for managing flatpaks.
author:
  - John Kwiatkoski (@JayKayy)
  - Alexander Bethke (@oolongbrothers)
requirements:
  - flatpak
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  executable:
    description:
      - The path to the C(flatpak) executable to use.
      - By default, this module looks for the C(flatpak) executable on the path.
    type: str
    default: flatpak
  flatpakrepo_url:
    description:
      - The URL to the C(flatpakrepo) file representing the repository remote to add.
      - When used with O(state=present), the flatpak remote specified under the O(flatpakrepo_url) is added using the specified
        installation O(method).
      - When used with O(state=absent), this is not required.
      - Required when O(state=present).
    type: str
  method:
    description:
      - The installation method to use.
      - Defines if the C(flatpak) is supposed to be installed globally for the whole V(system) or only for the current V(user).
    type: str
    choices: [system, user]
    default: system
  name:
    description:
      - The desired name for the flatpak remote to be registered under on the managed host.
      - When used with O(state=present), the remote will be added to the managed host under the specified O(name).
      - When used with O(state=absent) the remote with that name will be removed.
    type: str
    required: true
  state:
    description:
      - Indicates the desired package state.
    type: str
    choices: [absent, present]
    default: present
  enabled:
    description:
      - Indicates whether this remote is enabled.
    type: bool
    default: true
    version_added: 6.4.0
as  
- name: Add the Gnome flatpak remote to the system installation
  community.general.flatpak_remote:
    name: gnome
    state: present
    flatpakrepo_url: https://sdk.gnome.org/gnome-apps.flatpakrepo

- name: Add the flathub flatpak repository remote to the user installation
  community.general.flatpak_remote:
    name: flathub
    state: present
    flatpakrepo_url: https://dl.flathub.org/repo/flathub.flatpakrepo
    method: user

- name: Remove the Gnome flatpak remote from the user installation
  community.general.flatpak_remote:
    name: gnome
    state: absent
    method: user

- name: Remove the flathub remote from the system installation
  community.general.flatpak_remote:
    name: flathub
    state: absent

- name: Disable the flathub remote in the system installation
  community.general.flatpak_remote:
    name: flathub
    state: present
    enabled: false
a  
command:
  description: The exact flatpak command that was executed.
  returned: When a flatpak command has been executed
  type: str
  sample: "/usr/bin/flatpak remote-add --system flatpak-test https://dl.flathub.org/repo/flathub.flatpakrepo"
msg:
  description: Module error message.
  returned: failure
  type: str
  sample: "Executable '/usr/local/bin/flatpak' was not found on the system."
rc:
  description: Return code from flatpak binary.
  returned: When a flatpak command has been executed
  type: int
  sample: 0
stderr:
  description: Error output from flatpak binary.
  returned: When a flatpak command has been executed
  type: str
  sample: "error: GPG verification enabled, but no summary found (check that the configured URL in remote config is correct)\n"
stdout:
  description: Output from flatpak binary.
  returned: When a flatpak command has been executed
  type: str
  sample: "flathub\tFlathub\thttps://dl.flathub.org/repo/\t1\t\n"
)AnsibleModule)to_bytes	to_nativec                 p    |ddj                  |      ||g}t        | | j                  |       dt        d<   y)zAdd a new remote.z
remote-add--{0}TchangedNformat_flatpak_command
check_moderesult)modulebinarynameflatpakrepo_urlmethodcommands         t/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/flatpak_remote.py
add_remoter      s9     |W^^F%;T?SGVV..8F9    c                 p    |ddj                  |      d|g}t        | | j                  |       dt        d<   y)zRemove an existing remote.zremote-deleter
   z--forceTr   Nr   r   r   r   r   r   s        r   remove_remoter      s9     v(>	4PGVV..8F9r   c                     |dddj                  |      g}t        | d|      }|j                         D ]4  }|j                         }t	        |      dk(  r"|d   t        |      k(  s4 y y)zCheck if the remote exists.remote-list--show-disabledr
   Fr   Tr   r   
splitlinessplitlenr   r   r   r   r   r   outputlinelisted_remotes           r   remote_existsr(      st    }&79OPGfeW5F!!# 

}"y. r   c                 p    |dddj                  |      |g}t        | | j                  |       dt        d<   y)zEnable a remote.remote-modifyz--enabler
   Tr   Nr   r   s        r   enable_remoter+      s9     
GNN64JDQGVV..8F9r   c                 p    |dddj                  |      |g}t        | | j                  |       dt        d<   y)zDisable a remote.r*   z	--disabler
   Tr   Nr   r   s        r   disable_remoter-      s9     W^^F5KTRGVV..8F9r   c                 "   |dddj                  |      g}t        | d|      }|j                         D ]Z  }|j                         }t	        |      dk(  r"|d   t        |      k(  s4t	        |      dk(  xs d|d   j                  d      vc S  y)	zCheck if the remote is enabled.r   r   r
   Fr      disabled,r    r$   s           r   remote_enabledr2      s    }&79OPGfeW5F!!# \

}"y.}%*[ja@P@V@VWZ@[.[[\ r   c                     dj                  |      t        d<   |r
dt        d<   y| j                  |d      \  t        d<   t        d<   t        d	<   t        d   S )
N r   r   rc T)check_rcstdoutstderr)joinr   run_command)r   noopr   s      r   r   r      sa    )F9t7=7I7I$ 8J 84F4L&"F8$4 (r   c                  .   t        t        t        dd      t        d      t        ddddg      t        ddd	dg      t        d
d      t        dd            d      } | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  |d       }|d}t        d      a|s | j
                  ddd|z  it         t        | |t        |      |      }|dk(  r|st        | ||||       n|d	k(  r|rt        | |||       |dk(  r;t        | |t        |      |      }	|r|	st        | |||       |s|	rt        | |||        | j                  di t         y )NstrT)typerequired)r?   systemuser)r?   defaultchoicespresentabsentbool)r?   rC   flatpak)r   r   r   stateenabled
executable)argument_specsupports_check_moder   r   r   rI   rJ   rK   r6   F)r   msgz,Executable '%s' was not found on the system. )r   dictparamsget_bin_pathr   	fail_jsonr(   r   r   r   r2   r+   r-   	exit_json)
r   r   r   r   rI   rJ   rK   r   remote_already_existsremote_already_enableds
             r   mainrW      s   540 e,UH!' 24E9 ()46fd3	:	
 !F == Dmm$56O]]8$FMM'"EmmI&G|,J  T2F F
 cKjXc\bc)&&(4.&Q	"7664&A	(	4ffdF3	!/PV!W1&&$716648Fvr   __main__N)
__future__r   r   r   r?   __metaclass__DOCUMENTATIONEXAMPLESRETURNansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   r   r   r   r(   r+   r-   r2   r   rW   __name__rO   r   r   <module>ra      so    C B>@@
8 5 K
3l zF r   