Viewing File: /lib/python3.6/site-packages/dnf-plugins/__pycache__/groups_manager.cpython-36.pyc

3

�f�4�@s�ddlmZddlmZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZmZddl
Z
ddlZ
dZejdje��Zejd�Zdddd	�Zd
d�Zdd
�Zdd�Ze
jjGdd�de
jj��ZdS)�)�absolute_import)�unicode_literalsN)�_�loggerz
-a-z0-9_.:z^[{}]+$z^[-a-zA-Z0-9_.@]+$T)Zdefault_explicitZuservisible_explicitZempty_groupscCstj|�stjtd���|S)zgroup id validatorzInvalid group id)�RE_GROUP_ID�match�argparse�ArgumentTypeErrorr)�value�r�$/usr/lib/python3.6/groups_manager.py�
group_id_type.s
r
cCsN|jdd�}t|�dkr&tjtd���|\}}tj|�sFtjtd���||fS)ztranslated texts validator�:�z6Invalid translated data, should be in form 'lang:text'z*Invalid/empty language for translated data)�split�lenrr	r�RE_LANGr)r
�data�lang�textrrr�translation_type5s

rcCs:|j�}tjdjt�d|�}|s6tjjtd�j|���|S)z#generate group id based on its namez[^{}]�zFCan't generate group id from '{}'. Please specify group id using --id.)	�lower�re�sub�format�RE_GROUP_ID_VALID�dnf�cli�CliErrorr)r�group_idrrr�
text_to_idAsr!csdeZdZdZed�Z�fdd�Zedd��Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Z�ZS)�GroupsManagerCommand�groups-managerz$create and edit groups metadata filecstt|�j|�tj�|_dS)N)�superr"�__init__�libcomps�Comps�comps)�selfr)�	__class__rrr%QszGroupsManagerCommand.__init__cCs�|jddgdtd�d�|jddgdtd�d�|jddtd	�d
�|jddd
td�d�|jdttd�d�|jddtd�d�|jdtd�d�|jdttd�d�|jddgdttd�d�|jddgdttd �d�|j�}|jd!d"ddtd#�d$�|jd%d"d&dtd'�d$�|j�}|jd(dtd)�d*�|jd+dtd,�d*�|jd-dd
td.�d�|jd/dtd0�d*�|jd1d2d3td4�d5�dS)6Nz--load�appendz	COMPS.XMLzload groups metadata from file)�action�default�metavar�helpz--savezsave groups metadata to filez--mergez%load and save groups metadata to file)r.r/z--print�
store_trueFz#print the result metadata to stdout)r,r-r/z--idzgroup id)�typer/z-nz--namez
group name)r/z
--descriptionzgroup descriptionz--display-orderzgroup display orderz--translated-namez	LANG:TEXTztranslated name for the group)r,r-r.r1r/z--translated-descriptionz$translated description for the groupz--user-visible�user_visiblez%make the group user visible (default))�destr,r-r/z--not-user-visibleZstore_falsezmake the group user invisiblez--mandatoryz%add packages to the mandatory section)r,r/z
--optionalz$add packages to the optional sectionz--removez5remove packages from the group instead of adding themz--dependenciesz-include also direct dependencies for packages�packages�*ZPACKAGEzpackage specification)�nargsr.r/)�add_argumentrr
�intrZadd_mutually_exclusive_group)�parserZvisibleZsectionrrr�
set_argparserUsR








z"GroupsManagerCommand.set_argparsercCs�|jj}|jjr"d|_d|_d|_|jjrP|jjj	d|jj�|jj
j|jj�|jjs�|jj
s�|jjs�|jjs�|jjdk	s�|jjr�|jjr�|jjr�tjjtd���dS)NTFrz;Can't edit group without specifying it (use --id or --name))r�demands�optsr4Zsack_activationZavailable_reposZload_system_repo�merge�load�insert�saver+�description�
display_order�translated_name�translated_descriptionr2�id�namerrr)r)r;rrr�	configure�s"zGroupsManagerCommand.configurecCs �x|jjD�]
}tj�}yp|jd�r~tj|��F}tjdd�}z$t	j
||�|j�|j|j
�Wdtj|j
�XWdQRXn
|j|�Wn~tttjfk
�r}zXt�}x2|j�D]&}||kr�q�tj|j��|j|�q�Wtjjtd�j||���WYdd}~XqX|j|7_qWdS)zm
        Loads all input xml files.
        Returns True if at least one file was successfuly loaded
        z.gzF)�deleteNzCan't load file "{}": {})r<r>r&r'�endswith�gzip�open�tempfileZNamedTemporaryFile�shutilZcopyfileobj�closeZ	fromxml_frF�os�unlink�IOError�OSErrorZParserError�setZget_last_errorsr�error�strip�addr�
