
    pO                     D    d dl mZ d dl mZ ddl d dlZ G d de      Zy)    )print_function)unicode_literals   )*Nc                   V     e Zd ZdZd fd	Zd Zd Zd ZddZd Z	d Z
d	 Zd
 Z xZS )XUtilsz[Subclass with higher-level methods
    
    See xorgparser.Parser for the low-level methodsc                 ,    t         t        |   |       y N)superr   __init__)selfsource	__class__s     -/usr/lib/python3/dist-packages/xkit/xutils.pyr   zXUtils.__init__   s    fd$V,    c                 l    | j                         }|D ]  }||   D ]  }| j                  ||        ! y)z.Fix broken references to non-existent sections)
identifierN)get_broken_referencesmake_section)r   broken_referencessection	references       r   fix_broken_referenceszXUtils.fix_broken_references    sK     668( 	AG.w7 A	!!'i!@A	Ar   c                 ,    d}| j                  |||      S )zGet the driver in use in a section

        If no driver is found it will return False.

        For further information see get_value()Driver)	get_value)r   r   positionoptions       r   
get_driverzXUtils.get_driver'   s     ~~gvx88r   c                 2    d}| j                  ||||       y)z"Set the driver in use in a sectionr   )r   N)
add_option)r   r   driverr   r   s        r   
set_driverzXUtils.set_driver0   s    (Cr   c                     |dk(  r&t        | j                  d   j                               }|D ]  }	 | j                  d|      |k7  r y y# t        $ r Y  yw xY w)zLook for a driver in the Device sections

        Return True if the driver is found in each of the specified
        sections, otherwise return False.

        if sections_list == None check all the Device sectionsNDeviceFT)list
globaldictkeysr   OptionException)r   r"   sections_listr   s       r   section_has_driverzXUtils.section_has_driver5   sq     D  !:!?!?!ABM$ 	G??8W5?  @	  # s   A	AAc                 N   g }| j                  d|dg      }t        |d         dkD  r_|d   D ]W  }	 | j                  d|      }	 | j                  d|dg      }|d   D ]%  }| j                  d|      }|j	                  |       ' Y |S # t        $ r Y gw xY w# t
        $ r Y vw xY w)zReturn a list of references to the Device sections in ServerLayout
        
        This method looks for references to Device sections in the Screen
        sections referred to in the ServerLayout[position] section.ServerLayoutScreenr   r%   )get_referenceslenget_positionIdentifierExceptionappendr)   )	r   r   devices_to_check
referencesr   screen_positiondevice_referencesdevicedevice_positions	            r   get_devices_in_serverlayoutz"XUtils.get_devices_in_serverlayoutH   s    
 ((H:N
z(#$q( (1 	&*&7&7)&LO(,(;(;H-<xj)J%"3H"= A*.*;*;Hf*M(//@A   +  ' s$   B	AB		BB	B$#B$c                    g }d}| j                   d   }| j                   d   }t        |      }t        |      }|dkD  r|dkD  rp|dkD  rO| j                         }t        |      dk(  r| j                  |d         }nI|D ]  }|| j                  |      z  } n-|D ]  }|| j                  |      z  } n| j                  d      }t        |      dk(  r&t	        | j                   d   j                               }|S )a  Return the Device sections in use

        If no Device sections are referenced in ServerLayout then all of
        the available Device sections are returned.

        This method supports old Xinerama setups and therefore looks for
        references to Device sections in the ServerLayout section(s) and
        checks only the default ServerLayout section provided than one is
        set in the ServerFlags section.Fr-   ServerFlagsr   r   r%   )r'   r0   get_default_serverlayoutr:   r&   r(   )	r   r4   driver_enabledserverlayoutserverflagsserverlayout_lengthserverflags_lengthdefaultlayouts	            r   get_devices_in_usezXUtils.get_devices_in_used   s*    ~6oom4!,/ -""Q&%) #;;=G7|q(88D ) '3 EF, <<VDE,E #/ A(88@A(A $(#C#CA#F  A%#DOOH$=$B$B$DEr   c                 L    | j                         }| j                  ||      }|S )a  See if a driver is enabled in the Device sections

        When possible, this method checks only the Device sections in use,
        otherwise it checks any available Device section.

        This method supports old Xinerama setups and therefore looks for
        references to Device sections in the ServerLayout section(s) and
        checks only the default ServerLayout section provided than one is
        set in the ServerFlags section.)r*   )rE   r+   )r   r"   r4   r>   s       r   is_driver_enabledzXUtils.is_driver_enabled   s6      22400=M 1 O r   c                     i }d}| j                   d   D ]T  }| j                  d|dg      }|d   d   }| j                  d|      }|j                  |       i ||<   |||   d<   |dz  }V |S )z>See which Screen sections are related to which Device sectionsr   r.   r%   )reflistr   )r'   r/   r1   
setdefault)r   relationshipsitscreenr5   r8   s         r   get_screen_device_relationshipsz&XUtils.get_screen_device_relationships   s    ooh/ 	F,,XrH:,NJ)!,F&&x8F$$V,$&M&!.0M&!(+!GB	 r   r
   )__name__
__module____qualname____doc__r   r   r   r#   r+   r:   rE   rG   rN   __classcell__)r   s   @r   r   r      s8    7-A9D
& 81 f r   r   )
__future__r   r   
xorgparsersysParserr    r   r   <module>rY      s!   ( & '  
[V [r   