Current File : //proc/self/root/kunden/lib/python3.9/site-packages/dnf-plugins/__pycache__/copr.cpython-39.pyc
a

���gYv�@s�ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlmZm
Z
ddlZddlmZddlmZddlZz$ddlmZmZmZmZdd�ZWnFey�d	d
�ZzddlmZWney�dd�ZYn0Yn0d
Zeed�ed�g�Zeed�ed�dg�Ze�r^ddl m!Z!m"Z"m#Z#ddl$m%Z%m&Z&m'Z'n(ddl!m!Z!m"Z"m#Z#ddl(m%Z%m&Z&m'Z'ej)j*Gdd�dej+j,��Z-ej)j*Gdd�de-��Z.dS)�)�print_functionN)�_�logger)�PY3)�ucd)�name�version�codename�os_release_attrcCst�t�t�fS�N)rrr	�rr�4/usr/lib/python3.9/site-packages/dnf-plugins/copr.py�linux_distribution.srcCsdS)N�r)rrrr
r
1sr
)rc
Cs�td��h}i}|D]<}z$|���d�\}}|�d�||<WqtyLYq0q|d|ddfWd�S1sv0YdS)Nz/etc/os-release�=�"�NAMEZ
VERSION_ID)�open�rstrip�split�strip�
ValueError)Zos_release_fileZos_release_data�lineZos_release_keyZos_release_valuerrr
r7s
�coprZyes�y�no�nr)�ConfigParser�
NoOptionError�NoSectionError)�urlopen�	HTTPError�URLErrorc@seZdZdZdZdZdZdZdZedeZ	dZ
ed	�Zd
Z
ed�Zedd
��Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zed$d%��Zd&d'�Zd(d)�Zd*d+�Z d,d-�Z!d.d/�Z"d0d1�Z#ed2d3��Z$ed4d5��Z%ed6d7��Z&dS)8�CoprCommandz Copr plugin for DNF Nzcopr.fedorainfracloud.orgZfedora�httpsi��://)rz Interact with Copr repositories.Ta�
  enable name/project [chroot]
  disable name/project
  remove name/project
  list --installed/enabled/disabled
  list --available-by-user=NAME
  search project

  Examples:
  copr enable rhscl/perl516 epel-6-x86_64
  copr enable ignatenkobrain/ocltoys
  copr disable rhscl/perl516
  copr remove rhscl/perl516
  copr list --enabled
  copr list --available-by-user=ignatenkobrain
  copr search tests
    cCs�|jddgd�d�|��}|jddtd�d�|jd	dtd
�d�|jddtd�d�|jd
dtd�d�|jdtd�d�|jddd�dS)N�
subcommand�)�help�enable�disable�remove�list�search��nargs�choicesz--installed�
store_truez.List all installed Copr repositories (default))�actionr(z	--enabledzList enabled Copr repositoriesz
--disabledzList disabled Copr repositoriesz--available-by-userrz-List available Copr repositories by user NAME)�metavarr(z--hubz(Specify an instance of Copr to work with)r(�arg�*)r/)�add_argument�add_mutually_exclusive_groupr)�parserZlist_optionrrr
�
set_argparserps$�����zCoprCommand.set_argparsercCs�|jjjjdkrdSd}t�}g}|jjjd}tj�	|t
d�}tj�|�r�|�|�|�
|�|�dd�r�|�dd�r�|�dd�}|�dd�}||g|_n
ddg|_t�tj�	|t
d��D],}|�d�r�tj�	|t
d|�}	|�|	�q�g}
t|jj��r|jjd�d	�}
t|
�d
k�rR|jj�rRt�td�td��tj�td
���nJ|jj�s|t|
�d
k�r||j|_|j|_n t|
�d
k�r�|
d}n|jj}|�rB|�rBd|_|�
t |dd��|�!||dd�}|�rB|�!||d|j"�}|�!||d|j#�}
||_|d||_t$|
�|j#k�rB|jd|
7_|jd|
7_|j�s�d|v�rl||_|j"d||_n|�dd�d|_||_dS)Nrrz.conf�main�distribution�
releaseverFz.d�/��Error: z^specify Copr hub either with `--hub` or using `copr_hub/copr_username/copr_projectname` formatzmultiple hubs specifiedT)�reverse�hostname�protocol�portr%�:r')%�cliZcommand�optsr�base�confZpluginconfpath�os�path�join�PLUGIN_CONF�isfile�append�readZ
has_option�get�
chroot_config�listdir�endswith�lenr4r�hubr�criticalr�dnf�CliError�default_hostname�
copr_hostname�default_url�copr_url�sorted�_read_config_item�default_protocol�default_port�int)�selfZcopr_hubZcopr_plugin_configZconfig_filesZconfig_pathZdefault_config_filer;r<�filenameZconfig_file�projectrArBrCrrr
�	configure�sv