exceptions�Errorrrr()r)�	file_nameZ
file_compsZgz_fileZ	temp_file�err�seenrTrrr�load_input_files�s,
$z%GroupsManagerCommand.load_input_filescCs�x�|jjD]�}y|jj|td�}Wn*tjk
rL}z|g}WYdd}~XnX|r
x"|dd�D]}tj|j	��q`Wt
jjt
d�j||dj	����q
WdS)N)�xml_options�zCan't save file "{}": {}���r_)r<r@r(Zxml_f�COMPS_XML_OPTIONSr&ZXMLGenErrorrrTrUrrWrXrr)r)rY�errorsrZrrr�save_output_files�sz&GroupsManagerCommand.save_output_filescCs\d}|r*x |jjD]}|j|kr|}PqW|dkrX|rXx |jjD]}|j|kr@|}Pq@W|S)zl
        Try to find group according to command line parameters - first by id
        then by name.
        N)r(�groupsrErF)r)r rF�groupZgrprrr�
find_group�s

zGroupsManagerCommand.find_groupcCs�dd�}|jjr|jj|_|jjr,|jj|_|jjr>|jj|_|jjdk	rT|jj|_|jjrj||jj�|_|jj	r�||jj	�|_
|jj�r�t�}xZ|jjD]N}t
jj|�}|j|jjdddd�j�}|s�tjtd�j|��q�|j|�q�W|jj�r2t�}x|D]}|j|j��qW|j|jjj�j|d��d	d
�|D�}	|jj�r�x�|	D].}
x&|j|
tj d�D]}|jj|��qfW�qPWnd|jj!�r�tj"}n|jj#�r�tj$}ntj%}x8t&|	�D],}
|j|
|d��s�|jj'tj(|
|d���q�WdS)zE
        Set attributes and package lists for selected group
        cSs&tj�}x|D]\}}|||<qW|S)N)r&ZStrDict)ZlstZstr_dictrrrrr�langlist_to_strdict�sz<GroupsManagerCommand.edit_group.<locals>.langlist_to_strdictNTF)Z
with_nevraZ
with_providesZwith_filenameszNo match for argument: {})ZprovidescSsh|]
}|j�qSr)rF)�.0�pkgrrr�	<setcomp>sz2GroupsManagerCommand.edit_group.<locals>.<setcomp>)rFr1))r<rFrAZdescrBr2ZuservisiblerCZname_by_langrDZdesc_by_langr4rSrZsubjectZSubjectZget_best_query�baseZsackZlatestrZwarningrr�updateZdependenciesZrequiresZqueryZfilterm�removeZpackages_matchr&ZPACKAGE_TYPE_UNKNOWNZ	mandatoryZPACKAGE_TYPE_MANDATORYZoptionalZPACKAGE_TYPE_OPTIONALZPACKAGE_TYPE_DEFAULT�sortedr+ZPackage)r)rdrfr4Zpkg_specZsubj�qZrequirementsrhZ	pkg_namesZpkg_nameZpkg_typerrr�
edit_group�sT










zGroupsManagerCommand.edit_groupcCs|j�|jjs|jjr�|j|jj|jjd�}|dkr�|jjrNtjjt	d���t
j�}|jjrt|jj|_|jj|_nD|jjr�t|jj�}|j|dd�r�tj
jt	d�j||jj���||_|jjj|�|j|�|j�|jjs�|jjr�t|jjtd��dS)N)r rFz-Can't remove packages from non-existent groupzRGroup id '{}' generated from '{}' is duplicit. Please specify group id using --id.)r])r\r<rErFrerlrrWrXrr&ZGroupr!rrrr(rcr+rorb�printr@Zxml_strr`)r)rdr rrr�run!s,

zGroupsManagerCommand.run)r#)�__name__�
__module__�__qualname__�aliasesrZsummaryr%�staticmethodr:rGr\rbrerorq�
__classcell__rr)r*rr"Ls1$=r")Z
__future__rrrrJr&rOrrMrLZdnfpluginscorerrrZdnf.clir�compilerrrr`r
rr!ZpluginZregister_commandrZCommandr"rrrr�<module>s,

Back to Directory File Manager
<