3
�<�e( � @ s* d dl Z d dlZdgZG dd� de�ZdS )� N�
DeviceMatcherc @ s e Zd ZdZdd� Zdd� ZdS )r a,
Device name matching against the devices specification in tuning profiles.
The devices specification consists of multiple rules separated by spaces.
The rules have a syntax of shell-style wildcards and are either positive
or negative. The negative rules are prefixed with an exclamation mark.
c s� t |t�rtjd|�}dd� |D �� � fdd�|D �}t� �dkrL� jd� d}x� D ]}tj||�rVd}P qVW x|D ]}tj||�rvd}P qvW |S ) a
Match a device against the specification in the profile.
If there is no positive rule in the specification, implicit rule
which matches all devices is added. The device matches if and only
if it matches some positive rule, but no negative rule.
z\s|,\s*c S s* g | ]"}|j d � r|j� dk r|�qS )�!� )�
startswith�strip)�.0�rule� r �$/usr/lib/python3.6/device_matcher.py�
<listcomp> s z'DeviceMatcher.match.<locals>.<listcomp>c s g | ]}|� kr|d d� �qS )� Nr )r r )�positive_rulesr r
r s r �*FT)�
isinstance�str�re�split�len�append�fnmatch)�self�rulesZdevice_nameZnegative_rulesZmatchesr r )r
r
�match s
zDeviceMatcher.matchc C s, g }x"|D ]}| j ||�r
|j|� q
W |S )z�
Match a device list against the specification in the profile. Returns
the list, which is a subset of devices which match.
)r r )r r Zdevice_listZmatching_devicesZdevicer r r
�
match_list, s
zDeviceMatcher.match_listN)�__name__�
__module__�__qualname__�__doc__r r r r r r
r s )r r �__all__�objectr r r r r
�<module> s