3 Yd@stddlZddlZddlmZmZddljZddlZ ddl Z ddl Zddl Z ddl mZejjZGdddeZdS)N) ConfigParserError)InvalidProfileExceptionc@sveZdZdZdddddgZddZd d Zed d Ze d dZ ddZ ddZ ddZ ddZddZddZdS)Loaderz Profiles loader. _profile_locator_profile_merger_profile_factory_global_config _variablescCs"||_||_||_||_||_dS)N)rrrr r )selfprofile_locatorZprofile_factoryZprofile_mergerZ global_config variablesr/usr/lib/python3.6/loader.py__init__s zLoader.__init__cCstjjj||S)N)tunedprofilesprofileZProfile)r profile_nameconfigrrr_create_profileszLoader._create_profilecCs tjd|S)Nz^[a-zA-Z0-9_.-]+$)rematch)clsrrrr safe_nameszLoader.safe_namecCs|jS)N)r)r rrrr "szLoader.profile_locatorcCst|tk r|j}tt|j|}t|dkr8tdt|dkrZtjddj |ntjd|dg}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 )typelistsplitfilterrlenrloginfojoin _load_profilermergenameunitsr Z add_from_cfgoptions_expand_vars_in_devices_expand_vars_in_regexes)r profile_namesrprocessed_filesZ final_profilerrrload&s*        z Loader.loadcCs0x*|jD] }|jj|j|j|j|_qWdS)N)r(r expandZdevices)r runitrrrr*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 Csx|D]}|jj||}|dkr"q|dkrFtd|tt|jjf|j||j|}|jj ||}d|j krt j d|j j|j jd}|j||||j|qWdS)Nz!Cannot find profile '%s' in '%s'.includez \s*[,;]\s*)rZ get_configrrreversedZ_load_directoriesappend_load_config_datarZcreater)rrr r/popr%) r r,rr-r'filenamerrZ include_namesrrrr%Ms    zLoader._load_profilecCstjd||S)Nz(?s