�

��


�
�
zCoprCommand.configurec	Cs.z|�||�WSttfy(|YS0dSr)rPrr)rbZconfigrU�section�defaultrrr
r^�szCoprCommand._read_config_itemcCstj�d�|����dS)N�{0}
)�sys�stderr�write�formatr)rb�textrrr
�_user_warning_before_prompt�sz'CoprCommand._user_warning_before_promptc
	Cs�|jjd}|dkr&|jj�|�dS|dkrl|jjrH|�|jj�dS|�|jj	j
d|jj|jj�dSz|jj
d}WnJttfy�t�td�td��|jj�|�tj�td���Yn0z\|jj
d}t|jj
�dkr�tj�td���|�d	�|_t|j�d
k�r"tj�td���Wn(t�yL|��}|�d	�|_Yn0|dk�rf|�|�dS|�d
�}t|�dv�r�t�td�td��tj�td���n<t|�dk�r�|d}|d}n|d}|d}|d
|}d�|jj	j|j|�|�|�}|dk�rj|� �td�}d
�!|j||g�}d�|�}	|�"||	�|�#||�t�$td��|�%||�nr|dk�r�|� �|�&||�t�$td��nD|dk�r�|� �|�'||�t�$td��ntj�td��|���dS)Nrr(r,r?z>exactly two additional parameters to copr command are requiredr'�zToo many arguments.�-r>zOBad format of optional chroot. The format is distribution-version-architecture.r-r=)ror>zEuse format `copr_username/copr_projectname` to reference copr projectzbad copr project formatz{0}/_copr:{1}:{2}:{3}.repor)a
Enabling a Copr repository. Please note that this repository is not part
of the main distribution, and quality may vary.

The Fedora Project does not exercise any power over the contents of
this repository beyond the rules outlined in the Copr FAQ at
<https://docs.pagure.org/copr.copr/user_documentation.html#what-i-can-build-in-copr>,
and packages are not held to any quality or security level.

Please do not file bug reports about these packages in Fedora
Bugzilla. In case of problems, contact the owner of this repository.
z!Do you really want to enable {0}?z Repository successfully enabled.r*z!Repository successfully disabled.r+z Repository successfully removed.�Unknown subcommand {}.)(rFr&rEZ	optparser�
print_helpZavailable_by_user�_list_user_projects�_list_installed_repositoriesrGrHZreposdir�enabledZdisabledr4r�
IndexErrorrrVrrWrXrT�
exceptions�Errorr�chroot_parts�
_guess_chroot�_searchrl�get_reposdirrZ�_sanitize_username�
_need_rootrK�	_ask_user�_download_repo�info�_runtime_deps_warning�
_disable_repo�_remove_repo)
rbr&�project_name�chrootrd�
copr_username�copr_projectname�
repo_filenamer��msgrrr
�run�s�����



��

�

�


