3 �<�e��@stddlZddlZddlmZmZddljZddlZ ddl Z ddl Zddl Z ddl mZejj�ZGdd�de�ZdS)�N)� ConfigParser�Error)�InvalidProfileExceptionc@sveZdZdZdddddgZdd�Zd d �Zed d ��Ze d d��Z dd�Z dd�Z dd�Z dd�Zdd�Zdd�ZdS)�Loaderz Profiles loader. �_profile_locator�_profile_merger�_profile_factory�_global_config� _variablescCs"||_||_||_||_||_dS)N)rrrr r )�self�profile_locatorZprofile_factoryZprofile_mergerZ global_config� variables�r�/usr/lib/python3.6/loader.py�__init__s zLoader.__init__cCstjjj||�S)N)�tuned�profiles�profileZProfile)r � profile_name�configrrr�_create_profileszLoader._create_profilecCs tjd|�S)Nz^[a-zA-Z0-9_.-]+$)�re�match)�clsrrrr� safe_nameszLoader.safe_namecCs|jS)N)r)r rrrr "szLoader.profile_locatorcCs�t|�tk r|j�}tt|j|��}t|�dkr8td��t|�dkrZtjddj |��ntjd|d�g}g}|j |||�t|�dkr�|j j |�}n|d}dj |�|_ d|jkr�|jj|jdj�|jd=|j|�|j|�|S) Nrz.No profile or invalid profiles were specified.�zloading profiles: %sz, zloading profile: %s� r )�type�list�split�filterr�lenr�log�info�join� _load_profiler�merge�name�unitsr Z add_from_cfg�options�_expand_vars_in_devices�_expand_vars_in_regexes)r � profile_namesr�processed_filesZ final_profilerrr�load&s*        z Loader.loadcCs0x*|jD] }|jj|j|j�|j|_qWdS)N)r(r �expandZdevices)r r�unitrrrr*Ds zLoader._expand_vars_in_devicescCsLxF|jD]<}|jj|j|j�|j|_|jj|j|j�|j|_qWdS)N)r(r r/Z cpuinfo_regexZ uname_regex)r rr0rrrr+Hs zLoader._expand_vars_in_regexesc Cs�x�|D]�}|jj||�}|dkr"q|dkrFtd|tt|jj��f��|j|�|j|�}|jj ||�}d|j kr�t j d|j j|j jd���}|j|||�|j|�qWdS)N�z!Cannot find profile '%s' in '%s'.�includez \s*[,;]\s*)rZ get_configrr�reversedZ_load_directories�append�_load_config_datarZcreater)rrr r/�popr%) r r,rr-r'�filenamerrZ include_namesrrrr%Ms    zLoader._load_profilecCstjd||�S)Nz(?s