o
    •Û_ˆ  ã                   @   s(   d dl Z d dlmZ G dd„ deƒZdS )é    N)Úreducec                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚMergerz0
	Tool for merging multiple profiles into one.
	c                 C   s   d S )N© )Úselfr   r   ú7/usr/lib/python3/dist-packages/tuned/profiles/merger.pyÚ__init__	   s   zMerger.__init__c                 C   s   t | j|ƒ}|S )z¶
		Merge multiple configurations into one. If there are multiple units of the same type, option 'devices'
		is set for each unit with respect to eliminating any duplicate devices.
		)r   Ú
_merge_two)r   ÚconfigsÚmerged_configr   r   r   Úmerge   s   zMerger.mergec                 C   s–  |j  |j ¡ t|j ¡ ƒD ]º\}}|js||jvr ||j|< q|j|j| _|j|j| _|j|j| _|j	durA|j	|j| _	|j
durM|j
|j| _
|jdurY|j|j| _|jdure|j|j| _|jdurq|j|j| _|jdur‰|jD ]}|j| j  |d¡ qyd|_|dkr¾|j| j  dd¡dur¾|j| j  dd¡}|j| j  |j ¡ ||j| j d  |j| j d< q|j| j  |j ¡ q|S )zà
		Merge two profiles. The configuration of units with matching names are updated with options
		from the newer profile. If the 'replace' options of the newer unit is 'True', all options from the
		older unit are dropped.
		NÚscript)ÚoptionsÚupdateÚlistÚunitsÚitemsÚreplaceÚtypeÚenabledÚdevicesÚdevices_udev_regexÚcpuinfo_regexÚuname_regexÚ
script_preÚscript_postÚdropÚpopÚget)r   Ú	profile_aÚ	profile_bÚ	unit_nameÚunitÚoptionr   r   r   r   r      s6   






 "zMerger._merge_twoN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r      s
    r   )ÚcollectionsÚ	functoolsr   Úobjectr   r   r   r   r   Ú<module>   s    