�zCoprCommand.runcCs�|j�d�d}t�d|j|�}|j|jko8t�d|�}t�d|�}|jjr\|sd|sddSn|sddSt�d|�rtdSt�d|�r�dS|j	}	|	r�|s�|	s�|r�dSd}
t�d	|�r�|�d
d�\}}}
}|d|
d|}n�t�d|��r,|�dd
�}|�
d
d�d�d
d
�d
}|d|dd|d
}n.|�dd
�}|jd|dd|d
}d}
|	�sh|d7}|
�rv|d7}t|�|
S)Nr=����_copr:Z_copr_z_copr:|^_copr_zcopr:.*:.*:.*:mlz
coprdep:.*F�copr:rDr>rpr'rorTz (disabled)z *)
�repofiler�re�matchrZr\r[rFrUru�rsplitrY�print)rb�repo_id�repo�enabled_only�
disabled_only�	file_nameZ	match_newZ	match_oldZ	match_anyru�old_reporrZZ
copr_ownerZcopr_dirr�Z	copr_namerrr
�_list_repo_file8sBzCoprCommand._list_repo_filecCsBd}|jj��D]\}}|�||||�rd}q|r>ttd��dS)NFTz�* These coprs have repo file with an old format that contains no information about Copr hub - the default one was assumed. Re-enable the project to fix this.)rG�repos�itemsr�r�r)rbZ	directoryr�r�r�r�r�rrr
rtisz(CoprCommand._list_installed_repositoriesc
Cs�d�|�}|j|}|jj|dd�}zt�|���}Wn(ty^tj	�
td��|���Yn0|�|�td��|�}|�
|�|dD]@}d�||d�}|d	p�td
�}	|jj�t|�|	�}t|�q�dS)Nz!/api_3/project/list?ownername={0}�w+��modez+Can't parse repositories for username '{}'.zList of {} coprsr�z
{0}/{1} : r�descriptionzNo description given�rlr\rGr �json�loadsrOrrWrwrxr�_check_json_output�_print_match_section�outputZ
fmtKeyValFillrr�)
rbZ	user_name�api_path�url�res�
json_parse�section_text�itemr��descrrr
rsss&

��


