Edit File: groups_manager.cpython-36.pyc
3 �*�d�4������������������@���s����d�dl�mZ�d�dl�mZ�d�dlZd�dlZd�dlZd�dlZd�dlZd�dlZd�dl Z d�dl mZmZ�d�dl Z d�dlZ dZejdje��Zejd�Zdddd �Zd d��Zdd ��Zdd��Ze jjG�dd��de jj��ZdS�)�����)�absolute_import)�unicode_literalsN)�_�loggerz -a-z0-9_.:z^[{}]+$z^[-a-zA-Z0-9_.@]+$T)Zdefault_explicitZuservisible_explicitZempty_groupsc�������������C���s���t�j|��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 ���c�������������C���sN���|�j�dd�}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�lenr���r ���r����RE_LANGr���)r ����data�lang�textr���r���r����translation_type5���s���� r���c�������������C���s:���|�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_idr���r���r���� text_to_idA���s����r!���c�������������������sd���e�Zd�ZdZed�Z��fdd�Zedd���Zdd��Z d d ��Z dd��Zd d��Zdd��Z dd��Z���ZS�)�GroupsManagerCommand�groups-managerz$create and edit groups metadata filec����������������s���t�t|��j|��tj��|�_d�S�)N)�superr"����__init__�libcomps�Comps�comps)�selfr���)� __class__r���r���r%���Q���s����zGroupsManagerCommand.__init__c�������������C���s���|�j�ddg�dtd�d��|�j�ddg�dtd�d��|�j�ddtd �d ��|�j�ddd td�d��|�j�dttd�d��|�j�ddtd�d��|�j�dtd�d��|�j�dttd�d��|�j�ddg�dttd�d��|�j�ddg�dttd �d��|�j��}|j�d!d"dd�td#�d$��|j�d%d"d&d�td'�d$��|�j��}|j�d(dtd)�d*��|j�d+dtd,�d*��|j�d-dd td.�d��|�j�d/dtd0�d*��|�j�d1d2d3td4�d5��d�S�)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.���r1���r/���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_argumentr���r ����intr���Zadd_mutually_exclusive_group)�parserZvisibleZsectionr���r���r���� set_argparserU���sR���� z"GroupsManagerCommand.set_argparserc�������������C���s����|�j�j}|�jjr"d|_d|_d|_|�jjrP|�jjj d|�jj��|�jj j|�jj��|�jjs�|�jj s�|�jjs�|�jjs�|�jjd�k s�|�jjr�|�jj�r�|�jj�r�tj�jtd���d�S�)NTFr���z;Can't edit group without specifying it (use --id or --name))r����demands�optsr4���Zsack_activationZavailable_reposZload_system_repo�merge�load�insert�saver+����description� display_order�translated_name�translated_descriptionr2����id�namer���r���r���)r)���r;���r���r���r���� configure����s"����zGroupsManagerCommand.configurec�������������C���s ���x|�j�jD��] }tj��}yp|jd�r~tj|��F}tjdd�}z$t j ||��|j���|j|j ��W�dtj|j ��X�W�dQ�R�X�n |j|��W�n~�tttjfk �r�}�zXt��}x2|j��D�]&}||kr�q�tj|j����|j|��q�W�tjjtd�j||���W�Y�dd}~X�qX�|��j|7��_qW�dS�)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�Errorr���r���r(���)r)���� file_nameZ file_compsZgz_fileZ temp_file�err�seenrT���r���r���r����load_input_files����s,���� $z%GroupsManagerCommand.load_input_filesc�������������C���s����x�|�j�jD�]�}y|�jj|td�}W�n*�tjk rL�}�z|g}W�Y�d�d�}~X�nX�|r x"|d�d��D�]}tj|j ����q`W�t jjt d�j||d�j �����q W�d�S�)N)�xml_options����zCan't save file "{}": {}���r_���)r<���r@���r(���Zxml_f�COMPS_XML_OPTIONSr&���ZXMLGenErrorr���rT���rU���r���rW���rX���r���r���)r)���rY����errorsrZ���r���r���r����save_output_files����s����z&GroupsManagerCommand.save_output_filesc�������������C���s\���d}|r*x |�j�jD�]}|j|kr|}P�qW�|dkrX|rXx |�j�jD�]}|j|kr@|}P�q@W�|S�)zl Try to find group according to command line parameters - first by id then by name. N)r(����groupsrE���rF���)r)���r ���rF����groupZgrpr���r���r���� find_group����s���� zGroupsManagerCommand.find_groupc�������������C���s���dd��}|�j�jr|�j�j|_|�j�jr,|�j�j|_|�j�jr>|�j�j|_|�j�jdk rT|�j�j|_|�j�jrj||�j�j�|_|�j�j r�||�j�j �|_ |�j�j�r�t��}xZ|�j�jD�]N}t jj|�}|j|�jjdddd�j��}|s�tjtd�j|���q�|j|��q�W�|�j�j�r2t��}x|D�]}|j|j���qW�|j|�jjj��j|d���d d ��|D��} |�j�j�r�x�| D�].} x&|j| tj d�D�]}|jj|���qfW��qPW�nd|�j�j!�r�tj"}n|�j�j#�r�tj$}ntj%}x8t&| �D�],} |j| |d��s�|jj'tj(| |d����q�W�dS�)zE Set attributes and package lists for selected group c�������������S���s&���t�j��}x|�D�]\}}|||<�qW�|S�)N)r&���ZStrDict)ZlstZstr_dictr���r���r���r���r����langlist_to_strdict����s����z<GroupsManagerCommand.edit_group.<locals>.langlist_to_strdictNTF)Z with_nevraZ with_providesZwith_filenameszNo match for argument: {})Zprovidesc�������������S���s���h�|�] }|j��qS�r���)rF���)�.0�pkgr���r���r���� <setcomp>��s����z2GroupsManagerCommand.edit_group.<locals>.<setcomp>)rF���r1���))r<���rF���rA���ZdescrB���r2���ZuservisiblerC���Zname_by_langrD���Zdesc_by_langr4���rS���r���ZsubjectZSubjectZget_best_query�baseZsackZlatestr���Zwarningr���r����updateZdependenciesZrequiresZqueryZfilterm�removeZpackages_matchr&���ZPACKAGE_TYPE_UNKNOWNZ mandatoryZPACKAGE_TYPE_MANDATORYZoptionalZPACKAGE_TYPE_OPTIONALZPACKAGE_TYPE_DEFAULT�sortedr+���ZPackage)r)���rd���rf���r4���Zpkg_specZsubj�qZrequirementsrh���Z pkg_namesZpkg_nameZpkg_typer���r���r���� edit_group����sT���� zGroupsManagerCommand.edit_groupc�������������C���s���|�j����|�jjs|�jjr�|�j|�jj|�jjd�}|d�kr�|�jjrNtjjt d���t j��}|�jjrt|�jj|_|�jj|_nD|�jjr�t|�jj�}|�j|d�d�r�tj jt d�j||�jj���||_|�jjj|��|�j|��|�j���|�jjs�|�jj�r�t|�jjtd���d�S�)N)r ���rF���z-Can't remove packages from non-existent groupzRGroup id '{}' generated from '{}' is duplicit. Please specify group id using --id.)r]���)r\���r<���rE���rF���re���rl���r���rW���rX���r���r&���ZGroupr!���r���r���r���r(���rc���r+���ro���rb����printr@���Zxml_strr`���)r)���rd���r ���r���r���r����run!��s,���� zGroupsManagerCommand.run)r#���)�__name__� __module__�__qualname__�aliasesr���Zsummaryr%����staticmethodr:���rG���r\���rb���re���ro���rq���� __classcell__r���r���)r*���r���r"���L���s���1$=r"���)Z __future__r���r���r���rJ���r&���rO���r���rM���rL���Zdnfpluginscorer���r���r���Zdnf.clir����compiler���r���r���r`���r ���r���r!���ZpluginZregister_commandr���ZCommandr"���r���r���r���r����<module>���s,���