zCoprCommand._list_user_projectsc
Cs�d�|�}|j|}|jj|dd�}zt�|���}Wn(ty^tj	�
td��|���Yn0|�|�td��|�}|�
|�|dD]>}d�|d�}|d	p�td
�}	|jj�t|�|	�}t|�q�dS)Nz/api_3/project/search?query={}r�r�zCan't parse search for '{}'.zMatched: {}r�z{0} : Z	full_namer�zNo description given.r�)
rb�queryr�r�r�r�r�r�r�r�rrr
r{�s"

�

zCoprCommand._searchcCs|jj�|�}t|�dSr)rGr�Z
fmtSectionr�)rbrm�	formattedrrr
r��sz CoprCommand._print_match_sectioncCsh|jstj�d�d|_tj�d�|����|j��rd|jjj	s`|jj
jd�|�d�|�d�sddSdS)N�
Frhz
{} [y/N]: z
{} [Y/n]: )r�Zdefaultyes_msgT)�
first_warningrirjrkrlrrGZ
_promptWantedrHZassumenor�Zuserconfirm�rbr�r�rrr
�_ask_user_no_raise�s
�zCoprCommand._ask_user_no_raisecCs |�||�stj�td���dS)NzSafe and good answer. Exiting.)r�rWrwrxrr�rrr
r�szCoprCommand._ask_usercCs t��dkrtj�td���dS)Nrz/This command has to be run under the root user.)rI�geteuidrWrwrxr)�clsrrr
r~�s�zCoprCommand._need_rootcCs|j}|dus&|ddus&|ddur,t�}|jjjd}d|dvr�d|vrXd|}n&d	td
�vrnd|}nd�|d|�}n�d|vr�t�d
�}d|vr�d�|�}nd�|d|�}n^d|vr�t�d�}d|vr�d�|�}nd�|d|�}n&d�|d�	dd�d|�r|nd�}|S)z2 Guess which chroot is equivalent to this machine NrFr'ZbasearchZFedoraZRawhidezfedora-rawhide-ZrawhideZredhat_support_product_versionzfedora-{0}-{1}ZMageiaz%{distro_arch}ZCauldronzmageia-cauldron-{}zmageia-{0}-{1}ZopenSUSEz%{_target_cpu}Z
Tumbleweedzopensuse-tumbleweed-{}zopensuse-leap-{0}-{1}z
epel-{}-{}�.Zx86_64)
rQrrGrH�
substitutionsr
rl�rpmZexpandMacror)rbZdistZdistarchr�rrr
rz�s, 



&zCoprCommand._guess_chrootc
Cs�d�|jdd��}|jd}d�|||�}z*t|j|�}tj�|�rRt�|�W�nbt	�yn}z�|j
dkr�td��|j||j
t|��}t
j�|��td�}|j�d�}	|	�r<t�|	��d�}
t�|
�}
|td	��d�|j�|�7}|
�d
��r.|td�d�d
d�|
d
D��7}|td��|�7}t
j�|��n|td��|�7}t
j�|��WYd}~nTd}~0t�y�}z2td��|j||jj�}t
j�|��WYd}~n
d}~00|��}|�d�}t�d|��r�tj�|jjjd|dd�d�}|j|j k�rV|�!ddd��!|j"d��!ddd��!dd��!dd�}
tj�|
��rVt�|
�t#|d��4}|�$|�|�%�D]}|�$|��qtWd�n1�s�0Yt�&|t'j(t'j)Bt'j*Bt'j+B�dS)Nrpr�z%/coprs/{0}/repo/{1}/dnf.repo?arch={2}i�z Request to {0} failed: {1} - {2}z+It wasn't possible to enable this project.
zCopr-Error-Datazutf-8z1Repository '{0}' does not exist in project '{1}'.zavailable chrootsz
Available repositories: z, css|]}d�|�VqdS)z'{}'N�rl)�.0�xrrr
�	<genexpr>�sz-CoprCommand._download_repo.<locals>.<genexpr>z�

If you want to enable a non-default repository, use the following command:
  'dnf copr enable {0} <repository>'
But note that the installed repo file will likely need a manual modification.zProject {0} does not exist.zFailed to connect to {0}: {1}z\[copr:rr'���z.repor��_coprrrDZgroup_�@�wb),rKryrlr r\rIrJ�existsr+r!�coder�strrWrwrxZheadersrP�base64Z	b64decode�decoder�r�r"�reason�strerror�readliner�r�rGrHr|r[�replacerZrrk�	readlines�chmod�stat�S_IRUSR�S_IWUSR�S_IRGRP�S_IROTH)rbr�r�Zshort_chrootZarchr�Zresponse�eZ	error_msgZ
error_dataZerror_data_decodedZ
first_linerZold_repo_filename�frrr
r��sj



��
� "
$����

.zCoprCommand._download_repocs�|jjdd�|j��|�|�|�|��g}�j��D]}|�d�rHq8|�|�q8|s\dSt	d�}t
�d��|�d�
��fdd	�|D���}|�|t	d
��s�|D]$}|jj��j||jjjddi�q�dS)
a,
        In addition to the main copr repo (that has repo ID prefixed with
        `copr:`), the repofile might contain additional repositories that
        serve as runtime dependencies. This method informs the user about
        the additional repos and provides an option to disable them.
        T)r�r�Na�Maintainer of the enabled Copr repository decided to make
it dependent on other repositories. Such repositories are
usually necessary for successful installation of RPMs from
the main Copr repository (they provide runtime dependencies).

Be aware that the note about quality and bug-reporting
above applies here too, Fedora Project doesn't control the
content. Please review the list:

{0}

These repositories have been enabled automatically.r'z

c	s*g|]"}djt��|�j�|d�d��qS)z){num:2}. [{repoid}]
    baseurl={baseurl}�baseurl)Znum�repoidr�)rl�next�cfgZgetValue)r�r��Zcounterr�rr
�
<listcomp>8s��z5CoprCommand._runtime_deps_warning.<locals>.<listcomp>z!Do you want to keep them enabled?ru�0)rG�resetZread_all_repos�_get_copr_repor}r��sections�
startswithrNr�	itertools�countrlrKr�rH�write_raw_configfiler�r�)rbr�r�Zruntime_depsr�r�Zdeprr�r
r�s.

�
�
�z!CoprCommand._runtime_deps_warningcCs�d�|j�dd�d|�|�|�}||jjvr�d�|�|�|�}}||jjvr�d|jj|jvr�|jj|j�d�d}z0|�dd	�d�dd�d}||jkr�WdSWq�ty�Yq�0ndS|jj|S)
Nzcopr:{0}:{1}:{2}rDr'rz{0}-{1}r�r=r�ro)	rlrZr�r}rGr�r�rrv)rbr�r�r�r�rZrrr
r�Fs$��

zCoprCommand._get_copr_repoc
Csv|�||�}|s,tj�td�|j||����zt�|j	�Wn4t
yp}ztj�t|���WYd}~n
d}~00dS)Nz&Failed to remove copr repo {0}/{1}/{2})r�rWrwrxrrlrZrIr+r��OSErrorr�)rbr�r�r�r�rrr
r�\s��zCoprCommand._remove_repocCs`|�||�}|dur,tj�td�||����|j��D]$}|jj	�
|j||jj	jddi�q6dS)Nz!Failed to disable copr repo {}/{}rur�)
r�rWrwrxrrlr�r�rGrHr�r�r�)rbr�r�r�r�rrr
r�hs���zCoprCommand._disable_repocCs<zt�|���}Wn$ty6tj�td��YdS0|S)z� Wrapper around response from server

        check data and print nice error in case of some error (and return None)
        otherwise return json object.
        �Unknown response from server.N)r�r�rOrrWrErXr)r�r�r�rrr
�	_get_datatszCoprCommand._get_datacCs"d|vrtj�d�|d���dS)N�errorz{})rWrwrxrl)r�Zjson_objrrr
r��szCoprCommand._check_json_outputcCs&|ddkrd�|dd��S|SdS)Nrr�zgroup_{}r'r�)r�r�rrr
r}�szCoprCommand._sanitize_username)'�__name__�
__module__�__qualname__�__doc__rQrYZdefault_hubr_r`r[�aliasesr�summaryr��usage�staticmethodr9rer^rnr�r�rtrsr{r�r�r�classmethodr~rzr�r�r�r�r�r�r�r}rrrr
r#PsL
L_1

%82


r#c@sDeZdZdZdZed�ZdZdd�Zdd�Z	e
d	d
��Zdd�Zd
S)�PlaygroundCommandz Playground plugin for DNF )Z
playgroundz$Interact with Playground repository.z [enable|disable|upgrade]c		Cs0|��|�td�td��d�|j�}|jj|dd�}|�|�}|��|ddkrft	j
�td���|d	D]�}d
�|d|d�}d
�|jjj
|�dd��}zp||dvr�Wqnd�|j||�}|jj|dd�}|�|�}|��|�rd|v�r|ddk�r|�||�Wqnt	jj�y(Yqn0qndS)Nz!Enabling a Playground repository.zDo you want to continue?z{0}/api/playground/list/r�r�r��okr�r�z{0}/{1}�usernameZcoprnamez{}/_playground_{}.repor=rpZchrootsz{0}/api/coprs/{1}/detail/{2}/)r~rrrlr\rGr r��closerWrErXrHr|r�r�rwrx)	rbr�Zapi_urlr�r�r�r�r�Zoutput2rrr
�_cmd_enable�sB��

��

�zPlaygroundCommand._cmd_enablecCs2|��t�d�|jjj��D]}|�|�qdS)Nz{}/_playground_*.repo)r~�globrlrGrHr|r�)rbr�rrr
�_cmd_disable�szPlaygroundCommand._cmd_disablecCs|jddgd�d�dS)Nr&r')r)r*�upgrader.)r6)r8rrr
r9�s�zPlaygroundCommand.set_argparsercCs�tj�d��|jjd}|��}|dkrB|�|�t�t	d��n`|dkrb|�
�t�t	d��n@|dkr�|�
�|�|�t�t	d��ntj�t	d	��|���dS)
Nz%Playground is temporarily unsupportedrr)z-Playground repositories successfully enabled.r*z.Playground repositories successfully disabled.r�z-Playground repositories successfully updated.rq)rWrwrxrFr&rzr�rr�rr�rl)rbr&r�rrr
r��s 

�zPlaygroundCommand.runN)
r�r�r�r�r�rr�r�r�r�r�r9r�rrrr
r��s 
r�)/Z
__future__rr�r�r�rIr��shutilr�rir�ZdnfpluginscorerrrWZ
dnf.pycomprZdnf.i18nrr�Zdistrorrr	r
r�ImportError�platformrL�setZYESZNOZconfigparserrrrZurllib.requestr r!r"Zurllib2ZpluginZregister_commandrEZCommandr#r�rrrr
�<module>sP
B